Scrollbar in child window not staying the right place

Started by RitoonL, 26 May 2020, 01:27:31

RitoonL

Hello,

I'm setting a scrollbar in a child window, i first tried with layouts, this should have been cool to

Code (cpp) Select
scrollbar->setPosition({bindRight(container)-10,0})

but the scrollbar is moving within the container when i move the window like it was not using relative coordinates, it just won't stay right of the window.

so i tried :

Code (cpp) Select
scrollbar->setPosition(sf::Vector2f(container->getSize().x - scrollbar->getSize().x, 0));

The scrollbar moves with the window as expected but stays in place when the window is resized, just like the window size is not updated.

I know it is a noob issue, but still, i can't figure how to fix it as it is my first day using TGUI. any idea ?

Regards,

RitoonL

texus

The bindRight behavior sounds like a bug. Which widgets are parents to each other? Is the container inside the child window? Is the scrollbar added to the container, to the child window or to the gui?

The bindRight function was intended for sibling widgets that needed to be placed next to each other. Since it looks like you want the scrollbar on top of the container, maybe you should just add the scrollbar to the container and call
Code (cpp) Select
scrollbar->setPosition({"100% - width", 0})

With bind functions this would be equivalent to the following, but note that you can't use this code yet as I just realized there is no bindInnerWidth function (it's sometimes equivalent to bindWidth, but bindWidth won't work correctly if your container has borders and padding).
Code (cpp) Select
scrollbar->setPosition({bindInnerWidth(container) + bindWidth(scrollbar), 0})

If the scrollbar really has to be part of the container then you could consider using ScrollablePanel instead of creating a scrollbar manually.

RitoonL

Thanks for your answer, Texus.

Sorry, i was not clear enough and used "container" to be more generic, but parent of my scrollbar is actually the child window, there is no other container. The code i submit is not the exact paste of what is in my project.

Not sure i'm happy or not that this is a bug, but at least, i now know that i was trying to do the right thing. What i want to do is Having the scrollbar on the inner right of the child window, fitting the whole height of it.

i used bindHeight in order to make the scrollbar fit the height of the window, wich worked great:

Code (cpp) Select
scrollbar->setSize({10, bindHeight(channels)});
channels is the name of my childwindow

and bindRight to set the scrollbar inner right of the window, using an offset that is the whidth of the scrollbar (getsize did not work and would not compile, i had to use the numerical value).

Code (cpp) Select
scrollbar->setPosition({bindRight(channels) - 10,0});

this is the part with strange behaviour, as the scrollbar is int the good position when creating the childwindow but doing weird stuff when moving the window, like it was not using the same coords than the window itself.

Code (cpp) Select
scrollbar->setPosition({"100% - width", 0})

this is working great and fixed my issue.

Also, Bindright seems to want to bind the left side of the scrollbar on the right side of the window, wich position it out the window , i think that's what you're talking about with bindInnerWidth, would'nt bindRight just want to stick right side of the widget on left side of the childwindow ?

Many thanks for your fast answer, i can continue building my interface now.

regards,

RLF




texus

The bindRight behavior is not a bug, I tested it here and having it move through the child window means you are using it wrong. If the scrollbar is added to the gui instead of to the child window then it will follow the child window around (although not at exactly the wanted pixel).

bindRight = bindLeft + bindWidth
So if you move the child window around then the left position of the window changes and thus the scrollbar will also move. But the position of the scrollbar is relative to that of the child window (since you added it to the child window), so it will moves twice (once with the child window and once because you change its position with the bind function).

QuoteAlso, Bindright seems to want to bind the left side of the scrollbar on the right side of the window, wich position it out the window

would'nt bindRight just want to stick right side of the widget on left side of the childwindow ?
The position of widgets is always the top left position, so even if you use bindRight, it will position the left side of the widget on that location. The bindRight function wasn't meant for overlapping widgets, it was meant for widgets that are placed next to each other. This is why you still have to subtract the width of your scrollbar from the position to get it to the right place. In TGUI 0.9-dev there is a setOrigin function now, so you would be able to call setOrigin(1, 0) and then you no longer have to subtract the width (because the position given to the widget would be the top-right position instead of top-left).

Quotei think that's what you're talking about with bindInnerWidth
Not really. Imagine you have a panel of size (100x100) and it has a border of 10 pixels width. The contents of that panel is only (80x80). In order to have a widget of width 20px on the right side of the panel, you must place it on left position 60. If you were to use bindSize()-20 then you would actually be placing it on position 80 (=100-20). There should be a bindInnerSize() function that returns 80 so that you can do bindInnerSize()-20.
The example that I gave uses a layout with the string "100%". This is internally translated to widget->getInnerSize() and not widget->getSize(), which is why it worked. But there currently isn't a bind function to achieve the same thing, you currently have to create the layout using a string to get the wanted behavior.

ChildWindow behaves a bit differently in TGUI 0.8, it's inner size and size are the same thing, the borders and title bar are drawn outside of its size. Since this is inconsistent with the other widgets, this was changed in 0.9-dev where there is a difference between size and inner size now.

Btw, your email provider has been blocking more than just my forum email yesterday. Before I replied on facebook I had actually send you an email, but today I received it back as undelivered. As I said in that email (which I've quoted below), free.fr was blocking the messages based on ip address (at least that was what the error claimed). Messages sent using my mail client are however send using a completely different mail provider. So either it lies in its error message and just really dislikes the "tgui.eu" domain name, or they had temporarily blacklisted a lot of ip addresses.
QuoteIt looks like free.fr is currently blocking ip addresses from sendgrid.com (which is where my forum emails are send from).
Sendgrid has been retrying to send the message every few minutes but it always gets a 451 error back.

I've activated you on the forum manually, you should be able to login now.

RitoonL

Ok i understand now that my error is to add the scrollbar to the child window instead of adding it with gui.add and binding it to my child window. I will keep this in mind for the future of the project.

As i'm still a beginner, and self learning, i have to learn by error, even if sometimes i can be considered as stupid/or asking stupid questions. But i have no mentor or school teatcher to who i can refer ... really sorry for that.

Your really accurate answer helps me a lot and i'm grateful for this.

Sorry for the problems with my mailbox, this is really strange, i received the confirmation mail this morning, but never received your personal answer. Thanks for adding me manually.

Regards,

RitoonL