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:
commit
b59b566325
2 changed files with 32 additions and 35 deletions
|
@ -1020,12 +1020,8 @@ void EditorInspectorSection::_test_unfold() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorInspectorSection::_notification(int p_what) {
|
Ref<Texture> EditorInspectorSection::_get_arrow() {
|
||||||
switch (p_what) {
|
|
||||||
case NOTIFICATION_SORT_CHILDREN: {
|
|
||||||
Ref<Font> font = get_font("font", "Tree");
|
|
||||||
Ref<Texture> arrow;
|
Ref<Texture> arrow;
|
||||||
|
|
||||||
if (foldable) {
|
if (foldable) {
|
||||||
if (object->editor_is_section_unfolded(section)) {
|
if (object->editor_is_section_unfolded(section)) {
|
||||||
arrow = get_icon("arrow", "Tree");
|
arrow = get_icon("arrow", "Tree");
|
||||||
|
@ -1033,15 +1029,29 @@ void EditorInspectorSection::_notification(int p_what) {
|
||||||
arrow = get_icon("arrow_collapsed", "Tree");
|
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();
|
Size2 size = get_size();
|
||||||
Point2 offset;
|
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");
|
offset.x += get_constant("inspector_margin", "Editor");
|
||||||
|
|
||||||
Rect2 rect(offset, size - offset);
|
Rect2 rect(offset, size - offset);
|
||||||
|
@ -1066,23 +1076,7 @@ void EditorInspectorSection::_notification(int p_what) {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_DRAW: {
|
case NOTIFICATION_DRAW: {
|
||||||
Ref<Texture> arrow;
|
int h = _get_header_height();
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
Rect2 header_rect = Rect2(Vector2(), Vector2(get_size().width, h));
|
Rect2 header_rect = Rect2(Vector2(), Vector2(get_size().width, h));
|
||||||
Color c = bg_color;
|
Color c = bg_color;
|
||||||
|
@ -1094,8 +1088,10 @@ void EditorInspectorSection::_notification(int p_what) {
|
||||||
|
|
||||||
const int arrow_margin = 3;
|
const int arrow_margin = 3;
|
||||||
Color color = get_color("font_color", "Tree");
|
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);
|
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()) {
|
if (arrow.is_valid()) {
|
||||||
draw_texture(arrow, Point2(Math::round(arrow_margin * EDSCALE), (h - arrow->get_height()) / 2).floor());
|
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;
|
Ref<InputEventMouseButton> mb = p_event;
|
||||||
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
|
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 >= _get_header_height()) {
|
||||||
if (mb->get_position().y > font->get_height()) { //clicked outside
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -237,6 +237,8 @@ class EditorInspectorSection : public Container {
|
||||||
bool foldable;
|
bool foldable;
|
||||||
|
|
||||||
void _test_unfold();
|
void _test_unfold();
|
||||||
|
int _get_header_height();
|
||||||
|
Ref<Texture> _get_arrow();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
|
Loading…
Reference in a new issue