mirror of
https://github.com/RGBCube/serenity
synced 2025-06-15 21:32:07 +00:00
LibGUI: Clamp selection when drag-selecting over out of range area
This commit is contained in:
parent
bee9cd2113
commit
a95794a356
2 changed files with 21 additions and 10 deletions
|
@ -149,6 +149,18 @@ Optional<int> GlyphMapWidget::glyph_at_position(Gfx::IntPoint position) const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GlyphMapWidget::glyph_at_position_clamped(Gfx::IntPoint position) const
|
||||||
|
{
|
||||||
|
Gfx::IntPoint map_offset { frame_thickness() - horizontal_scrollbar().value(), frame_thickness() - vertical_scrollbar().value() };
|
||||||
|
auto map_position = position - map_offset;
|
||||||
|
auto col = clamp((map_position.x() - 1) / ((font().max_glyph_width() + m_horizontal_spacing)), 0, columns() - 1);
|
||||||
|
auto row = clamp((map_position.y() - 1) / ((font().glyph_height() + m_vertical_spacing)), 0, rows() - 1);
|
||||||
|
auto glyph = row * columns() + col + m_active_range.first;
|
||||||
|
if (row == rows() - 1)
|
||||||
|
glyph = min(glyph, m_glyph_count + m_active_range.first - 1);
|
||||||
|
return glyph;
|
||||||
|
}
|
||||||
|
|
||||||
void GlyphMapWidget::mousedown_event(MouseEvent& event)
|
void GlyphMapWidget::mousedown_event(MouseEvent& event)
|
||||||
{
|
{
|
||||||
Frame::mousedown_event(event);
|
Frame::mousedown_event(event);
|
||||||
|
@ -172,13 +184,13 @@ void GlyphMapWidget::mouseup_event(GUI::MouseEvent& event)
|
||||||
|
|
||||||
if (!m_in_drag_select)
|
if (!m_in_drag_select)
|
||||||
return;
|
return;
|
||||||
|
auto constrained = event.position().constrained(rect().shrunken(0, frame_thickness() * 2));
|
||||||
if (auto maybe_glyph = glyph_at_position(event.position()); maybe_glyph.has_value()) {
|
if (auto maybe_glyph = glyph_at_position(constrained); maybe_glyph.has_value()) {
|
||||||
auto glyph = maybe_glyph.value();
|
auto glyph = maybe_glyph.value();
|
||||||
m_selection.extend_to(glyph);
|
m_selection.extend_to(glyph);
|
||||||
m_in_drag_select = false;
|
|
||||||
set_active_glyph(glyph, ShouldResetSelection::No);
|
set_active_glyph(glyph, ShouldResetSelection::No);
|
||||||
}
|
}
|
||||||
|
m_in_drag_select = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlyphMapWidget::mousemove_event(GUI::MouseEvent& event)
|
void GlyphMapWidget::mousemove_event(GUI::MouseEvent& event)
|
||||||
|
@ -188,13 +200,11 @@ void GlyphMapWidget::mousemove_event(GUI::MouseEvent& event)
|
||||||
if (!m_in_drag_select)
|
if (!m_in_drag_select)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (auto maybe_glyph = glyph_at_position(event.position()); maybe_glyph.has_value()) {
|
auto glyph = glyph_at_position_clamped(event.position());
|
||||||
auto glyph = maybe_glyph.value();
|
m_selection.extend_to(glyph);
|
||||||
m_selection.extend_to(glyph);
|
set_active_glyph(glyph, ShouldResetSelection::No);
|
||||||
set_active_glyph(glyph, ShouldResetSelection::No);
|
scroll_to_glyph(glyph);
|
||||||
scroll_to_glyph(glyph);
|
update();
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlyphMapWidget::doubleclick_event(MouseEvent& event)
|
void GlyphMapWidget::doubleclick_event(MouseEvent& event)
|
||||||
|
|
|
@ -80,6 +80,7 @@ private:
|
||||||
|
|
||||||
Gfx::IntRect get_outer_rect(int glyph) const;
|
Gfx::IntRect get_outer_rect(int glyph) const;
|
||||||
Optional<int> glyph_at_position(Gfx::IntPoint) const;
|
Optional<int> glyph_at_position(Gfx::IntPoint) const;
|
||||||
|
int glyph_at_position_clamped(Gfx::IntPoint) const;
|
||||||
|
|
||||||
void recalculate_content_size();
|
void recalculate_content_size();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue