Jelajahi Sumber

LibGUI: Add AbstractTableView::scroll_into_view(ModelIndex, bool, bool)

This API lets you specify whether to scroll horizontally, vertically,
or both.
Andreas Kling 4 tahun lalu
induk
melakukan
e5a6e297bf

+ 6 - 0
Libraries/LibGUI/AbstractTableView.cpp

@@ -460,6 +460,12 @@ void AbstractTableView::scroll_into_view(const ModelIndex& index, Orientation or
     ScrollableWidget::scroll_into_view(rect, orientation);
 }
 
+void AbstractTableView::scroll_into_view(const ModelIndex& index, bool scroll_horizontally, bool scroll_vertically)
+{
+    auto rect = row_rect(index.row()).translated(0, -header_height());
+    ScrollableWidget::scroll_into_view(rect, scroll_horizontally, scroll_vertically);
+}
+
 void AbstractTableView::doubleclick_event(MouseEvent& event)
 {
     if (!model())

+ 1 - 0
Libraries/LibGUI/AbstractTableView.h

@@ -71,6 +71,7 @@ public:
     Gfx::IntRect row_rect(int item_index) const;
 
     void scroll_into_view(const ModelIndex&, Orientation);
+    void scroll_into_view(const ModelIndex&, bool scroll_horizontally, bool scroll_vertically);
 
     virtual ModelIndex index_at_event_position(const Gfx::IntPoint&, bool& is_toggle) const;
     virtual ModelIndex index_at_event_position(const Gfx::IntPoint&) const override;