mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
LibGUI: Standardize automatic scrolling in TextEditor+GlyphMapWidget
Both widgets now make use of their base class's scrolling timer and now always accept drag selection updates on mousemove_event(). This guarantees much snappier feeling selections when actively moving the mouse.
This commit is contained in:
parent
d938b9effe
commit
804baa42f9
4 changed files with 45 additions and 30 deletions
|
@ -54,19 +54,6 @@ GlyphMapWidget::GlyphMapWidget()
|
|||
horizontal_scrollbar().set_visible(false);
|
||||
did_change_font();
|
||||
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)
|
||||
|
@ -233,7 +220,6 @@ void GlyphMapWidget::mousedown_event(MouseEvent& event)
|
|||
if (event.shift())
|
||||
m_selection.extend_to(glyph);
|
||||
m_in_drag_select = true;
|
||||
m_automatic_selection_scroll_timer->start();
|
||||
set_active_glyph(glyph, event.shift() ? ShouldResetSelection::No : ShouldResetSelection::Yes);
|
||||
}
|
||||
}
|
||||
|
@ -257,6 +243,27 @@ void GlyphMapWidget::mouseup_event(GUI::MouseEvent& event)
|
|||
void GlyphMapWidget::mousemove_event(GUI::MouseEvent& event)
|
||||
{
|
||||
m_last_mousemove_position = event.position();
|
||||
if (m_in_drag_select) {
|
||||
auto constrained = event.position().constrained(widget_inner_rect());
|
||||
auto glyph = glyph_at_position_clamped(constrained);
|
||||
m_selection.extend_to(glyph);
|
||||
set_active_glyph(glyph, ShouldResetSelection::No);
|
||||
scroll_to_glyph(glyph);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void GlyphMapWidget::automatic_scrolling_timer_did_fire()
|
||||
{
|
||||
if (!m_in_drag_select) {
|
||||
set_automatic_scrolling_timer_active(false);
|
||||
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();
|
||||
}
|
||||
|
||||
void GlyphMapWidget::doubleclick_event(MouseEvent& event)
|
||||
|
@ -569,6 +576,17 @@ ErrorOr<void> GlyphMapWidget::set_font(Gfx::Font const& font)
|
|||
return {};
|
||||
}
|
||||
|
||||
void GlyphMapWidget::enter_event(Core::Event&)
|
||||
{
|
||||
set_automatic_scrolling_timer_active(false);
|
||||
}
|
||||
|
||||
void GlyphMapWidget::leave_event(Core::Event&)
|
||||
{
|
||||
if (m_in_drag_select)
|
||||
set_automatic_scrolling_timer_active(true);
|
||||
}
|
||||
|
||||
Optional<UISize> GlyphMapWidget::calculated_min_size() const
|
||||
{
|
||||
auto scrollbar = vertical_scrollbar().effective_min_size().height().as_int();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue