mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +00:00
LibGUI: Add automatic scrolling to GlyphMapWidget
Similar to TextEditor, GlyphMapWidget now automatically scrolls when dragging a selection outside its boundaries.
This commit is contained in:
parent
a26e71a137
commit
5c6326ae23
2 changed files with 18 additions and 8 deletions
|
@ -54,6 +54,19 @@ GlyphMapWidget::GlyphMapWidget()
|
||||||
horizontal_scrollbar().set_visible(false);
|
horizontal_scrollbar().set_visible(false);
|
||||||
did_change_font();
|
did_change_font();
|
||||||
set_active_glyph('A');
|
set_active_glyph('A');
|
||||||
|
|
||||||
|
m_automatic_selection_scroll_timer = add<Core::Timer>(20, [this] {
|
||||||
|
if (!m_in_drag_select) {
|
||||||
|
m_automatic_selection_scroll_timer->stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto glyph = glyph_at_position_clamped(m_last_mousemove_position);
|
||||||
|
m_selection.extend_to(glyph);
|
||||||
|
set_active_glyph(glyph, ShouldResetSelection::No);
|
||||||
|
scroll_to_glyph(glyph);
|
||||||
|
update();
|
||||||
|
});
|
||||||
|
m_automatic_selection_scroll_timer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlyphMapWidget::resize_event(ResizeEvent& event)
|
void GlyphMapWidget::resize_event(ResizeEvent& event)
|
||||||
|
@ -168,6 +181,7 @@ void GlyphMapWidget::mousedown_event(MouseEvent& event)
|
||||||
if (event.shift())
|
if (event.shift())
|
||||||
m_selection.extend_to(glyph);
|
m_selection.extend_to(glyph);
|
||||||
m_in_drag_select = true;
|
m_in_drag_select = true;
|
||||||
|
m_automatic_selection_scroll_timer->start();
|
||||||
set_active_glyph(glyph, event.shift() ? ShouldResetSelection::No : ShouldResetSelection::Yes);
|
set_active_glyph(glyph, event.shift() ? ShouldResetSelection::No : ShouldResetSelection::Yes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,14 +201,7 @@ void GlyphMapWidget::mouseup_event(GUI::MouseEvent& event)
|
||||||
|
|
||||||
void GlyphMapWidget::mousemove_event(GUI::MouseEvent& event)
|
void GlyphMapWidget::mousemove_event(GUI::MouseEvent& event)
|
||||||
{
|
{
|
||||||
if (!m_in_drag_select)
|
m_last_mousemove_position = event.position();
|
||||||
return;
|
|
||||||
|
|
||||||
auto glyph = glyph_at_position_clamped(event.position());
|
|
||||||
m_selection.extend_to(glyph);
|
|
||||||
set_active_glyph(glyph, ShouldResetSelection::No);
|
|
||||||
scroll_to_glyph(glyph);
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlyphMapWidget::doubleclick_event(MouseEvent& event)
|
void GlyphMapWidget::doubleclick_event(MouseEvent& event)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibCore/Timer.h>
|
||||||
#include <LibGUI/AbstractScrollableWidget.h>
|
#include <LibGUI/AbstractScrollableWidget.h>
|
||||||
#include <LibGUI/TextRange.h>
|
#include <LibGUI/TextRange.h>
|
||||||
#include <LibGfx/BitmapFont.h>
|
#include <LibGfx/BitmapFont.h>
|
||||||
|
@ -94,6 +95,8 @@ private:
|
||||||
int m_visible_glyphs { 0 };
|
int m_visible_glyphs { 0 };
|
||||||
bool m_in_drag_select { false };
|
bool m_in_drag_select { false };
|
||||||
Unicode::CodePointRange m_active_range { 0x0000, 0x10FFFF };
|
Unicode::CodePointRange m_active_range { 0x0000, 0x10FFFF };
|
||||||
|
RefPtr<Core::Timer> m_automatic_selection_scroll_timer;
|
||||||
|
Gfx::IntPoint m_last_mousemove_position;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue