Skip to content

Commit

Permalink
Update FoldableContainer
Browse files Browse the repository at this point in the history
Fix shaping when font is null.
Unify the panel content margin.
Make allowed size flags empty.
  • Loading branch information
WhalesState committed Jan 13, 2025
1 parent 00f571d commit 2fbc750
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion editor/themes/editor_theme_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ void EditorThemeManager::_populate_standard_styles(const Ref<EditorTheme> &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<StyleBoxFlat> 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<StyleBoxFlat> 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);
Expand Down
39 changes: 15 additions & 24 deletions scene/gui/foldable_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,11 @@ Size2 FoldableContainer::get_minimum_size() const {
}

Vector<int> FoldableContainer::get_allowed_size_flags_horizontal() const {
Vector<int> flags;
flags.append(SIZE_FILL);
flags.append(SIZE_SHRINK_BEGIN);
flags.append(SIZE_SHRINK_CENTER);
flags.append(SIZE_SHRINK_END);
return flags;
return Vector<int>();
}

Vector<int> FoldableContainer::get_allowed_size_flags_vertical() const {
Vector<int> flags;
flags.append(SIZE_FILL);
flags.append(SIZE_SHRINK_BEGIN);
flags.append(SIZE_SHRINK_CENTER);
flags.append(SIZE_SHRINK_END);
return flags;
return Vector<int>();
}

void FoldableContainer::set_expanded(bool p_expanded) {
Expand All @@ -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<Control>(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 {
Expand Down Expand Up @@ -401,6 +384,7 @@ void FoldableContainer::gui_input(const Ref<InputEvent> &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;
}
Expand All @@ -416,6 +400,7 @@ void FoldableContainer::gui_input(const Ref<InputEvent> &p_event) {
_pressed = button_pos;
if (_pressed == -1) {
set_expanded(!expanded);
emit_signal(SNAME("folding_changed"), !expanded);
}
accept_event();
} else {
Expand Down Expand Up @@ -578,13 +563,13 @@ void FoldableContainer::_notification(int p_what) {

for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(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;
Expand Down Expand Up @@ -660,6 +645,12 @@ Ref<Texture2D> FoldableContainer::_get_title_icon() const {
}

void FoldableContainer::_shape() {
Ref<Font> 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);

Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion scene/theme/default_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,8 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &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<StyleBoxFlat> foldable_container_panel = make_flat_stylebox(style_normal_color, 18);
Ref<StyleBoxFlat> 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);
Expand Down

0 comments on commit 2fbc750

Please sign in to comment.