ToolTip inside ScrollablePanel

Started by glagan, 13 July 2018, 15:41:29

glagan

Hi, when you add ToolTips to elements in a ScrollablePanel, the tooltip stay fixed, after scrolling the tooltip is at the same place.

Thanks.

texus

I couldn't actually reproduce what you said, when I tested the tooltip in a ScrollablePanel it didn't even show up when the panel was scrolled.
I've fixed this behavior, you should check if your problem is solved when you download the latest version from github (https://github.com/texus/TGUI).

glagan

Thanks, it works now :)
The tooltip did show up, but you had to hover the old position of the element (without scroll) to show it.

One last problem is that tooltips are not really visible when you hover an element at the bottom of the window, the tooltip is "out" of the window.
A simple trick would be to display the tooltip above the mouse instead of below. I tried to do it but I still don't really understand how everything works ^^'

texus

The tooltip gets positioned in this part of code, which has no idea about the original widget to which the tooltip is connected (and it thus can't know that the widget is at the bottom).
The position is determined by 3 parts: the mouse position, a constant offset retrieved via ToolTip::getDistanceToMouse() and the position of the tooltip widget which is normally always (0,0). The first one can't be changed and the second one applies to all tooltips, so only the third one can be used to alter the position without changing the current design. If you know the widget is at the bottom then you can create the tooltip like this: (code hasn't been tested)
Code (cpp) Select
auto tooltip = tgui::Label::create("Tooltip text");
tooltip->setPosition(0, -tgui::ToolTip::getDistanceToMouse().y - 20);
widget->setTooltip(tooltip);


But that is just a hack, you can't even rely on the label height (unless you call tooltip->setFont yourself first) because it will only receive a font when it becomes visible.
The only way to do it properly is to change the current design and rewrite how tooltips are created.

glagan

I knew it would be complicated since you need to know the parent height :(
I actually know when the tooltip will not be visible, so the code you wrote actually works and it's fine for me, thanks for the answers :)
I replaced - 20 with - bindHeight(tooltip) and it works.