MCPcopy Create free account
hub / github.com/TankOs/SFGUI / AllocateChildren

Method AllocateChildren

src/SFGUI/Table.cpp:124–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124void Table::AllocateChildren() {
125 auto gap = Context::Get().GetEngine().GetProperty<float>(
126 "Gap",
127 shared_from_this()
128 );
129
130 // Calculate column allocations.
131 auto total_width = GetAllocation().size.x - 2 * gap;
132 std::size_t num_expand = 0;
133
134 // First step is counting number of expandable columns and setting allocation
135 // to requisition.
136 for( auto& column : m_columns ) {
137 if( column.expand ) {
138 ++num_expand;
139 }
140
141 column.allocation = column.requisition;
142 total_width -= column.allocation;
143 }
144
145 // Next step is distribution of remaining width (i.e. extra width given by
146 // parent) to expandable columns. Also calculate column positions.
147 auto extra_width = (num_expand > 0 ? total_width / static_cast<float>( num_expand ) : 0 );
148
149 for( std::size_t col_idx = 0; col_idx < m_columns.size(); ++col_idx ) {
150 auto& col = m_columns[col_idx];
151
152 if( col.expand ) {
153 col.allocation += extra_width;
154 }
155
156 if( col_idx == 0 ) {
157 col.position = 0;
158 }
159 else {
160 col.position = m_columns[col_idx - 1].position + m_columns[col_idx - 1].allocation;
161 }
162 }
163
164 // Calculate row allocations.
165 auto total_height = 2 * gap + GetAllocation().size.y;
166 num_expand = 0;
167
168 // First step is counting number of expandable rows and setting allocation
169 // to requisition.
170 for( auto& row : m_rows ) {
171 if( row.expand ) {
172 ++num_expand;
173 }
174
175 row.allocation = row.requisition;
176 total_height -= row.allocation;
177 }
178
179 // Next step is distribution of remaining height (i.e. extra height given by
180 // parent) to expandable rows. Also calculate rows positions.
181 auto extra_height = (num_expand > 0 ? total_height / static_cast<float>( num_expand ) : 0 );

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.80
SetAllocationMethod · 0.80

Tested by

no test coverage detected