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.
This commit is contained in:
Gabriel Nava Marino 2023-10-10 15:20:27 -04:00 committed by Andreas Kling
parent 3748f1d290
commit f4515aae80
Notes: sideshowbarker 2024-07-17 17:06:59 +09:00
2 changed files with 12 additions and 0 deletions

View file

@ -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<void> {
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);

View file

@ -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 };