Binding buttons to an hidden menu

Started by glagan, 23 July 2018, 22:45:00


Hi, I'm creating a menu that is hidden by default, and when i click a button, it is introduced with a nice showWithEffect().
The thing here is that the button is binded to the right of the menu, and it moves with it when it's showing. Everything is fine for now, the default width of the menu is it's real size and buttons are binded to 0% by default.
I also hide the menu with hideWithEffect(), and the problem is here, after hideWithEffect is called it's original position is set back, and so my buttons are to the right again, floating in the middle of nowhere.

So, i want the buttons to actually stay at 0%, on the left, after the animation is over.
To achieve that i created a tiny class "Timer" that execute an action after a set amount of time, and i use that to set the buttons position to 0 after the same amount of time as the animation.
My solution seems kind of overkill, so is there an easier solution that i just didn't think of or not ?  :-X

Here is what's happening on the first link, and what i want to achieve on the second link (working with my solution):
First gif and the second gif

Also, i'm actually creating the menus (3 of them in the gif) individually, by that i mean that each menu is totally independent from the others.
I actually did that for a reason. On my first try, i did a "MenuContainer" where i would put menus inside and hide them at choice, but i couldn't scroll a ScrollablePanel inside a panel and so i create them "individually".
Does ignoreMouseEvents() could actually help me scroll in a panel inside another panel ? Or another option that i didn't see ? I'm actually asking before trying again because i don't want to try everything again if there is no solution :x

Thanks and sorry for the long post.


The hideWithEffect issue is intended behavior. If I wouldn't reset the position and size after the animation then it wouldn't be possible to hide and show the widget again, you would have to manually specify the size again before showing (in your case this is probably simple, but I imagine that others may not like to have to store the size themselves just to be able to show their widget again).

The timer solution sounds tricky, I can imagine that in some exceptional case your timer might expire before the internal timer in TGUI. I'll see if I can add a AnimationFinished callback that gets triggered at the end of animations, that might be a better solution.
The real solution would be to have proper animation support, where you would be able to define both a begin and and end state (so that you can move a widget from one place to another or like in your case change the size from some value to another). When I originally looked into this I decided to just keep things simple and only add animation support for showing and hiding and I don't think that will change soon.

Not being able to scroll when the scrollbable panel is inside a panel sounds like a bug, I'll look into that tomorrow evening. The ignoreMouseEvents function only exists for Picture and Label so it isn't relevant here. Even if it existed for Panel, it would also mean that the events would never reach the ScrollablePanel but would instead be delivered to the widgets behind the Panel.


The AnimationFinished callback would be really great i think, i actually searched for one when i had the problem and you made one that is called when the animation is done but it's only used for internal purpose :(

Also, the issue where i'm not able to scroll a scrollable panel inside a panel is wrong, i didn't check first but it's a scrollable panel inside another scrollable panel, so... this issue was kind of dumb for my purpose, i can simply remplace the outter one with a simple Panel and it will work, since the outter one is just a container with fixed size, there is no need for it to have a scrollbar (i don't know why i did that).
But the issue may be a real one ? I don't know, it could be tricky to fix with even more nested scrollable panel.



Both issues have been fixed.

1) An "AnimationFinished" signal was added to the Widget class. The following calls are all valid (the ShowAnimationType parameter is the same as passed to showWithEffect/hideWithEffect while the boolean will be true for showWithEffect and false for hideWithEffect)
Code (cpp) Select
widget->connect("AnimationFinished", [](){});
widget->connect("AnimationFinished", [](tgui::ShowAnimationType type){});
widget->connect("AnimationFinished", [](bool visible){});
widget->connect("AnimationFinished", [](tgui::ShowAnimationType type, bool visible){});

2) Although nested scrollable panels is an unlikely scenario, the issue would also happen on any scrollable widget within a scrollable panel (e.g. list box, text box, chat box, ...). The scrollable panel simply handled the mouse wheel event without checking whether any child widget should get it instead.

New version can be downloaded from github.


It works perfectly :) Thanks again !