Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EditorProperty and its child EditorProperty behave like sibling nodes when handling mouse events #103316

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/classes/EditorInspector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<members>
<member name="draw_focus_border" type="bool" setter="set_draw_focus_border" getter="get_draw_focus_border" overrides="ScrollContainer" default="true" />
<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" overrides="Control" enum="Control.FocusMode" default="2" />
<member name="follow_focus" type="bool" setter="set_follow_focus" getter="is_following_focus" overrides="ScrollContainer" default="true" />
<member name="horizontal_scroll_mode" type="int" setter="set_horizontal_scroll_mode" getter="get_horizontal_scroll_mode" overrides="ScrollContainer" enum="ScrollContainer.ScrollMode" default="0" />
</members>
<signals>
Expand Down
23 changes: 6 additions & 17 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,9 @@ void EditorProperty::gui_input(const Ref<InputEvent> &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;
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -3046,7 +3047,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) {
Expand Down Expand Up @@ -3075,7 +3075,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;
}

Expand Down Expand Up @@ -3954,7 +3954,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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -4975,6 +4963,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;
Expand Down
1 change: 0 additions & 1 deletion editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<StringName, int> per_array_page;
void _page_change_request(int p_new_page, const StringName &p_array_prefix);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions editor/editor_properties_array_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion scene/gui/scroll_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -98,7 +99,6 @@ class ScrollContainer : public Container {

public:
virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
bool child_has_focus();

void set_h_scroll(int p_pos);
int get_h_scroll() const;
Expand Down