From 7e79563bb9db3ba864e689fd6eb0c243adbc5a84 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 28 Dec 2020 21:26:47 +0100 Subject: [PATCH] LibGUI: Show tooltip after a small delay It always felt a bit jarring that tooltips would pop in right away when you hover over a toolbar button. This patch adds a 700ms delay before they appear, and a 50ms delay before they disappear. Once a tooltip is up, moving the cursor between two widgets that both have tooltips will leave the tooltip on screen without delays. --- Libraries/LibGUI/Application.cpp | 122 ++++++++++++++++---------- Libraries/LibGUI/Application.h | 7 +- Libraries/LibGUI/Widget.cpp | 2 +- Libraries/LibWeb/InProcessWebView.cpp | 4 +- 4 files changed, 84 insertions(+), 51 deletions(-) diff --git a/Libraries/LibGUI/Application.cpp b/Libraries/LibGUI/Application.cpp index 18837aeb07..a70e7d5b39 100644 --- a/Libraries/LibGUI/Application.cpp +++ b/Libraries/LibGUI/Application.cpp @@ -40,6 +40,34 @@ namespace GUI { +class Application::TooltipWindow final : public Window { + C_OBJECT(TooltipWindow); + +public: + void set_tooltip(String tooltip) + { + // FIXME: Add some kind of GUI::Label auto-sizing feature. + int text_width = m_label->font().width(tooltip); + set_rect(rect().x(), rect().y(), text_width + 10, m_label->font().glyph_height() + 8); + m_label->set_text(move(tooltip)); + } + +private: + TooltipWindow() + { + set_window_type(WindowType::Tooltip); + m_label = set_main_widget