Skip to content

Commit 2ef3ebf

Browse files
committed
Fix ColorPickerButton close popup on mouse click
Fixes godotengine#91813
1 parent 8b4b93a commit 2ef3ebf

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

scene/gui/color_picker.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,14 @@ void ColorPickerButton::_modal_closed() {
24462446
void ColorPickerButton::pressed() {
24472447
_update_picker();
24482448

2449+
// Checking if the popup was open before, so we can keep it closed instead of reopening it.
2450+
// Popups get closed when it's clicked outside of them.
2451+
if (popup_was_open) {
2452+
// Reset popup_was_open value.
2453+
popup_was_open = popup->is_visible();
2454+
return;
2455+
}
2456+
24492457
Size2 minsize = popup->get_contents_minimum_size();
24502458
float viewport_height = get_viewport_rect().size.y;
24512459

@@ -2471,6 +2479,19 @@ void ColorPickerButton::pressed() {
24712479
}
24722480
}
24732481

2482+
void ColorPickerButton::gui_input(const Ref<InputEvent> &p_event) {
2483+
ERR_FAIL_COND(p_event.is_null());
2484+
2485+
Ref<InputEventMouseButton> mouse_button = p_event;
2486+
bool ui_accept = p_event->is_action("ui_accept", true) && !p_event->is_echo();
2487+
bool mouse_left_pressed = mouse_button.is_valid() && mouse_button->get_button_index() == MouseButton::LEFT && mouse_button->is_pressed();
2488+
if (mouse_left_pressed || ui_accept) {
2489+
popup_was_open = popup && popup->is_visible();
2490+
}
2491+
2492+
BaseButton::gui_input(p_event);
2493+
}
2494+
24742495
void ColorPickerButton::_notification(int p_what) {
24752496
switch (p_what) {
24762497
case NOTIFICATION_ACCESSIBILITY_UPDATE: {

scene/gui/color_picker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ class ColorPickerButton : public Button {
521521
Color color;
522522
bool edit_alpha = true;
523523
bool edit_intensity = true;
524+
bool popup_was_open = false;
524525

525526
struct ThemeCache {
526527
Ref<StyleBox> normal_style;
@@ -540,6 +541,7 @@ class ColorPickerButton : public Button {
540541
protected:
541542
void _notification(int);
542543
static void _bind_methods();
544+
virtual void gui_input(const Ref<InputEvent> &p_event) override;
543545

544546
public:
545547
void set_pick_color(const Color &p_color);

0 commit comments

Comments
 (0)