From f4515aae80b8c7000e728b8b38bad58f388fcbf0 Mon Sep 17 00:00:00 2001 From: Gabriel Nava Marino Date: Tue, 10 Oct 2023 15:20:27 -0400 Subject: [PATCH] Userland: Draw tooltip over glyph to show UTF-8 code point Currently finding a particular glyph with a given code point is a bit tedious as it requires clicking on the glyph to update the status bar and display the glyph's name and codepoint. A more convenient way to know where we are in the Glyph Map is by seeing a tooltip over the glyph where the mouse is currently hovering over. This patch adds that support by setting the Widget tooltip with the glyph found at the current position in GlyphMapWidget::mousemove_event. --- Userland/Libraries/LibGUI/GlyphMapWidget.cpp | 11 +++++++++++ Userland/Libraries/LibGUI/GlyphMapWidget.h | 1 + 2 files changed, 12 insertions(+) diff --git a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp index a4d1acd49c..f3399cfe14 100644 --- a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp +++ b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp @@ -247,6 +247,17 @@ void GlyphMapWidget::mouseup_event(GUI::MouseEvent& event) void GlyphMapWidget::mousemove_event(GUI::MouseEvent& event) { m_last_mousemove_position = event.position(); + if (auto maybe_glyph = glyph_at_position(event.position()); maybe_glyph.has_value() && maybe_glyph != m_tooltip_glyph) { + m_tooltip_glyph = maybe_glyph.value(); + auto draw_tooltip = [this]() -> ErrorOr { + StringBuilder builder; + TRY(builder.try_appendff("U+{:04X}", m_tooltip_glyph)); + set_tooltip(TRY(builder.to_string())); + return {}; + }(); + if (draw_tooltip.is_error()) + warnln("Failed to draw tooltip"); + } if (m_in_drag_select) { auto constrained = event.position().constrained(widget_inner_rect()); auto glyph = glyph_at_position_clamped(constrained); diff --git a/Userland/Libraries/LibGUI/GlyphMapWidget.h b/Userland/Libraries/LibGUI/GlyphMapWidget.h index f90bbfea1b..62b30f38a6 100644 --- a/Userland/Libraries/LibGUI/GlyphMapWidget.h +++ b/Userland/Libraries/LibGUI/GlyphMapWidget.h @@ -111,6 +111,7 @@ private: int m_vertical_spacing { 4 }; Selection m_selection; int m_active_glyph { 0 }; + int m_tooltip_glyph { 0 }; int m_visible_glyphs { 0 }; bool m_in_drag_select { false }; bool m_highlight_modifications { false };