diff options
author | David Isaksson <davidisaksson93@gmail.com> | 2021-09-18 12:16:57 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-19 21:52:32 +0200 |
commit | 3c8493c667991574b159fe8f74d9ff625cdd5aab (patch) | |
tree | 7f0f8ce6ab1d1b25caadd3452fa715241ca8f461 /Userland | |
parent | 5a91f5b3205c98431a87cfa1d22c8df9cfb667b0 (diff) | |
download | serenity-3c8493c667991574b159fe8f74d9ff625cdd5aab.zip |
LibGUI: Add option to disable on_change call for sliders set_value()
This makes it possible to avoid messy situations where a slider
controlled value can be changed from multiple sources.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGUI/AbstractSlider.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/AbstractSlider.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/ValueSlider.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/ValueSlider.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Widget.h | 6 |
5 files changed, 12 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGUI/AbstractSlider.cpp b/Userland/Libraries/LibGUI/AbstractSlider.cpp index ccb0613c1b..c6109ad6cf 100644 --- a/Userland/Libraries/LibGUI/AbstractSlider.cpp +++ b/Userland/Libraries/LibGUI/AbstractSlider.cpp @@ -53,7 +53,7 @@ void AbstractSlider::set_range(int min, int max) update(); } -void AbstractSlider::set_value(int value) +void AbstractSlider::set_value(int value, CallOnChange call_on_change) { value = clamp(value, m_min, m_max); if (m_value == value) @@ -61,7 +61,7 @@ void AbstractSlider::set_value(int value) m_value = value; update(); - if (on_change) + if (on_change && call_on_change == CallOnChange::Yes) on_change(m_value); } diff --git a/Userland/Libraries/LibGUI/AbstractSlider.h b/Userland/Libraries/LibGUI/AbstractSlider.h index f3a1991982..dc6204e9e5 100644 --- a/Userland/Libraries/LibGUI/AbstractSlider.h +++ b/Userland/Libraries/LibGUI/AbstractSlider.h @@ -30,7 +30,7 @@ public: bool is_max() const { return m_value == m_max; } void set_range(int min, int max); - virtual void set_value(int); + virtual void set_value(int, CallOnChange call_on_change = CallOnChange::Yes); void set_min(int min) { set_range(min, max()); } void set_max(int max) { set_range(min(), max); } diff --git a/Userland/Libraries/LibGUI/ValueSlider.cpp b/Userland/Libraries/LibGUI/ValueSlider.cpp index 4039f884d6..227c8ba607 100644 --- a/Userland/Libraries/LibGUI/ValueSlider.cpp +++ b/Userland/Libraries/LibGUI/ValueSlider.cpp @@ -141,9 +141,9 @@ int ValueSlider::value_at(const Gfx::IntPoint& position) const return (int)(relative_offset * (float)max()); } -void ValueSlider::set_value(int value) +void ValueSlider::set_value(int value, CallOnChange call_on_change) { - AbstractSlider::set_value(value); + AbstractSlider::set_value(value, call_on_change); m_textbox->set_text(formatted_value()); } diff --git a/Userland/Libraries/LibGUI/ValueSlider.h b/Userland/Libraries/LibGUI/ValueSlider.h index 886e1adf18..b9a3c91f3c 100644 --- a/Userland/Libraries/LibGUI/ValueSlider.h +++ b/Userland/Libraries/LibGUI/ValueSlider.h @@ -24,7 +24,7 @@ public: void set_suffix(String suffix) { m_suffix = move(suffix); } void set_knob_style(KnobStyle knobstyle) { m_knob_style = knobstyle; } - virtual void set_value(int value) override; + virtual void set_value(int value, CallOnChange call_on_change = CallOnChange::Yes) override; protected: virtual void paint_event(PaintEvent&) override; diff --git a/Userland/Libraries/LibGUI/Widget.h b/Userland/Libraries/LibGUI/Widget.h index 2327533830..e90f1c6269 100644 --- a/Userland/Libraries/LibGUI/Widget.h +++ b/Userland/Libraries/LibGUI/Widget.h @@ -39,6 +39,7 @@ enum class HorizontalDirection { Left, Right }; + enum class VerticalDirection { Up, Down @@ -53,6 +54,11 @@ enum class FocusPolicy { AK_ENUM_BITWISE_OPERATORS(FocusPolicy) +enum class CallOnChange { + No, + Yes +}; + class Widget : public Core::Object { C_OBJECT(Widget) public: |