1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-04 17:04:49 +00:00

Merge pull request #81532 from wlsnmrk/button-focus-loss-event-fix

Fix `button_up` and `button_down` signals with focus changes or multiple inputs
This commit is contained in:
Rémi Verschelde
2025-01-06 22:46:26 +01:00
2 changed files with 10 additions and 3 deletions

View File

@@ -114,6 +114,11 @@ void BaseButton::_notification(int p_what) {
} else if (status.hovering) { } else if (status.hovering) {
queue_redraw(); queue_redraw();
} }
if (status.pressed_down_with_focus) {
status.pressed_down_with_focus = false;
emit_signal(SNAME("button_up"));
}
} break; } break;
case NOTIFICATION_VISIBILITY_CHANGED: case NOTIFICATION_VISIBILITY_CHANGED:
@@ -146,9 +151,10 @@ void BaseButton::_toggled(bool p_pressed) {
void BaseButton::on_action_event(Ref<InputEvent> p_event) { void BaseButton::on_action_event(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> mouse_button = p_event; Ref<InputEventMouseButton> mouse_button = p_event;
if (p_event->is_pressed() && (mouse_button.is_null() || status.hovering)) { if (!status.pressed_down_with_focus && p_event->is_pressed() && (mouse_button.is_null() || status.hovering)) {
status.press_attempt = true; status.press_attempt = true;
status.pressing_inside = true; status.pressing_inside = true;
status.pressed_down_with_focus = true;
emit_signal(SNAME("button_down")); emit_signal(SNAME("button_down"));
} }
@@ -175,9 +181,10 @@ void BaseButton::on_action_event(Ref<InputEvent> p_event) {
} }
} }
if (!p_event->is_pressed()) { if (status.pressed_down_with_focus && !p_event->is_pressed()) {
status.press_attempt = false; status.press_attempt = false;
status.pressing_inside = false; status.pressing_inside = false;
status.pressed_down_with_focus = false;
emit_signal(SNAME("button_up")); emit_signal(SNAME("button_up"));
} }

View File

@@ -61,7 +61,7 @@ private:
bool hovering = false; bool hovering = false;
bool press_attempt = false; bool press_attempt = false;
bool pressing_inside = false; bool pressing_inside = false;
bool pressed_down_with_focus = false;
bool disabled = false; bool disabled = false;
} status; } status;