Merge pull request #70261 from Maran23/4-x-editor-inspector-section-click

EditorInspectorSection is not (un)folded when clicking under the font
This commit is contained in:
Rémi Verschelde 2022-12-21 18:27:27 +01:00
commit 224d26fb49
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 50 additions and 59 deletions

View file

@ -1172,21 +1172,7 @@ void EditorInspectorSection::_test_unfold() {
}
}
void EditorInspectorSection::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;
case NOTIFICATION_SORT_CHILDREN: {
if (!vbox_added) {
return;
}
// Get the section header font.
Ref<Font> font = get_theme_font(SNAME("bold"), SNAME("EditorFonts"));
int font_size = get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts"));
// Get the right direction arrow texture, if the section is foldable.
Ref<Texture2D> EditorInspectorSection::_get_arrow() {
Ref<Texture2D> arrow;
if (foldable) {
if (object->editor_is_section_unfolded(section)) {
@ -1199,14 +1185,34 @@ void EditorInspectorSection::_notification(int p_what) {
}
}
}
return arrow;
}
int EditorInspectorSection::_get_header_height() {
Ref<Font> font = get_theme_font(SNAME("bold"), SNAME("EditorFonts"));
int font_size = get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts"));
// Compute the height of the section header.
int header_height = font->get_height(font_size);
Ref<Texture2D> arrow = _get_arrow();
if (arrow.is_valid()) {
header_height = MAX(header_height, arrow->get_height());
}
header_height += get_theme_constant(SNAME("v_separation"), SNAME("Tree"));
return header_height;
}
void EditorInspectorSection::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;
case NOTIFICATION_SORT_CHILDREN: {
if (!vbox_added) {
return;
}
int inspector_margin = get_theme_constant(SNAME("inspector_margin"), SNAME("Editor"));
int section_indent_size = get_theme_constant(SNAME("indent_size"), SNAME("EditorInspectorSection"));
if (indent_depth > 0 && section_indent_size > 0) {
@ -1218,6 +1224,7 @@ void EditorInspectorSection::_notification(int p_what) {
}
Size2 size = get_size() - Vector2(inspector_margin, 0);
int header_height = _get_header_height();
Vector2 offset = Vector2(is_layout_rtl() ? 0 : inspector_margin, header_height);
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
@ -1233,36 +1240,6 @@ void EditorInspectorSection::_notification(int p_what) {
} break;
case NOTIFICATION_DRAW: {
// Get the section header font.
Ref<Font> font = get_theme_font(SNAME("bold"), SNAME("EditorFonts"));
int font_size = get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts"));
Color font_color = get_theme_color(SNAME("font_color"), SNAME("Editor"));
// Get the right direction arrow texture, if the section is foldable.
Ref<Texture2D> arrow;
bool folded = foldable;
if (foldable) {
if (object->editor_is_section_unfolded(section)) {
arrow = get_theme_icon(SNAME("arrow"), SNAME("Tree"));
folded = false;
} else {
if (is_layout_rtl()) {
arrow = get_theme_icon(SNAME("arrow_collapsed_mirrored"), SNAME("Tree"));
} else {
arrow = get_theme_icon(SNAME("arrow_collapsed"), SNAME("Tree"));
}
}
}
bool rtl = is_layout_rtl();
// Compute the height and width of the section header.
int header_height = font->get_height(font_size);
if (arrow.is_valid()) {
header_height = MAX(header_height, arrow->get_height());
}
header_height += get_theme_constant(SNAME("v_separation"), SNAME("Tree"));
int section_indent = 0;
int section_indent_size = get_theme_constant(SNAME("indent_size"), SNAME("EditorInspectorSection"));
if (indent_depth > 0 && section_indent_size > 0) {
@ -1275,11 +1252,13 @@ void EditorInspectorSection::_notification(int p_what) {
int header_width = get_size().width - section_indent;
int header_offset_x = 0.0;
bool rtl = is_layout_rtl();
if (!rtl) {
header_offset_x += section_indent;
}
// Draw header area.
int header_height = _get_header_height();
Rect2 header_rect = Rect2(Vector2(header_offset_x, 0.0), Vector2(header_width, header_height));
Color c = bg_color;
c.a *= 0.4;
@ -1288,7 +1267,7 @@ void EditorInspectorSection::_notification(int p_what) {
}
draw_rect(header_rect, c);
// Draw header title, folding arrow and coutn of revertable properties.
// Draw header title, folding arrow and count of revertable properties.
{
int separation = Math::round(2 * EDSCALE);
@ -1296,6 +1275,7 @@ void EditorInspectorSection::_notification(int p_what) {
int margin_end = separation;
// - Arrow.
Ref<Texture2D> arrow = _get_arrow();
if (arrow.is_valid()) {
Point2 arrow_position;
if (rtl) {
@ -1313,6 +1293,13 @@ void EditorInspectorSection::_notification(int p_what) {
// - Count of revertable properties.
String num_revertable_str;
int num_revertable_width = 0;
bool folded = foldable && !object->editor_is_section_unfolded(section);
Ref<Font> font = get_theme_font(SNAME("bold"), SNAME("EditorFonts"));
int font_size = get_theme_font_size(SNAME("bold_size"), SNAME("EditorFonts"));
Color font_color = get_theme_color(SNAME("font_color"), SNAME("Editor"));
if (folded && revertable_properties.size()) {
int label_width = font->get_string_size(label, HORIZONTAL_ALIGNMENT_LEFT, available, font_size, TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS).x;
@ -1481,11 +1468,13 @@ 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() == MouseButton::LEFT) {
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Tree"));
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Tree"));
if (mb->get_position().y > font->get_height(font_size)) { //clicked outside
if (object->editor_is_section_unfolded(section)) {
int header_height = _get_header_height();
if (mb->get_position().y >= header_height) {
return;
}
}
accept_event();

View file

@ -280,6 +280,8 @@ class EditorInspectorSection : public Container {
HashSet<StringName> revertable_properties;
void _test_unfold();
int _get_header_height();
Ref<Texture2D> _get_arrow();
protected:
Object *object = nullptr;