MCPcopy Create free account
hub / github.com/TranslucentTB/TranslucentTB / GetDimensions

Method GetDimensions

Xaml/Controls/UniformGrid.cpp:177–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175 }
176
177 std::tuple<int, int> UniformGrid::GetDimensions(const std::vector<wux::FrameworkElement> &visible, int rows, int cols, int firstColumn)
178 {
179 // If a dimension isn't specified, we need to figure out the other one (or both).
180 if (rows == 0 || cols == 0)
181 {
182 // Calculate the size & area of all objects in the grid to know how much space we need.
183 const auto sizes = visible | std::views::transform([](const wux::FrameworkElement &item)
184 {
185 return composable_base::GetRowSpan(item) * composable_base::GetColumnSpan(item);
186 });
187
188 auto count = std::max(1, std::accumulate(sizes.begin(), sizes.end(), 0));
189
190 if (rows == 0)
191 {
192 if (cols > 0)
193 {
194 // Bound check
195 const auto first = (firstColumn >= cols || firstColumn < 0) ? 0 : firstColumn;
196
197 // If we have columns but no rows, calculate rows based on column offset and number of children.
198 rows = (count + first + (cols - 1)) / cols;
199 return { rows, cols };
200 }
201 else
202 {
203 // Otherwise, determine square layout if both are zero.
204 const auto size = static_cast<int>(std::ceil(std::sqrt(count)));
205
206 // Figure out if firstColumn is in bounds
207 const auto first = (firstColumn >= size || firstColumn < 0) ? 0 : firstColumn;
208
209 rows = static_cast<int>(std::ceil(std::sqrt(count + first)));
210 return { rows, rows };
211 }
212 }
213 else if (cols == 0)
214 {
215 // If we have rows and no columns, then calculate columns needed based on rows
216 cols = (count + (rows - 1)) / rows;
217
218 // Now that we know a rough size of our shape, see if the FirstColumn effects that:
219 const auto first = (firstColumn >= cols || firstColumn < 0) ? 0 : firstColumn;
220
221 cols = (count + first + (rows - 1)) / rows;
222 }
223 }
224
225 return { rows, cols };
226 }
227
228 void UniformGrid::SetupRowDefinitions(uint32_t rows)
229 {

Callers

nothing calls this directly

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected