Skip to content

Commit ac53af6

Browse files
committed
LibGUI: Mouse events didn't hit table headers when vertically scrolled
Only take the horizontal scroll into account when hit testing the table view headers.
1 parent 4f99c37 commit ac53af6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Libraries/LibGUI/AbstractTableView.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ void AbstractTableView::mousemove_event(MouseEvent& event)
263263
return AbstractView::mousemove_event(event);
264264

265265
auto adjusted_position = this->adjusted_position(event.position());
266+
Gfx::Point horizontally_adjusted_position(adjusted_position.x(), event.position().y());
266267

267268
if (m_in_column_resize) {
268269
auto delta = adjusted_position - m_column_resize_origin;
@@ -281,7 +282,7 @@ void AbstractTableView::mousemove_event(MouseEvent& event)
281282

282283
if (m_pressed_column_header_index != -1) {
283284
auto header_rect = this->header_rect(m_pressed_column_header_index);
284-
if (header_rect.contains(adjusted_position)) {
285+
if (header_rect.contains(horizontally_adjusted_position)) {
285286
set_hovered_header_index(m_pressed_column_header_index);
286287
if (!m_pressed_column_header_is_pressed)
287288
update_headers();
@@ -299,12 +300,12 @@ void AbstractTableView::mousemove_event(MouseEvent& event)
299300
int column_count = model()->column_count();
300301
bool found_hovered_header = false;
301302
for (int i = 0; i < column_count; ++i) {
302-
if (column_resize_grabbable_rect(i).contains(adjusted_position)) {
303+
if (column_resize_grabbable_rect(i).contains(horizontally_adjusted_position)) {
303304
window()->set_override_cursor(StandardCursor::ResizeHorizontal);
304305
set_hovered_header_index(-1);
305306
return;
306307
}
307-
if (header_rect(i).contains(adjusted_position)) {
308+
if (header_rect(i).contains(horizontally_adjusted_position)) {
308309
set_hovered_header_index(i);
309310
found_hovered_header = true;
310311
}
@@ -320,16 +321,17 @@ void AbstractTableView::mousemove_event(MouseEvent& event)
320321
void AbstractTableView::mouseup_event(MouseEvent& event)
321322
{
322323
auto adjusted_position = this->adjusted_position(event.position());
324+
Gfx::Point horizontally_adjusted_position(adjusted_position.x(), event.position().y());
323325
if (event.button() == MouseButton::Left) {
324326
if (m_in_column_resize) {
325-
if (!column_resize_grabbable_rect(m_resizing_column).contains(adjusted_position))
327+
if (!column_resize_grabbable_rect(m_resizing_column).contains(horizontally_adjusted_position))
326328
window()->set_override_cursor(StandardCursor::None);
327329
m_in_column_resize = false;
328330
return;
329331
}
330332
if (m_pressed_column_header_index != -1) {
331333
auto header_rect = this->header_rect(m_pressed_column_header_index);
332-
if (header_rect.contains(adjusted_position)) {
334+
if (header_rect.contains(horizontally_adjusted_position)) {
333335
auto new_sort_order = SortOrder::Ascending;
334336
if (model()->key_column() == m_pressed_column_header_index)
335337
new_sort_order = model()->sort_order() == SortOrder::Ascending
@@ -356,11 +358,12 @@ void AbstractTableView::mousedown_event(MouseEvent& event)
356358
return AbstractView::mousedown_event(event);
357359

358360
auto adjusted_position = this->adjusted_position(event.position());
361+
Gfx::Point horizontally_adjusted_position(adjusted_position.x(), event.position().y());
359362

360363
if (event.y() < header_height()) {
361364
int column_count = model()->column_count();
362365
for (int i = 0; i < column_count; ++i) {
363-
if (column_resize_grabbable_rect(i).contains(adjusted_position)) {
366+
if (column_resize_grabbable_rect(i).contains(horizontally_adjusted_position)) {
364367
m_resizing_column = i;
365368
m_in_column_resize = true;
366369
m_column_resize_original_width = column_width(i);
@@ -369,7 +372,7 @@ void AbstractTableView::mousedown_event(MouseEvent& event)
369372
}
370373
auto header_rect = this->header_rect(i);
371374
auto column_metadata = model()->column_metadata(i);
372-
if (header_rect.contains(adjusted_position) && column_metadata.sortable == Model::ColumnMetadata::Sortable::True) {
375+
if (header_rect.contains(horizontally_adjusted_position) && column_metadata.sortable == Model::ColumnMetadata::Sortable::True) {
373376
m_pressed_column_header_index = i;
374377
m_pressed_column_header_is_pressed = true;
375378
update_headers();

0 commit comments

Comments
 (0)