Improve button behavior when multiple mouse buttons are used at the same time

- To emit `pressed`, buttons require that the press was initiated while hovering.
- Controls can't grab focus from a mouse click if they're not hovered.
- Hovers are updated both before and after a handled mouse button event.
This commit is contained in:
Anni Ryynänen
2024-06-23 07:30:40 +03:00
parent 04bf7d4cad
commit 2033510a65
2 changed files with 6 additions and 8 deletions

View File

@ -1768,7 +1768,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Control *control = Object::cast_to<Control>(ci);
if (control) {
if (control->get_focus_mode() != Control::FOCUS_NONE) {
if (control != gui.key_focus) {
// Grabbing unhovered focus can cause issues when mouse is dragged
// with another button held down.
if (control != gui.key_focus && gui.mouse_over_hierarchy.has(control)) {
control->grab_focus();
}
break;