diff options
author | Matthew Jones <matthewbjones85@gmail.com> | 2021-06-02 14:46:15 -0600 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-02 22:50:51 +0100 |
commit | f0e9fd09b45a1e66fa515db60794baec5bfed059 (patch) | |
tree | 72795574c400ac07f29baaf12e8ec99df2d89f79 | |
parent | d1d1f4f251edb5d13cc96648ab31c9c21fbcee7f (diff) | |
download | serenity-f0e9fd09b45a1e66fa515db60794baec5bfed059.zip |
LibGUI: Tooltip no longer exceeds screen width, now truncates
-rw-r--r-- | Userland/Libraries/LibGUI/Application.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/Application.cpp b/Userland/Libraries/LibGUI/Application.cpp index 6d3aca6564..976303f2fc 100644 --- a/Userland/Libraries/LibGUI/Application.cpp +++ b/Userland/Libraries/LibGUI/Application.cpp @@ -27,7 +27,13 @@ public: void set_tooltip(const String& tooltip) { m_label->set_text(Gfx::parse_ampersand_string(tooltip)); - set_rect(rect().x(), rect().y(), m_label->min_width() + 10, m_label->font().glyph_height() + 8); + int tooltip_width = m_label->min_width() + 10; + + Gfx::IntRect desktop_rect = Desktop::the().rect(); + if (tooltip_width > desktop_rect.width()) + tooltip_width = desktop_rect.width(); + + set_rect(rect().x(), rect().y(), tooltip_width, m_label->font().glyph_height() + 8); } private: @@ -196,6 +202,8 @@ void Application::tooltip_show_timer_did_fire() if (adjusted_pos.y() + m_tooltip_window->height() >= desktop_rect.height() - margin) { adjusted_pos = adjusted_pos.translated(0, -(m_tooltip_window->height() * 2)); } + if (adjusted_pos.x() < 0) + adjusted_pos.set_x(0); m_tooltip_window->move_to(adjusted_pos); m_tooltip_window->show(); |