summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorKarol Kosek <krkk@serenityos.org>2022-12-28 00:35:30 +0100
committerAndreas Kling <kling@serenityos.org>2022-12-30 17:16:29 +0100
commite673fc41837e003f8b787c57a852c202f0cd26e6 (patch)
tree9750716c9fc18003d6fdd5d784e7f35d30921e6e /Userland
parente40726cb348b6ffb77778a82d33827afb590e261 (diff)
downloadserenity-e673fc41837e003f8b787c57a852c202f0cd26e6.zip
LibGUI: Determine model index from a content position in ColumnsView
We didn't take the scroll value into account when we were converting a position to an index, which basically prevented us from selecting a desired file if a list wasn't small enough to fit entirely in the widget box.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/ColumnsView.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/Userland/Libraries/LibGUI/ColumnsView.cpp b/Userland/Libraries/LibGUI/ColumnsView.cpp
index 53cf83f687..f5ec502982 100644
--- a/Userland/Libraries/LibGUI/ColumnsView.cpp
+++ b/Userland/Libraries/LibGUI/ColumnsView.cpp
@@ -241,13 +241,11 @@ void ColumnsView::update_column_sizes()
set_content_size({ total_width, total_height });
}
-Optional<ColumnsView::Column> ColumnsView::column_at_event_position(Gfx::IntPoint a_position) const
+Optional<ColumnsView::Column> ColumnsView::column_at_event_position(Gfx::IntPoint position) const
{
if (!model())
return {};
- auto position = a_position.translated(horizontal_scrollbar().value() - frame_thickness(), vertical_scrollbar().value() - frame_thickness());
-
int column_x = 0;
for (auto const& column : m_columns) {
@@ -288,8 +286,9 @@ ModelIndex ColumnsView::index_at_event_position_in_column(Gfx::IntPoint position
return model()->index(row, m_model_column, column.parent_index);
}
-ModelIndex ColumnsView::index_at_event_position(Gfx::IntPoint position) const
+ModelIndex ColumnsView::index_at_event_position(Gfx::IntPoint widget_position) const
{
+ auto position = to_content_position(widget_position);
auto const& column = column_at_event_position(position);
if (!column.has_value())
return {};
@@ -307,11 +306,12 @@ void ColumnsView::mousedown_event(MouseEvent& event)
if (event.button() != MouseButton::Primary)
return;
- auto column = column_at_event_position(event.position());
+ auto position = to_content_position(event.position());
+ auto column = column_at_event_position(position);
if (!column.has_value())
return;
- auto index = index_at_event_position_in_column(event.position(), *column);
+ auto index = index_at_event_position_in_column(position, *column);
if (index.is_valid() && !(event.modifiers() & Mod_Ctrl)) {
if (model()->row_count(index))
push_column(index);
@@ -321,8 +321,8 @@ void ColumnsView::mousedown_event(MouseEvent& event)
if (selection_mode() == SelectionMode::MultiSelection) {
m_rubber_banding = true;
m_rubber_band_origin_column = *column;
- m_rubber_band_origin = event.position().y();
- m_rubber_band_current = event.position().y();
+ m_rubber_band_origin = position.y();
+ m_rubber_band_current = position.y();
}
}