mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:17:35 +00:00
LibGUI: Make GUI::ColorPicker
interactive
There is now a `on_color_changed` callback that clients can optionally hook into to receive real-time updates while the user is picking a color. If the user hits Cancel, the callback gets called once more with the color passed in while constructing `ColorPicker`. If the user hits OK, the same happens with the currently selected color instead. Programs therefore can perform all their updates with this callback, and only care about `ExecResult` if they want to make a decision, like if we should write the result to `ConfigServer`, for example.
This commit is contained in:
parent
ca1a98ba9f
commit
825c9eaeb1
3 changed files with 13 additions and 2 deletions
|
@ -185,6 +185,7 @@ private:
|
|||
|
||||
ColorPicker::ColorPicker(Color color, Window* parent_window, DeprecatedString title)
|
||||
: Dialog(parent_window)
|
||||
, m_original_color(color)
|
||||
, m_color(color)
|
||||
{
|
||||
set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/color-chooser.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
|
@ -230,6 +231,8 @@ void ColorPicker::build_ui()
|
|||
auto& ok_button = button_container.add<DialogButton>();
|
||||
ok_button.set_text("OK"_short_string);
|
||||
ok_button.on_click = [this](auto) {
|
||||
if (on_color_changed)
|
||||
on_color_changed(m_color);
|
||||
done(ExecResult::OK);
|
||||
};
|
||||
ok_button.set_default(true);
|
||||
|
@ -237,6 +240,8 @@ void ColorPicker::build_ui()
|
|||
auto& cancel_button = button_container.add<DialogButton>();
|
||||
cancel_button.set_text("Cancel"_short_string);
|
||||
cancel_button.on_click = [this](auto) {
|
||||
if (on_color_changed)
|
||||
on_color_changed(m_original_color);
|
||||
done(ExecResult::Cancel);
|
||||
};
|
||||
}
|
||||
|
@ -439,6 +444,8 @@ void ColorPicker::update_color_widgets()
|
|||
m_alpha_spinbox->set_enabled(m_color_has_alpha_channel);
|
||||
m_alpha->set_value(m_color.alpha());
|
||||
m_alpha->set_visible(m_color_has_alpha_channel);
|
||||
if (on_color_changed)
|
||||
on_color_changed(m_color);
|
||||
}
|
||||
|
||||
void ColorPicker::create_color_button(Widget& container, unsigned rgb)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue