diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 4d2985981c6..23d8681ea25 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1020,28 +1020,38 @@ void EditorInspectorSection::_test_unfold() { } } +Ref EditorInspectorSection::_get_arrow() { + Ref arrow; + if (foldable) { + if (object->editor_is_section_unfolded(section)) { + arrow = get_icon("arrow", "Tree"); + } else { + arrow = get_icon("arrow_collapsed", "Tree"); + } + } + return arrow; +} + +int EditorInspectorSection::_get_header_height() { + Ref font = get_font("font", "Tree"); + + int header_height = font->get_height(); + Ref arrow = _get_arrow(); + if (arrow.is_valid()) { + header_height = MAX(header_height, arrow->get_height()); + } + header_height += get_constant("vseparation", "Tree"); + + return header_height; +} + void EditorInspectorSection::_notification(int p_what) { switch (p_what) { case NOTIFICATION_SORT_CHILDREN: { - Ref font = get_font("font", "Tree"); - Ref arrow; - - if (foldable) { - if (object->editor_is_section_unfolded(section)) { - arrow = get_icon("arrow", "Tree"); - } else { - arrow = get_icon("arrow_collapsed", "Tree"); - } - } - Size2 size = get_size(); Point2 offset; - offset.y = font->get_height(); - if (arrow.is_valid()) { - offset.y = MAX(offset.y, arrow->get_height()); - } - offset.y += get_constant("vseparation", "Tree"); + offset.y = _get_header_height(); offset.x += get_constant("inspector_margin", "Editor"); Rect2 rect(offset, size - offset); @@ -1066,23 +1076,7 @@ void EditorInspectorSection::_notification(int p_what) { } break; case NOTIFICATION_DRAW: { - Ref arrow; - - if (foldable) { - if (object->editor_is_section_unfolded(section)) { - arrow = get_icon("arrow", "Tree"); - } else { - arrow = get_icon("arrow_collapsed", "Tree"); - } - } - - Ref font = get_font("font", "Tree"); - - int h = font->get_height(); - if (arrow.is_valid()) { - h = MAX(h, arrow->get_height()); - } - h += get_constant("vseparation", "Tree"); + int h = _get_header_height(); Rect2 header_rect = Rect2(Vector2(), Vector2(get_size().width, h)); Color c = bg_color; @@ -1094,8 +1088,10 @@ void EditorInspectorSection::_notification(int p_what) { const int arrow_margin = 3; Color color = get_color("font_color", "Tree"); + Ref font = get_font("font", "Tree"); draw_string(font, Point2(Math::round((16 + arrow_margin) * EDSCALE), font->get_ascent() + (h - font->get_height()) / 2).floor(), label, color, get_size().width); + Ref arrow = _get_arrow(); if (arrow.is_valid()) { draw_texture(arrow, Point2(Math::round(arrow_margin * EDSCALE), (h - arrow->get_height()) / 2).floor()); } @@ -1161,8 +1157,7 @@ void EditorInspectorSection::_gui_input(const Ref &p_event) { Ref mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - Ref font = get_font("font", "Tree"); - if (mb->get_position().y > font->get_height()) { //clicked outside + if (mb->get_position().y >= _get_header_height()) { return; } diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index dd16ac941a8..c22f4f395bb 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -237,6 +237,8 @@ class EditorInspectorSection : public Container { bool foldable; void _test_unfold(); + int _get_header_height(); + Ref _get_arrow(); protected: void _notification(int p_what);