Now ColorSelectorButton can work both in toggle mode, and in normal mode.

This commit is contained in:
Relintai 2022-11-17 23:04:16 +01:00
parent e53868f60f
commit 4b3c8aed30
2 changed files with 12 additions and 3 deletions

View File

@ -1246,8 +1246,7 @@ void ColorSelectorButton::_update_picker() {
picker->connect("color_changed", this, "_color_changed"); picker->connect("color_changed", this, "_color_changed");
popup->connect("modal_closed", this, "_modal_closed"); popup->connect("modal_closed", this, "_modal_closed");
popup->connect("about_to_show", this, "_about_to_show"); popup->connect("about_to_show", this, "_about_to_show");
popup->connect("popup_hide", this, "set_pressed", varray(false)); //popup->connect("popup_hide", this, "set_pressed", varray(false));
popup->connect("popup_hide", this, "set_toggle_mode", varray(false));
picker->set_pick_color(color); picker->set_pick_color(color);
picker->set_edit_alpha(edit_alpha); picker->set_edit_alpha(edit_alpha);
picker->set_display_old_color(true); picker->set_display_old_color(true);
@ -1259,10 +1258,18 @@ void ColorSelectorButton::pressed() {
if (_button == BUTTON_LEFT) { if (_button == BUTTON_LEFT) {
Button::pressed(); Button::pressed();
} else if (_button == BUTTON_RIGHT) { } else if (_button == BUTTON_RIGHT) {
set_toggle_mode(true);
popup_open_request(); popup_open_request();
} }
} }
void ColorSelectorButton::toggled(bool p_pressed) {
if (_button == BUTTON_LEFT) {
Button::toggled(p_pressed);
} else if (_button == BUTTON_RIGHT) {
if (p_pressed) {
popup_open_request();
}
}
}
void ColorSelectorButton::_gui_input(Ref<InputEvent> p_event) { void ColorSelectorButton::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> mouse_button = p_event; Ref<InputEventMouseButton> mouse_button = p_event;
@ -1302,4 +1309,5 @@ ColorSelectorButton::ColorSelectorButton() {
edit_alpha = true; edit_alpha = true;
set_button_mask(BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT); set_button_mask(BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT);
//set_toggle_mode(true);
} }

View File

@ -219,6 +219,7 @@ class ColorSelectorButton : public Button {
protected: protected:
void pressed(); void pressed();
void toggled(bool p_pressed);
void _gui_input(Ref<InputEvent> p_event); void _gui_input(Ref<InputEvent> p_event);
void _notification(int); void _notification(int);