mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:47:44 +00:00
LibGUI: Add a AutoScroll timer to AbstractScrollableWidget
This commit adds a timer to AbstractScrollableWidget that can be used when implementing automatic scrolling. By overriding on_automatic_scrolling_timer_fired() we can calculate the scrolling delta when dragging objects, and redraw as needed. A helper function, automatic_scroll_delta_from_position() gives us a delta that we can use to calculate speed and direction. By default m_autoscroll_threshold is 20 pixels from the edge, and gives a linear change in scroll delta.
This commit is contained in:
parent
522119ab95
commit
eec411c508
2 changed files with 47 additions and 0 deletions
|
@ -51,6 +51,9 @@ public:
|
|||
void scroll_to_top();
|
||||
void scroll_to_bottom();
|
||||
|
||||
void set_automatic_scrolling_timer(bool active);
|
||||
Gfx::IntPoint automatic_scroll_delta_from_position(const Gfx::IntPoint&) const;
|
||||
|
||||
int width_occupied_by_vertical_scrollbar() const;
|
||||
int height_occupied_by_horizontal_scrollbar() const;
|
||||
|
||||
|
@ -71,6 +74,7 @@ protected:
|
|||
virtual void did_scroll() { }
|
||||
void set_content_size(const Gfx::IntSize&);
|
||||
void set_size_occupied_by_fixed_elements(const Gfx::IntSize&);
|
||||
virtual void on_automatic_scrolling_timer_fired() {};
|
||||
|
||||
private:
|
||||
class AbstractScrollableWidgetScrollbar final : public Scrollbar {
|
||||
|
@ -103,6 +107,10 @@ private:
|
|||
Gfx::IntSize m_size_occupied_by_fixed_elements;
|
||||
bool m_scrollbars_enabled { true };
|
||||
bool m_should_hide_unnecessary_scrollbars { false };
|
||||
|
||||
RefPtr<Core::Timer> m_automatic_scrolling_timer;
|
||||
bool m_active_scrolling_enabled { false };
|
||||
int m_autoscroll_threshold { 20 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue