Parcourir la source

LibGUI: Support GTableView navigation with Page Up and Page Down.

Also base the vertical scrollbar's gutter range on the visible content rect,
making it very similar to a Page Up/Down. Maybe they should be exactly the
same, I don't know.
Andreas Kling il y a 6 ans
Parent
commit
63cdc3d2d5
1 fichiers modifiés avec 22 ajouts et 1 suppressions
  1. 22 1
      LibGUI/GTableView.cpp

+ 22 - 1
LibGUI/GTableView.cpp

@@ -11,7 +11,6 @@ GTableView::GTableView(GWidget* parent)
 
     m_vertical_scrollbar = new GScrollBar(Orientation::Vertical, this);
     m_vertical_scrollbar->set_step(4);
-    m_vertical_scrollbar->set_big_step(30);
     m_vertical_scrollbar->on_change = [this] (int) {
         update();
     };
@@ -55,6 +54,8 @@ void GTableView::update_scrollbar_ranges()
     int available_width = width() - m_vertical_scrollbar->width();
     int excess_width = max(0, content_width() - available_width);
     m_horizontal_scrollbar->set_range(0, excess_width);
+
+    m_vertical_scrollbar->set_big_step(visible_content_rect().height() - item_height());
 }
 
 int GTableView::content_width() const
@@ -196,6 +197,26 @@ void GTableView::keydown_event(GKeyEvent& event)
         }
         return;
     }
+    if (event.key() == KeyCode::Key_PageUp) {
+        int items_per_page = visible_content_rect().height() / item_height();
+        GModelIndex new_index(max(0, model.selected_index().row() - items_per_page), model.selected_index().column());
+        if (model.is_valid(new_index)) {
+            model.set_selected_index(new_index);
+            scroll_into_view(new_index, Orientation::Vertical);
+            update();
+        }
+        return;
+    }
+    if (event.key() == KeyCode::Key_PageDown) {
+        int items_per_page = visible_content_rect().height() / item_height();
+        GModelIndex new_index(min(model.row_count() - 1, model.selected_index().row() + items_per_page), model.selected_index().column());
+        if (model.is_valid(new_index)) {
+            model.set_selected_index(new_index);
+            scroll_into_view(new_index, Orientation::Vertical);
+            update();
+        }
+        return;
+    }
     return GWidget::keydown_event(event);
 }