From 2fbc7509c3f386711a1e56e3796cb886da2aa04a Mon Sep 17 00:00:00 2001 From: WhalesState Date: Mon, 13 Jan 2025 04:34:25 +0200 Subject: [PATCH] Update FoldableContainer Fix shaping when font is null. Unify the panel content margin. Make allowed size flags empty. --- editor/themes/editor_theme_manager.cpp | 2 +- scene/gui/foldable_container.cpp | 39 ++++++++++---------------- scene/theme/default_theme.cpp | 3 +- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/editor/themes/editor_theme_manager.cpp b/editor/themes/editor_theme_manager.cpp index 514c074c3499..e2703b95ca4e 100644 --- a/editor/themes/editor_theme_manager.cpp +++ b/editor/themes/editor_theme_manager.cpp @@ -1269,7 +1269,7 @@ void EditorThemeManager::_populate_standard_styles(const Ref &p_the p_theme->set_stylebox("title_hover_panel", "FoldableContainer", foldable_container_hover); p_theme->set_stylebox("title_collapsed_panel", "FoldableContainer", make_flat_stylebox(p_config.dark_color_1.darkened(0.125), p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.base_margin)); p_theme->set_stylebox("title_collapsed_hover_panel", "FoldableContainer", make_flat_stylebox(p_config.dark_color_1.lerp(p_config.base_color, 0.4), p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.base_margin)); - Ref foldable_container_panel = make_flat_stylebox(p_config.dark_color_1, p_config.forced_even_separation, p_config.base_margin, p_config.base_margin, p_config.base_margin); + Ref foldable_container_panel = make_flat_stylebox(p_config.dark_color_1, p_config.base_margin, p_config.base_margin, p_config.base_margin, p_config.base_margin); foldable_container_panel->set_corner_radius(CORNER_TOP_LEFT, 0); foldable_container_panel->set_corner_radius(CORNER_TOP_RIGHT, 0); p_theme->set_stylebox(SceneStringName(panel), "FoldableContainer", foldable_container_panel); diff --git a/scene/gui/foldable_container.cpp b/scene/gui/foldable_container.cpp index f90ffe0d73d8..996d22c4cbe0 100644 --- a/scene/gui/foldable_container.cpp +++ b/scene/gui/foldable_container.cpp @@ -56,21 +56,11 @@ Size2 FoldableContainer::get_minimum_size() const { } Vector FoldableContainer::get_allowed_size_flags_horizontal() const { - Vector flags; - flags.append(SIZE_FILL); - flags.append(SIZE_SHRINK_BEGIN); - flags.append(SIZE_SHRINK_CENTER); - flags.append(SIZE_SHRINK_END); - return flags; + return Vector(); } Vector FoldableContainer::get_allowed_size_flags_vertical() const { - Vector flags; - flags.append(SIZE_FILL); - flags.append(SIZE_SHRINK_BEGIN); - flags.append(SIZE_SHRINK_CENTER); - flags.append(SIZE_SHRINK_END); - return flags; + return Vector(); } void FoldableContainer::set_expanded(bool p_expanded) { @@ -79,16 +69,9 @@ void FoldableContainer::set_expanded(bool p_expanded) { } expanded = p_expanded; - for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); - if (!c || c->is_set_as_top_level()) { - continue; - } - c->set_visible(expanded); - } update_minimum_size(); + queue_sort(); queue_redraw(); - emit_signal(SNAME("folding_changed"), !expanded); } bool FoldableContainer::is_expanded() const { @@ -401,6 +384,7 @@ void FoldableContainer::gui_input(const Ref &p_event) { if (has_focus() && p_event->is_action_pressed("ui_accept", false, true)) { set_expanded(!expanded); + emit_signal(SNAME("folding_changed"), !expanded); accept_event(); return; } @@ -416,6 +400,7 @@ void FoldableContainer::gui_input(const Ref &p_event) { _pressed = button_pos; if (_pressed == -1) { set_expanded(!expanded); + emit_signal(SNAME("folding_changed"), !expanded); } accept_event(); } else { @@ -578,13 +563,13 @@ void FoldableContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible_in_tree()) { + if (!c || c->is_set_as_top_level()) { continue; } - if (c->is_set_as_top_level()) { + c->set_visible(expanded); + if (!expanded || !c->is_visible_in_tree()) { continue; } - c->set_visible(expanded); fit_child_in_rect(c, Rect2(ofs, size)); } } break; @@ -660,6 +645,12 @@ Ref FoldableContainer::_get_title_icon() const { } void FoldableContainer::_shape() { + Ref font = theme_cache.title_font; + int font_size = theme_cache.title_font_size; + if (font.is_null() || font_size == 0) { + return; + } + text_buf->clear(); text_buf->set_width(-1); @@ -673,7 +664,7 @@ void FoldableContainer::_shape() { text_buf->set_text_overrun_behavior(overrun_behavior); - text_buf->add_string(atr(title), theme_cache.title_font, theme_cache.title_font_size, language); + text_buf->add_string(atr(title), font, font_size, language); } HorizontalAlignment FoldableContainer::_get_actual_alignment() const { diff --git a/scene/theme/default_theme.cpp b/scene/theme/default_theme.cpp index 57b723c0f540..9a9a490beacd 100644 --- a/scene/theme/default_theme.cpp +++ b/scene/theme/default_theme.cpp @@ -1217,7 +1217,8 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_stylebox("title_hover_panel", "FoldableContainer", foldable_container_hover); theme->set_stylebox("title_collapsed_panel", "FoldableContainer", make_flat_stylebox(style_pressed_color)); theme->set_stylebox("title_collapsed_hover_panel", "FoldableContainer", make_flat_stylebox(style_hover_color)); - Ref foldable_container_panel = make_flat_stylebox(style_normal_color, 18); + Ref foldable_container_panel = make_flat_stylebox(style_normal_color); + foldable_container_panel->set_content_margin_all(default_margin); foldable_container_panel->set_corner_radius(CORNER_TOP_LEFT, 0); foldable_container_panel->set_corner_radius(CORNER_TOP_RIGHT, 0); theme->set_stylebox(SceneStringName(panel), "FoldableContainer", foldable_container_panel);