ToolTip inside ScrollablePanel
« on: 13 July 2018, 15:41:29 »
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

  • *****
  • 1279
    • View Profile
    • Texus's Blog
Re: ToolTip inside ScrollablePanel
« Reply #1 on: 13 July 2018, 16:41:49 »
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).

Re: ToolTip inside ScrollablePanel
« Reply #2 on: 13 July 2018, 23:56:10 »
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

  • *****
  • 1279
    • View Profile
    • Texus's Blog
Re: ToolTip inside ScrollablePanel
« Reply #3 on: 14 July 2018, 00:30:27 »
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)
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.

Re: ToolTip inside ScrollablePanel
« Reply #4 on: 14 July 2018, 13:06:53 »
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
Code: [Select]
- bindHeight(tooltip) and it works.