MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _notification

Method _notification

scene/gui/grid_container.cpp:44–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42#include "scene/theme/theme_db.h"
43
44void GridContainer::_notification(int p_what) {
45 switch (p_what) {
46 case NOTIFICATION_SORT_CHILDREN: {
47 RBMap<int, int> col_minw; // Max of min_width of all controls in each col (indexed by col).
48 RBMap<int, int> row_minh; // Max of min_height of all controls in each row (indexed by row).
49 RBSet<int> col_expanded; // Columns which have the SIZE_EXPAND flag set.
50 RBSet<int> row_expanded; // Rows which have the SIZE_EXPAND flag set.
51
52 // Compute the per-column/per-row data.
53 int valid_controls_index = 0;
54 for (int i = 0; i < get_child_count(); i++) {
55 Control *c = as_sortable_control(get_child(i));
56 if (!c) {
57 continue;
58 }
59
60 int row = valid_controls_index / columns;
61 int col = valid_controls_index % columns;
62 valid_controls_index++;
63
64 Size2i ms = c->get_combined_minimum_size();
65 if (col_minw.has(col)) {
66 col_minw[col] = MAX(col_minw[col], ms.width);
67 } else {
68 col_minw[col] = ms.width;
69 }
70 if (row_minh.has(row)) {
71 row_minh[row] = MAX(row_minh[row], ms.height);
72 } else {
73 row_minh[row] = ms.height;
74 }
75
76 if (c->get_h_size_flags().has_flag(SIZE_EXPAND)) {
77 col_expanded.insert(col);
78 }
79 if (c->get_v_size_flags().has_flag(SIZE_EXPAND)) {
80 row_expanded.insert(row);
81 }
82 }
83
84 int max_col = MIN(valid_controls_index, columns);
85 int max_row = std::ceil((float)valid_controls_index / (float)columns);
86
87 // Consider all empty columns expanded.
88 for (int i = valid_controls_index; i < columns; i++) {
89 col_expanded.insert(i);
90 }
91
92 // Evaluate the remaining space for expanded columns/rows.
93 Size2 remaining_space = get_size();
94 for (const KeyValue<int, int> &E : col_minw) {
95 if (!col_expanded.has(E.key)) {
96 remaining_space.width -= E.value;
97 }
98 }
99
100 for (const KeyValue<int, int> &E : row_minh) {
101 if (!row_expanded.has(E.key)) {

Callers

nothing calls this directly

Calls 15

MAXFunction · 0.85
MINFunction · 0.85
ceilFunction · 0.85
get_sizeFunction · 0.85
get_h_size_flagsMethod · 0.80
get_v_size_flagsMethod · 0.80
sizeMethod · 0.65
Rect2Class · 0.50
hasMethod · 0.45
has_flagMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected