1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 01:37:34 +00:00

LibGUI: Update active tooltip when source widget changes the label

Application::show_tooltip() now keeps track of the application's active
tooltip source widget so it can be updated while being shown when the
same widget updates its tooltip label.
Application::hide_tooltip() will unset the tooltip source widget,
respectively.

This is pretty useful for the ResourceGraph applet's tooltips!

Also re-use the Application::TooltipWindow's rect position in its
set_tooltip() method to avoid flickering from the window temporarily
being moved to 100, 100 and the position adjusted moments later.
This commit is contained in:
Linus Groh 2020-08-15 11:44:34 +02:00 committed by Andreas Kling
parent f19b88c965
commit 47d7faa998
5 changed files with 27 additions and 7 deletions

View file

@ -317,8 +317,7 @@ void Widget::handle_mousedoubleclick_event(MouseEvent& event)
void Widget::handle_enter_event(Core::Event& event)
{
if (has_tooltip())
Application::the()->show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2));
show_tooltip();
enter_event(event);
}
@ -843,4 +842,17 @@ Gfx::IntRect Widget::content_rect() const
return rect;
}
void Widget::set_tooltip(const StringView& tooltip)
{
m_tooltip = tooltip;
if (GUI::Application::the()->tooltip_source_widget() == this)
show_tooltip();
}
void Widget::show_tooltip()
{
if (has_tooltip())
Application::the()->show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2), this);
}
}