1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

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.
This commit is contained in:
David Isaksson 2021-09-18 12:16:57 +02:00 committed by Andreas Kling
parent 5a91f5b320
commit 3c8493c667
5 changed files with 12 additions and 6 deletions

View file

@ -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);
}

View file

@ -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); }

View file

@ -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());
}

View file

@ -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;

View file

@ -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: