Skip to content

Commit ebe83ac

Browse files
committed
Merge pull request godotengine#110871 from KoBeWi/fold_code
Reduce repetitive code in FoldableContainer
2 parents 618be07 + a5ece93 commit ebe83ac

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

scene/gui/foldable_container.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ void FoldableContainer::gui_input(const Ref<InputEvent> &p_event) {
219219

220220
Ref<InputEventMouseMotion> m = p_event;
221221
if (m.is_valid()) {
222-
Rect2 title_rect = Rect2(0, (title_position == POSITION_TOP) ? 0 : get_size().height - title_minimum_size.height, get_size().width, title_minimum_size.height);
223-
if (title_rect.has_point(m->get_position())) {
222+
if (_get_title_rect().has_point(m->get_position())) {
224223
if (!is_hovering) {
225224
is_hovering = true;
226225
queue_redraw();
@@ -241,8 +240,7 @@ void FoldableContainer::gui_input(const Ref<InputEvent> &p_event) {
241240

242241
Ref<InputEventMouseButton> b = p_event;
243242
if (b.is_valid()) {
244-
Rect2 title_rect = Rect2(0, (title_position == POSITION_TOP) ? 0 : get_size().height - title_minimum_size.height, get_size().width, title_minimum_size.height);
245-
if (b->get_button_index() == MouseButton::LEFT && b->is_pressed() && title_rect.has_point(b->get_position())) {
243+
if (b->get_button_index() == MouseButton::LEFT && b->is_pressed() && _get_title_rect().has_point(b->get_position())) {
246244
set_folded(!folded);
247245
emit_signal(SNAME("folding_changed"), folded);
248246
accept_event();
@@ -272,9 +270,7 @@ void FoldableContainer::_notification(int p_what) {
272270
title_controls_width += h_separation;
273271
}
274272

275-
Rect2 title_rect(
276-
Point2(0, (title_position == POSITION_TOP) ? 0 : size.height - title_minimum_size.height),
277-
Size2(size.width, title_minimum_size.height));
273+
const Rect2 title_rect = _get_title_rect();
278274
_draw_flippable_stylebox(title_style, title_rect);
279275

280276
Size2 title_ms = title_style->get_minimum_size();
@@ -431,6 +427,10 @@ Ref<Texture2D> FoldableContainer::_get_title_icon() const {
431427
return theme_cache.folded_arrow;
432428
}
433429

430+
Rect2 FoldableContainer::_get_title_rect() const {
431+
return Rect2(0, (title_position == POSITION_TOP) ? 0 : (get_size().height - title_minimum_size.height), get_size().width, title_minimum_size.height);
432+
}
433+
434434
void FoldableContainer::_update_title_min_size() const {
435435
Ref<StyleBox> title_style = folded ? theme_cache.title_collapsed_style : theme_cache.title_style;
436436
Ref<Texture2D> icon = _get_title_icon();

scene/gui/foldable_container.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class FoldableContainer : public Container {
8989

9090
Ref<StyleBox> _get_title_style() const;
9191
Ref<Texture2D> _get_title_icon() const;
92+
Rect2 _get_title_rect() const;
9293
int _get_h_separation() const { return MAX(theme_cache.h_separation, 0); }
9394
real_t _get_title_controls_width() const;
9495

0 commit comments

Comments
 (0)