From 3b445bc66ac8d15847e0ede434a9552eb11c1145 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 30 Dec 2020 14:47:22 +0100 Subject: [PATCH] LibGUI: Add page_step setting to AbstractSlider and use it in Slider This makes clicking on the track of a GUI::Slider actually move the knob more than 1 value unit (assuming page_step > 1) --- Libraries/LibGUI/AbstractSlider.cpp | 7 +++++++ Libraries/LibGUI/AbstractSlider.h | 3 +++ Libraries/LibGUI/Slider.cpp | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Libraries/LibGUI/AbstractSlider.cpp b/Libraries/LibGUI/AbstractSlider.cpp index 75d6f63c07..551b93126b 100644 --- a/Libraries/LibGUI/AbstractSlider.cpp +++ b/Libraries/LibGUI/AbstractSlider.cpp @@ -36,9 +36,11 @@ namespace GUI { AbstractSlider::AbstractSlider(Orientation orientation) : m_orientation(orientation) { + REGISTER_INT_PROPERTY("value", value, set_value); REGISTER_INT_PROPERTY("min", min, set_min); REGISTER_INT_PROPERTY("max", max, set_max); REGISTER_INT_PROPERTY("step", step, set_step); + REGISTER_INT_PROPERTY("page_step", page_step, set_page_step); REGISTER_ENUM_PROPERTY("orientation", this->orientation, set_orientation, Orientation, { Orientation::Horizontal, "Horizontal" }, { Orientation::Vertical, "Vertical" }); @@ -56,6 +58,11 @@ void AbstractSlider::set_orientation(Orientation value) update(); } +void AbstractSlider::set_page_step(int page_step) +{ + m_page_step = AK::max(0, page_step); +} + void AbstractSlider::set_range(int min, int max) { ASSERT(min <= max); diff --git a/Libraries/LibGUI/AbstractSlider.h b/Libraries/LibGUI/AbstractSlider.h index 98ec292b70..b61131cc21 100644 --- a/Libraries/LibGUI/AbstractSlider.h +++ b/Libraries/LibGUI/AbstractSlider.h @@ -43,6 +43,7 @@ public: int min() const { return m_min; } int max() const { return m_max; } int step() const { return m_step; } + int page_step() const { return m_page_step; } void set_range(int min, int max); void set_value(int); @@ -50,6 +51,7 @@ public: void set_min(int min) { set_range(min, max()); } void set_max(int max) { set_range(min(), max); } void set_step(int step) { m_step = step; } + void set_page_step(int page_step); Function on_value_changed; @@ -63,6 +65,7 @@ private: int m_min { 0 }; int m_max { 100 }; int m_step { 1 }; + int m_page_step { 10 }; Orientation m_orientation { Orientation::Horizontal }; }; diff --git a/Libraries/LibGUI/Slider.cpp b/Libraries/LibGUI/Slider.cpp index 68ca874736..6989f251c2 100644 --- a/Libraries/LibGUI/Slider.cpp +++ b/Libraries/LibGUI/Slider.cpp @@ -105,9 +105,9 @@ void Slider::mousedown_event(MouseEvent& event) return; } else { if (event.position().primary_offset_for_orientation(orientation()) > knob_rect().last_edge_for_orientation(orientation())) - set_value(value() + 1); + set_value(value() + page_step()); else if (event.position().primary_offset_for_orientation(orientation()) < knob_rect().first_edge_for_orientation(orientation())) - set_value(value() - 1); + set_value(value() - page_step()); } } return Widget::mousedown_event(event);