mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57: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:
parent
5a91f5b320
commit
3c8493c667
5 changed files with 12 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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); }
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue