Fixed undo/redo behaviour of color picker and added ability to cancel/confirm color selection.

This commit is contained in:
Zi Ye
2024-02-22 18:01:28 -06:00
parent 99ff024f78
commit d827b34ea8
5 changed files with 48 additions and 10 deletions

View File

@ -714,6 +714,10 @@ Color ColorPicker::get_pick_color() const {
return color;
}
Color ColorPicker::get_old_color() const {
return old_color;
}
void ColorPicker::set_picker_shape(PickerShapeType p_shape) {
ERR_FAIL_INDEX(p_shape, SHAPE_MAX);
if (p_shape == current_shape) {
@ -1514,7 +1518,7 @@ void ColorPicker::_pick_finished() {
return;
}
if (Input::get_singleton()->is_key_pressed(Key::ESCAPE)) {
if (Input::get_singleton()->is_action_just_pressed(SNAME("ui_cancel"))) {
set_pick_color(old_color);
} else {
emit_signal(SNAME("color_changed"), color);
@ -1627,7 +1631,12 @@ void ColorPicker::_html_focus_exit() {
if (c_text->is_menu_visible()) {
return;
}
_html_submitted(c_text->get_text());
if (is_visible_in_tree()) {
_html_submitted(c_text->get_text());
} else {
_update_text_value();
}
}
void ColorPicker::set_can_add_swatches(bool p_enabled) {
@ -2026,6 +2035,15 @@ ColorPicker::~ColorPicker() {
/////////////////
void ColorPickerPopupPanel::_input_from_window(const Ref<InputEvent> &p_event) {
if (p_event->is_action_pressed(SNAME("ui_accept"), false, true)) {
_close_pressed();
}
PopupPanel::_input_from_window(p_event);
}
/////////////////
void ColorPickerButton::_about_to_popup() {
set_pressed(true);
if (picker) {
@ -2040,6 +2058,10 @@ void ColorPickerButton::_color_changed(const Color &p_color) {
}
void ColorPickerButton::_modal_closed() {
if (Input::get_singleton()->is_action_just_pressed(SNAME("ui_cancel"))) {
set_pick_color(picker->get_old_color());
emit_signal(SNAME("color_changed"), color);
}
emit_signal(SNAME("popup_closed"));
set_pressed(false);
}
@ -2137,7 +2159,7 @@ PopupPanel *ColorPickerButton::get_popup() {
void ColorPickerButton::_update_picker() {
if (!picker) {
popup = memnew(PopupPanel);
popup = memnew(ColorPickerPopupPanel);
popup->set_wrap_controls(true);
picker = memnew(ColorPicker);
picker->set_anchors_and_offsets_preset(PRESET_FULL_RECT);