diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index ff52236c0bf..9b4d77b84de 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2158,6 +2158,11 @@ Control::FocusBehaviorRecursive Control::get_focus_behavior_recursive() const { return data.focus_behavior_recursive; } +bool Control::_is_focusable() const { + bool ac_enabled = is_inside_tree() && get_tree()->is_accessibility_enabled(); + return (is_visible_in_tree() && ((get_focus_mode_with_override() == FOCUS_ALL) || (get_focus_mode_with_override() == FOCUS_CLICK) || (ac_enabled && get_focus_mode_with_override() == FOCUS_ACCESSIBILITY))); +} + bool Control::_is_focus_mode_enabled() const { if (data.focus_behavior_recursive == FOCUS_BEHAVIOR_INHERITED) { if (data.parent_control) { @@ -2270,7 +2275,7 @@ Control *Control::find_next_valid_focus() const { ERR_FAIL_NULL_V_MSG(n, nullptr, "Next focus node path is invalid: '" + data.focus_next + "'."); Control *c = Object::cast_to(n); ERR_FAIL_NULL_V_MSG(c, nullptr, "Next focus node is not a control: '" + n->get_name() + "'."); - if (c->is_visible_in_tree() && c->get_focus_mode_with_override() != FOCUS_NONE) { + if (c->_is_focusable()) { return c; } } @@ -2374,7 +2379,7 @@ Control *Control::find_prev_valid_focus() const { ERR_FAIL_NULL_V_MSG(n, nullptr, "Previous focus node path is invalid: '" + data.focus_prev + "'."); Control *c = Object::cast_to(n); ERR_FAIL_NULL_V_MSG(c, nullptr, "Previous focus node is not a control: '" + n->get_name() + "'."); - if (c->is_visible_in_tree() && c->get_focus_mode_with_override() != FOCUS_NONE) { + if (c->_is_focusable()) { return c; } } @@ -2494,7 +2499,7 @@ Control *Control::_get_focus_neighbor(Side p_side, int p_count) { ERR_FAIL_NULL_V_MSG(n, nullptr, "Neighbor focus node path is invalid: '" + data.focus_neighbor[p_side] + "'."); Control *c = Object::cast_to(n); ERR_FAIL_NULL_V_MSG(c, nullptr, "Neighbor focus node is not a control: '" + n->get_name() + "'."); - if (c->is_visible_in_tree() && c->get_focus_mode_with_override() != FOCUS_NONE) { + if (c->_is_focusable()) { return c; } diff --git a/scene/gui/control.h b/scene/gui/control.h index d27c7b6e9ce..ebd3d7a750d 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -337,6 +337,7 @@ private: // Focus. + bool _is_focusable() const; void _window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Rect2 &p_rect, const Rect2 &p_clamp, real_t p_min, real_t &r_closest_dist_squared, Control **r_closest); Control *_get_focus_neighbor(Side p_side, int p_count = 0); bool _is_focus_mode_enabled() const; diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index e14556cf50c..13bd4277130 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -2263,6 +2263,10 @@ void GraphEdit::gui_input(const Ref &p_ev) { } } + key_input(p_ev); +} + +void GraphEdit::key_input(const Ref &p_ev) { if (p_ev->is_pressed()) { if (p_ev->is_action("ui_graph_duplicate", true)) { emit_signal(SNAME("duplicate_nodes_request")); diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index cbc71997058..3b8289f0186 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -401,6 +401,8 @@ public: PackedStringArray get_configuration_warnings() const override; + void key_input(const Ref &p_ev); + // This method has to be public (for undo redo). // TODO: Find a better way to do this. void _update_graph_frame(GraphFrame *p_frame); diff --git a/scene/gui/graph_element.cpp b/scene/gui/graph_element.cpp index 7abefee974f..5986da60dca 100644 --- a/scene/gui/graph_element.cpp +++ b/scene/gui/graph_element.cpp @@ -173,6 +173,11 @@ void GraphElement::gui_input(const Ref &p_ev) { emit_signal(SNAME("resize_request"), resizing_from_size + diff); } + + GraphEdit *graph = Object::cast_to(get_parent()); + if (graph && has_focus()) { + graph->key_input(p_ev); + } } void GraphElement::set_resizable(bool p_enable) { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 658572a248c..b9100503ed0 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1933,7 +1933,7 @@ void Viewport::_gui_input_event(Ref p_event) { while (ci) { Control *control = Object::cast_to(ci); if (control) { - if (control->get_focus_mode_with_override() != Control::FOCUS_NONE) { + if (control->_is_focusable()) { // 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)) {