Merge pull request #70262 from Maran23/3-x-editor-inspector-section-click

[3.x] EditorInspectorSection is not (un)folded when clicking under the font
This commit is contained in:
Rémi Verschelde 2022-12-22 08:56:37 +01:00
commit b59b566325
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 32 additions and 35 deletions

View file

@ -1020,12 +1020,8 @@ void EditorInspectorSection::_test_unfold() {
}
}
void EditorInspectorSection::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_SORT_CHILDREN: {
Ref<Font> font = get_font("font", "Tree");
Ref<Texture> EditorInspectorSection::_get_arrow() {
Ref<Texture> arrow;
if (foldable) {
if (object->editor_is_section_unfolded(section)) {
arrow = get_icon("arrow", "Tree");
@ -1033,15 +1029,29 @@ void EditorInspectorSection::_notification(int p_what) {
arrow = get_icon("arrow_collapsed", "Tree");
}
}
return arrow;
}
int EditorInspectorSection::_get_header_height() {
Ref<Font> font = get_font("font", "Tree");
int header_height = font->get_height();
Ref<Texture> 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: {
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<Texture> arrow;
if (foldable) {
if (object->editor_is_section_unfolded(section)) {
arrow = get_icon("arrow", "Tree");
} else {
arrow = get_icon("arrow_collapsed", "Tree");
}
}
Ref<Font> 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> 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<Texture> 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<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
Ref<Font> font = get_font("font", "Tree");
if (mb->get_position().y > font->get_height()) { //clicked outside
if (mb->get_position().y >= _get_header_height()) {
return;
}

View file

@ -237,6 +237,8 @@ class EditorInspectorSection : public Container {
bool foldable;
void _test_unfold();
int _get_header_height();
Ref<Texture> _get_arrow();
protected:
void _notification(int p_what);