1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +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:
Valtteri Koskivuori 2023-07-21 00:51:05 +03:00 committed by Ali Mohammad Pur
parent ca1a98ba9f
commit 825c9eaeb1
3 changed files with 13 additions and 2 deletions

View file

@ -71,9 +71,11 @@ void ColorInput::mouseup_event(MouseEvent& event)
m_may_be_color_rect_click = false;
if (is_color_rect_click) {
auto dialog = GUI::ColorPicker::construct(m_color, window(), m_color_picker_title);
dialog->on_color_changed = [this](Gfx::Color color) {
set_color(color);
};
dialog->set_color_has_alpha_channel(m_color_has_alpha_channel);
if (dialog->exec() == GUI::Dialog::ExecResult::OK)
set_color(dialog->color());
dialog->exec();
event.accept();
return;
}