mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibGUI: Allow setting smooth/coarse scrolling animation on ScrollBar
This commit is contained in:
parent
9ab3ab86cb
commit
91fff3f1ae
2 changed files with 17 additions and 0 deletions
|
@ -114,6 +114,11 @@ bool Scrollbar::has_scrubber() const
|
||||||
return max() != min();
|
return max() != min();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Scrollbar::set_scroll_animation(Animation scroll_animation)
|
||||||
|
{
|
||||||
|
m_scroll_animation = scroll_animation;
|
||||||
|
}
|
||||||
|
|
||||||
void Scrollbar::set_value(int value, AllowCallback allow_callback)
|
void Scrollbar::set_value(int value, AllowCallback allow_callback)
|
||||||
{
|
{
|
||||||
m_target_value = value;
|
m_target_value = value;
|
||||||
|
@ -125,6 +130,9 @@ void Scrollbar::set_value(int value, AllowCallback allow_callback)
|
||||||
|
|
||||||
void Scrollbar::set_target_value(int new_target_value)
|
void Scrollbar::set_target_value(int new_target_value)
|
||||||
{
|
{
|
||||||
|
if (m_scroll_animation == Animation::CoarseScroll)
|
||||||
|
return set_value(new_target_value);
|
||||||
|
|
||||||
new_target_value = clamp(new_target_value, min(), max());
|
new_target_value = clamp(new_target_value, min(), max());
|
||||||
|
|
||||||
// If we are already at or scrolling to the new target then don't touch anything
|
// If we are already at or scrolling to the new target then don't touch anything
|
||||||
|
|
|
@ -23,6 +23,13 @@ public:
|
||||||
|
|
||||||
bool has_scrubber() const;
|
bool has_scrubber() const;
|
||||||
|
|
||||||
|
enum class Animation {
|
||||||
|
SmoothScroll,
|
||||||
|
CoarseScroll
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_scroll_animation(Animation scroll_animation);
|
||||||
|
|
||||||
virtual void set_value(int, AllowCallback = AllowCallback::Yes) override;
|
virtual void set_value(int, AllowCallback = AllowCallback::Yes) override;
|
||||||
void set_target_value(int);
|
void set_target_value(int);
|
||||||
|
|
||||||
|
@ -79,6 +86,8 @@ private:
|
||||||
|
|
||||||
void update_animated_scroll();
|
void update_animated_scroll();
|
||||||
|
|
||||||
|
Animation m_scroll_animation { Animation::SmoothScroll };
|
||||||
|
|
||||||
int m_target_value { 0 };
|
int m_target_value { 0 };
|
||||||
int m_start_value { 0 };
|
int m_start_value { 0 };
|
||||||
double m_animation_time_elapsed { 0 };
|
double m_animation_time_elapsed { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue