Scrollbar and Panel

Started by sors, 02 September 2018, 13:34:10

sors

Hi, I want to do that Scrollbar moving my Panel:
Quotescrollbar_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

#1
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:
Code (cpp) Select
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.

sors

i using 0.7.7
My panel size is: 280, 448
My picture size: 280, 800

Scrollbar options:
QuoteScrollbar."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

#3
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).

sors