1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 06:47:34 +00:00

LibGUI+WindowServer: Add support for GWidget tooltips.

Any GWidget can have a tooltip and it will automatically pop up below the
center of the widget when hovered. GActions added to GToolBars will use
the action text() as their tooltip automagically. :^)
This commit is contained in:
Andreas Kling 2019-04-08 18:58:44 +02:00
parent 3e175c9a96
commit 7f2eeb0b35
15 changed files with 136 additions and 27 deletions

View file

@ -6,6 +6,7 @@
#include <AK/Assertions.h>
#include <SharedGraphics/GraphicsBitmap.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GApplication.h>
#include <unistd.h>
@ -79,9 +80,9 @@ void GWidget::event(GEvent& event)
case GEvent::MouseUp:
return handle_mouseup_event(static_cast<GMouseEvent&>(event));
case GEvent::Enter:
return enter_event(event);
return handle_enter_event(event);
case GEvent::Leave:
return leave_event(event);
return handle_leave_event(event);
default:
return GObject::event(event);
}
@ -177,6 +178,19 @@ void GWidget::handle_mousedown_event(GMouseEvent& event)
mousedown_event(event);
}
void GWidget::handle_enter_event(GEvent& event)
{
if (has_tooltip())
GApplication::the().show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2));
enter_event(event);
}
void GWidget::handle_leave_event(GEvent& event)
{
GApplication::the().hide_tooltip();
leave_event(event);
}
void GWidget::click_event(GMouseEvent&)
{
}
@ -261,6 +275,11 @@ Rect GWidget::window_relative_rect() const
return rect;
}
Rect GWidget::screen_relative_rect() const
{
return window_relative_rect().translated(window()->position());
}
GWidget::HitTestResult GWidget::hit_test(int x, int y)
{
// FIXME: Care about z-order.