1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:08:11 +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

@ -115,7 +115,7 @@ public:
{
// FIXME: Add some kind of GUI::Label auto-sizing feature.
int text_width = m_label->font().width(tooltip);
set_rect(100, 100, text_width + 10, m_label->font().glyph_height() + 8);
set_rect(rect().x(), rect().y(), text_width + 10, m_label->font().glyph_height() + 8);
m_label->set_text(tooltip);
}
@ -134,8 +134,9 @@ private:
RefPtr<Label> m_label;
};
void Application::show_tooltip(const StringView& tooltip, const Gfx::IntPoint& screen_location)
void Application::show_tooltip(const StringView& tooltip, const Gfx::IntPoint& screen_location, const Widget* tooltip_source_widget)
{
m_tooltip_source_widget = tooltip_source_widget;
if (!m_tooltip_window) {
m_tooltip_window = TooltipWindow::construct();
m_tooltip_window->set_double_buffering_enabled(false);
@ -159,6 +160,7 @@ void Application::show_tooltip(const StringView& tooltip, const Gfx::IntPoint& s
void Application::hide_tooltip()
{
m_tooltip_source_widget = nullptr;
if (m_tooltip_window) {
m_tooltip_window->hide();
m_tooltip_window = nullptr;