瀏覽代碼

LibGUI: Add GScrollableWidget::scroll_to_bottom/top().

Andreas Kling 6 年之前
父節點
當前提交
9551e2e4b5
共有 2 個文件被更改,包括 13 次插入0 次删除
  1. 10 0
      LibGUI/GScrollableWidget.cpp
  2. 3 0
      LibGUI/GScrollableWidget.h

+ 10 - 0
LibGUI/GScrollableWidget.cpp

@@ -124,3 +124,13 @@ void GScrollableWidget::set_scrollbars_enabled(bool scrollbars_enabled)
     m_horizontal_scrollbar->set_visible(m_scrollbars_enabled);
     m_corner_widget->set_visible(m_scrollbars_enabled);
 }
+
+void GScrollableWidget::scroll_to_top()
+{
+    scroll_into_view({ 0, 0, 1, 1 }, Orientation::Vertical);
+}
+
+void GScrollableWidget::scroll_to_bottom()
+{
+    scroll_into_view({ 0, content_height(), 1, 1 }, Orientation::Vertical);
+}

+ 3 - 0
LibGUI/GScrollableWidget.h

@@ -27,6 +27,9 @@ public:
     GWidget& corner_widget() { return *m_corner_widget; }
     const GWidget& corner_widget() const { return *m_corner_widget; }
 
+    void scroll_to_top();
+    void scroll_to_bottom();
+
     virtual const char* class_name() const override { return "GScrollableWidget"; }
 
 protected: