From a375e77b85700f8da8547f9580296e17b376ae3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Wed, 26 Feb 2025 16:25:50 +0800 Subject: [PATCH 1/3] Revert "Fix inspector follow focus when child is focused" This reverts commit 286d3ae41595f7bcfc7d0812e861d56215560abd. --- editor/editor_inspector.cpp | 21 +++++++++------------ editor/editor_inspector.h | 1 - scene/gui/scroll_container.h | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 58b02ed2b8a1..2a4ca11e650e 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -4528,14 +4528,6 @@ void EditorInspector::_node_removed(Node *p_node) { } } -void EditorInspector::_gui_focus_changed(Control *p_control) { - if (!is_visible_in_tree() && !is_following_focus()) { - return; - } - // Don't follow focus when the inspector nor any of its children is focused. Prevents potential jumping when gaining focus. - set_follow_focus(has_focus() || child_has_focus()); -} - void EditorInspector::_update_current_favorites() { current_favorites.clear(); if (!can_favorite) { @@ -4733,10 +4725,6 @@ void EditorInspector::_notification(int p_what) { if (!is_sub_inspector()) { get_tree()->connect("node_removed", callable_mp(this, &EditorInspector::_node_removed)); } - - Viewport *viewport = get_viewport(); - ERR_FAIL_NULL(viewport); - viewport->connect("gui_focus_changed", callable_mp(this, &EditorInspector::_gui_focus_changed)); } break; case NOTIFICATION_PREDELETE: { @@ -4819,6 +4807,15 @@ void EditorInspector::_notification(int p_what) { update_tree(); } } break; + + case NOTIFICATION_FOCUS_ENTER: { + set_follow_focus(true); + } break; + + case NOTIFICATION_FOCUS_EXIT: { + // Don't follow focus when the inspector is not focused. Prevents potential jumping when gaining focus. + set_follow_focus(false); + } break; } } diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 9baf65444f27..ee82806003b2 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -606,7 +606,6 @@ class EditorInspector : public ScrollContainer { void _clear_current_favorites(); void _node_removed(Node *p_node); - void _gui_focus_changed(Control *p_control); HashMap per_array_page; void _page_change_request(int p_new_page, const StringName &p_array_prefix); diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h index 408f70157dfe..ea6309f57e80 100644 --- a/scene/gui/scroll_container.h +++ b/scene/gui/scroll_container.h @@ -82,6 +82,7 @@ class ScrollContainer : public Container { bool draw_focus_border = false; bool focus_border_is_drawn = false; + bool child_has_focus(); protected: Size2 get_minimum_size() const override; @@ -98,7 +99,6 @@ class ScrollContainer : public Container { public: virtual void gui_input(const Ref &p_gui_input) override; - bool child_has_focus(); void set_h_scroll(int p_pos); int get_h_scroll() const; From d0437d5052092aca46e511e6a26042634326b113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Wed, 26 Feb 2025 16:26:03 +0800 Subject: [PATCH 2/3] Revert "Fix inspector jumping when gaining focus" This reverts commit 922642440132bf7b070a16240c3a21d119584403. --- doc/classes/EditorInspector.xml | 1 + editor/editor_inspector.cpp | 15 +++------------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/doc/classes/EditorInspector.xml b/doc/classes/EditorInspector.xml index 644cbe5b5817..0bbd55f00757 100644 --- a/doc/classes/EditorInspector.xml +++ b/doc/classes/EditorInspector.xml @@ -51,6 +51,7 @@ + diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 2a4ca11e650e..824e288a43eb 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -3046,7 +3046,6 @@ void EditorInspector::update_tree() { int current_focusable = -1; // Temporarily disable focus following on the root inspector to avoid jumping while the inspector is updating. - bool was_following = get_root_inspector()->is_following_focus(); get_root_inspector()->set_follow_focus(false); if (property_focusable != -1) { @@ -3075,7 +3074,7 @@ void EditorInspector::update_tree() { _clear(!object); if (!object) { - get_root_inspector()->set_follow_focus(was_following); + get_root_inspector()->set_follow_focus(true); return; } @@ -3954,7 +3953,7 @@ void EditorInspector::update_tree() { EditorNode::get_singleton()->hide_unused_editors(); } - get_root_inspector()->set_follow_focus(was_following); + get_root_inspector()->set_follow_focus(true); } void EditorInspector::update_property(const String &p_prop) { @@ -4807,15 +4806,6 @@ void EditorInspector::_notification(int p_what) { update_tree(); } } break; - - case NOTIFICATION_FOCUS_ENTER: { - set_follow_focus(true); - } break; - - case NOTIFICATION_FOCUS_EXIT: { - // Don't follow focus when the inspector is not focused. Prevents potential jumping when gaining focus. - set_follow_focus(false); - } break; } } @@ -4972,6 +4962,7 @@ EditorInspector::EditorInspector() { base_vbox->add_child(main_vbox); set_horizontal_scroll_mode(SCROLL_MODE_DISABLED); + set_follow_focus(true); changing = 0; search_box = nullptr; From 62aa4a6f9ebc47a95fdf3b987e253f2eff874a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Wed, 26 Feb 2025 17:46:40 +0800 Subject: [PATCH 3/3] Make `EditorProperty` and its child EditorProperties behave more like sibling nodes Let `EditorProperty::gui_input()` no longer handle mouse events that occur in the child EditorProperty rect. --- editor/editor_inspector.cpp | 5 +++-- editor/editor_properties.cpp | 2 +- editor/editor_properties_array_dict.cpp | 2 -- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 824e288a43eb..5818c863538b 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -918,6 +918,9 @@ void EditorProperty::gui_input(const Ref &p_event) { if (me.is_valid()) { Vector2 mpos = me->get_position(); + if (bottom_child_rect.has_point(mpos)) { + return; // Makes child EditorProperties behave like sibling nodes when handling mouse events. + } if (is_layout_rtl()) { mpos.x = get_size().x - mpos.x; } @@ -2715,8 +2718,6 @@ VBoxContainer *EditorInspectorArray::get_vbox(int p_index) { EditorInspectorArray::EditorInspectorArray(bool p_read_only) { read_only = p_read_only; - set_mouse_filter(Control::MOUSE_FILTER_STOP); - odd_style.instantiate(); even_style.instantiate(); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 52780d7c5889..935915a0c080 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -3303,11 +3303,11 @@ void EditorPropertyResource::update_property() { sub_inspector->set_use_folding(is_using_folding()); sub_inspector->set_draw_focus_border(false); + sub_inspector->set_focus_mode(FocusMode::FOCUS_NONE); sub_inspector->set_use_filter(use_filter); sub_inspector->register_text_enter(parent_inspector->search_box); - sub_inspector->set_mouse_filter(MOUSE_FILTER_STOP); add_child(sub_inspector); set_bottom_editor(sub_inspector); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 93c5a70cf907..066c0d7d9e32 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -430,7 +430,6 @@ void EditorPropertyArray::update_property() { if (!container) { container = memnew(PanelContainer); - container->set_mouse_filter(MOUSE_FILTER_STOP); add_child(container); set_bottom_editor(container); @@ -1208,7 +1207,6 @@ void EditorPropertyDictionary::update_property() { if (!container) { container = memnew(PanelContainer); - container->set_mouse_filter(MOUSE_FILTER_STOP); add_child(container); set_bottom_editor(container);