1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:07:47 +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

@ -34,6 +34,10 @@ public:
Size preferred_size() const { return m_preferred_size; }
void set_preferred_size(const Size&);
bool has_tooltip() const { return !m_tooltip.is_empty(); }
String tooltip() const { return m_tooltip; }
void set_tooltip(const String& tooltip) { m_tooltip = tooltip; }
virtual void event(GEvent&) override;
virtual void paint_event(GPaintEvent&);
virtual void resize_event(GResizeEvent&);
@ -56,6 +60,7 @@ public:
Point relative_position() const { return m_relative_rect.location(); }
Rect window_relative_rect() const;
Rect screen_relative_rect() const;
int x() const { return m_relative_rect.x(); }
int y() const { return m_relative_rect.y(); }
@ -149,6 +154,8 @@ private:
void handle_resize_event(GResizeEvent&);
void handle_mousedown_event(GMouseEvent&);
void handle_mouseup_event(GMouseEvent&);
void handle_enter_event(GEvent&);
void handle_leave_event(GEvent&);
void do_layout();
GWindow* m_window { nullptr };
@ -158,6 +165,7 @@ private:
Color m_background_color;
Color m_foreground_color;
RetainPtr<Font> m_font;
String m_tooltip;
SizePolicy m_horizontal_size_policy { SizePolicy::Fill };
SizePolicy m_vertical_size_policy { SizePolicy::Fill };