1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 03:08:13 +00:00

LibGUI: Rename CallOnChange => AllowCallback and implement elsewhere

This is a helpful option to prevent unwanted side effects, distinguish
between user and programmatic input, etc. Sliders and SpinBoxes were
implementing it idiosyncratically, so let's generalize the API and
give Buttons and TextEditors the same ability.
This commit is contained in:
thankyouverycool 2021-09-21 17:02:48 -04:00 committed by Andreas Kling
parent d47e431d54
commit 92fffc3abc
15 changed files with 40 additions and 39 deletions

View file

@ -53,7 +53,7 @@ SpinBox::~SpinBox()
{
}
void SpinBox::set_value(int value)
void SpinBox::set_value(int value, AllowCallback allow_callback)
{
value = clamp(value, m_min, m_max);
if (m_value == value)
@ -61,11 +61,11 @@ void SpinBox::set_value(int value)
m_value = value;
m_editor->set_text(String::number(value));
update();
if (on_change)
if (on_change && allow_callback == AllowCallback::Yes)
on_change(value);
}
void SpinBox::set_range(int min, int max, bool change)
void SpinBox::set_range(int min, int max, AllowCallback allow_callback)
{
VERIFY(min <= max);
if (m_min == min && m_max == max)
@ -78,7 +78,7 @@ void SpinBox::set_range(int min, int max, bool change)
m_value = clamp(m_value, m_min, m_max);
if (m_value != old_value) {
m_editor->set_text(String::number(m_value));
if (change && on_change)
if (on_change && allow_callback == AllowCallback::Yes)
on_change(m_value);
}