1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 19:05:08 +00:00

LibGUI: Take scroll offset into account on ItemView rubberband selection

Same kind of issue as #1271.
This commit is contained in:
Tibor Nagy 2020-03-12 15:42:43 +01:00 committed by Andreas Kling
parent ee5a49e2fe
commit b58893cfe1
2 changed files with 16 additions and 5 deletions

View file

@ -129,7 +129,7 @@ ModelIndex ItemView::index_at_event_position(const Gfx::Point& position) const
ASSERT(model());
// FIXME: Since all items are the same size, just compute the clicked item index
// instead of iterating over everything.
auto adjusted_position = position.translated(0, vertical_scrollbar().value());
auto adjusted_position = this->adjusted_position(position);
const auto& column_metadata = model()->column_metadata(model_column());
const auto& font = column_metadata.font ? *column_metadata.font : this->font();
for (int item_index = 0; item_index < item_count(); ++item_index) {
@ -145,6 +145,11 @@ ModelIndex ItemView::index_at_event_position(const Gfx::Point& position) const
return {};
}
Gfx::Point ItemView::adjusted_position(const Gfx::Point& position) const
{
return position.translated(0, vertical_scrollbar().value());
}
void ItemView::mousedown_event(MouseEvent& event)
{
if (!model())
@ -169,10 +174,12 @@ void ItemView::mousedown_event(MouseEvent& event)
selection().clear();
}
auto adjusted_position = this->adjusted_position(event.position());
m_might_drag = false;
m_rubber_banding = true;
m_rubber_band_origin = event.position();
m_rubber_band_current = event.position();
m_rubber_band_origin = adjusted_position;
m_rubber_band_current = adjusted_position;
}
void ItemView::mouseup_event(MouseEvent& event)
@ -210,8 +217,9 @@ void ItemView::mousemove_event(MouseEvent& event)
return AbstractView::mousemove_event(event);
if (m_rubber_banding) {
if (m_rubber_band_current != event.position()) {
m_rubber_band_current = event.position();
auto adjusted_position = this->adjusted_position(event.position());
if (m_rubber_band_current != adjusted_position) {
m_rubber_band_current = adjusted_position;
auto rubber_band_rect = Gfx::Rect::from_two_points(m_rubber_band_origin, m_rubber_band_current);
selection().clear();
for (auto item_index : items_intersecting_rect(rubber_band_rect)) {
@ -249,6 +257,8 @@ void ItemView::second_paint_event(PaintEvent& event)
Painter painter(*this);
painter.add_clip_rect(event.rect());
painter.translate(frame_thickness(), frame_thickness());
painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
auto rubber_band_rect = Gfx::Rect::from_two_points(m_rubber_band_origin, m_rubber_band_current);
painter.fill_rect(rubber_band_rect, parent_widget()->palette().rubber_band_fill());