LibGUI: Add show_tooltip_immediately()
This allows an application to display a tooltip without waiting for a timer to fire first.
This commit is contained in:
parent
552dd7abd3
commit
d46c3896c6
Notes:
sideshowbarker
2024-07-18 07:17:41 +09:00
Author: https://github.com/TobyAsE Commit: https://github.com/SerenityOS/serenity/commit/d46c3896c67 Pull-request: https://github.com/SerenityOS/serenity/pull/9262 Reviewed-by: https://github.com/metmo
2 changed files with 19 additions and 4 deletions
Userland/Libraries/LibGUI
|
@ -93,7 +93,7 @@ Application::Application(int argc, char** argv, Core::EventLoop::MakeInspectable
|
|||
}
|
||||
|
||||
m_tooltip_show_timer = Core::Timer::create_single_shot(700, [this] {
|
||||
tooltip_show_timer_did_fire();
|
||||
request_tooltip_show();
|
||||
});
|
||||
|
||||
m_tooltip_hide_timer = Core::Timer::create_single_shot(50, [this] {
|
||||
|
@ -146,7 +146,7 @@ void Application::show_tooltip(String tooltip, const Widget* tooltip_source_widg
|
|||
m_tooltip_window->set_tooltip(move(tooltip));
|
||||
|
||||
if (m_tooltip_window->is_visible()) {
|
||||
tooltip_show_timer_did_fire();
|
||||
request_tooltip_show();
|
||||
m_tooltip_show_timer->stop();
|
||||
m_tooltip_hide_timer->stop();
|
||||
} else {
|
||||
|
@ -155,6 +155,20 @@ void Application::show_tooltip(String tooltip, const Widget* tooltip_source_widg
|
|||
}
|
||||
}
|
||||
|
||||
void Application::show_tooltip_immediately(String tooltip, 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);
|
||||
}
|
||||
m_tooltip_window->set_tooltip(move(tooltip));
|
||||
|
||||
request_tooltip_show();
|
||||
m_tooltip_show_timer->stop();
|
||||
m_tooltip_hide_timer->stop();
|
||||
}
|
||||
|
||||
void Application::hide_tooltip()
|
||||
{
|
||||
m_tooltip_show_timer->stop();
|
||||
|
@ -194,7 +208,7 @@ Gfx::Palette Application::palette() const
|
|||
return Palette(*m_palette);
|
||||
}
|
||||
|
||||
void Application::tooltip_show_timer_did_fire()
|
||||
void Application::request_tooltip_show()
|
||||
{
|
||||
VERIFY(m_tooltip_window);
|
||||
Gfx::IntRect desktop_rect = Desktop::the().rect();
|
||||
|
|
|
@ -36,6 +36,7 @@ public:
|
|||
void unregister_global_shortcut_action(Badge<Action>, Action&);
|
||||
|
||||
void show_tooltip(String, const Widget* tooltip_source_widget);
|
||||
void show_tooltip_immediately(String, const Widget* tooltip_source_widget);
|
||||
void hide_tooltip();
|
||||
Widget* tooltip_source_widget() { return m_tooltip_source_widget; };
|
||||
|
||||
|
@ -85,7 +86,7 @@ private:
|
|||
|
||||
virtual void event(Core::Event&) override;
|
||||
|
||||
void tooltip_show_timer_did_fire();
|
||||
void request_tooltip_show();
|
||||
void tooltip_hide_timer_did_fire();
|
||||
|
||||
void set_drag_hovered_widget_impl(Widget*, const Gfx::IntPoint& = {}, Vector<String> = {});
|
||||
|
|
Loading…
Add table
Reference in a new issue