*

sors

  • *
  • 13
    • View Profile
Scrollbar and Panel
« on: 02 September 2018, 13:34:10 »
Hi, I want to do that Scrollbar moving my Panel:
Quote
    scrollbar_ZonesPanel->connect("ValueChanged ", [&]()
                                        {
                                            int scrolbarValue = scrollbar_ZonesPanel->getValue();
                                            scrolbarValue = (scrolbarValue * 8 ) ? scrolbarValue * 8:8;

                                            for(auto& widget : panel_ZonesPanel->getWidgets())
                                                {
                                                    if(widget->getWidgetType() != "Scrollbar")
                                                        {
                                                            if(previousScrolbarValue < scrollbar_ZonesPanel->getValue())
                                                                {
                                                                    widget->setPosition(widget->getPosition().x, widget->getPosition().y - scrolbarValue);
                                                                }
                                                            else
                                                                {
                                                                    widget->setPosition(widget->getPosition().x, widget->getPosition().y + scrolbarValue);
                                                                }
                                                        }
                                                }
                                            previousScrolbarValue = scrollbar_ZonesPanel->getValue();
                                        });
This code works, but the problem is that in them it omits the panel, but on top in the original position is not, why?

*

texus

  • *****
  • 1279
    • View Profile
    • Texus's Blog
Re: Scrollbar and Panel
« Reply #1 on: 02 September 2018, 13:54:09 »
I didn't understand your problem and what you were trying to do with the scrolbarValue and what the multiplication by 8 is for.

If you just want to scroll all widgets in the panel except for the scrollbar then you need something like this:
scrollbar_ZonesPanel->connect("ValueChanged", [&]()
        {
            int scrolbarDiff = int(previousScrolbarValue) - int(scrollbar_ZonesPanel->getValue());
            for(auto& widget : panel_ZonesPanel->getWidgets())
            {
                if(widget != scrollbar_ZonesPanel)
                    widget->setPosition(widget->getPosition().x, widget->getPosition().y + scrolbarDiff);
            }
            previousScrolbarValue = scrollbar_ZonesPanel->getValue();
        });

If that is what you need then maybe you could also have a look at the ScrollablePanel widget where you don't have to implement scrolling yourself: a scrollbar will appear if widgets no longer fit inside the panel or when you manually set the content size (with setContentSize) larger than the panel size.
Edit: ScrollablePanel is only in TGUI 0.8, so you won't be able to use it if you are still using 0.7.
« Last Edit: 02 September 2018, 13:56:50 by texus »

*

sors

  • *
  • 13
    • View Profile
Re: Scrollbar and Panel
« Reply #2 on: 02 September 2018, 14:05:13 »
i using 0.7.7
My panel size is: 280, 448
My picture size: 280, 800

Scrollbar options:
Quote
    Scrollbar."Scrollbar" {
        ArrowScrollAmount: 1;
        AutoHide: false;
        LowValue: 1;
        Maximum: 10;
        Position: (256, 16);
        Size: (16, 424);
        Value: 0;
   
        Renderer {
            ArrowDownHoverImage: "Black.png" Part(183, 174, 20, 20) Middle(0, 1, 20, 19);
            ArrowDownImage: "Black.png" Part(163, 174, 20, 20) Middle(0, 1, 20, 19);
            ArrowUpHoverImage: "Black.png" Part(183, 154, 20, 20) Middle(0, 0, 20, 19);
            ArrowUpImage: "Black.png" Part(163, 154, 20, 20) Middle(0, 0, 20, 19);
            ThumbHoverImage: "Black.png" Part(143, 174, 20, 20);
            ThumbImage: "Black.png" Part(143, 154, 20, 20);
            TrackHoverImage: "Black.png" Part(123, 174, 20, 20);
            TrackImage: "Black.png" Part(123, 154, 20, 20);
        }
    }
The problem is that the picture does not completely disappear

*

texus

  • *****
  • 1279
    • View Profile
    • Texus's Blog
Re: Scrollbar and Panel
« Reply #3 on: 02 September 2018, 14:14:25 »
So you want the panel to display the top 424 pixels of the picture when the scrollbar is on top, the bottom 424 pixels of the picture when the scrollbar is around 2/3th down and no picture at all when the scrollbar is at the bottom? (The 424 might have to be 448 here, I don't know exactly how the panel looks, but those pixels are the visible part of the panel).
Then set LowValue to 424 (same as scrollbar height) and set the Maximum to 1224 (800 + 424 = size of picture + visible area of panel).
« Last Edit: 02 September 2018, 14:17:19 by texus »

*

sors

  • *
  • 13
    • View Profile
Re: Scrollbar and Panel
« Reply #4 on: 02 September 2018, 19:27:09 »
thx!