mirror of
https://github.com/RGBCube/serenity
synced 2025-06-28 16:42:12 +00:00
LibGUI: Add AllowCallback parameter to ColorInput::set_color()
The `TextEditor::on_change` callback now only fires if the user types in the box, or `set_text()` is called with `AllowCallback::Yes`. Previously that callback was what set `m_color`, so I've rearranged things a little so that the color still updates regardless of what source the color came from.
This commit is contained in:
parent
91230ff28d
commit
5fd0140772
2 changed files with 9 additions and 9 deletions
|
@ -23,7 +23,7 @@ ColorInput::ColorInput()
|
|||
TextEditor::on_change = [this] {
|
||||
auto parsed_color = Color::from_string(text());
|
||||
if (parsed_color.has_value())
|
||||
set_color_without_changing_text(parsed_color.value());
|
||||
set_color_internal(parsed_color.value(), AllowCallback::Yes, false);
|
||||
};
|
||||
|
||||
REGISTER_STRING_PROPERTY("color_picker_title", color_picker_title, set_color_picker_title);
|
||||
|
@ -37,21 +37,21 @@ Gfx::IntRect ColorInput::color_rect() const
|
|||
return { width() - color_box_size - color_box_padding, color_box_padding, color_box_size, color_box_size };
|
||||
}
|
||||
|
||||
void ColorInput::set_color_without_changing_text(Color color)
|
||||
void ColorInput::set_color_internal(Color color, AllowCallback allow_callback, bool change_text)
|
||||
{
|
||||
if (m_color == color)
|
||||
return;
|
||||
m_color = color;
|
||||
if (change_text)
|
||||
set_text(m_color_has_alpha_channel ? color.to_string() : color.to_string_without_alpha(), AllowCallback::No);
|
||||
update();
|
||||
if (on_change)
|
||||
if (allow_callback == AllowCallback::Yes && on_change)
|
||||
on_change();
|
||||
}
|
||||
|
||||
void ColorInput::set_color(Color color)
|
||||
void ColorInput::set_color(Color color, AllowCallback allow_callback)
|
||||
{
|
||||
if (m_color == color)
|
||||
return;
|
||||
set_text(m_color_has_alpha_channel ? color.to_string() : color.to_string_without_alpha());
|
||||
set_color_internal(color, allow_callback, true);
|
||||
};
|
||||
|
||||
void ColorInput::mousedown_event(MouseEvent& event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue