| 27 | } |
| 28 | |
| 29 | wf::Size UniformGrid::MeasureOverride(const wf::Size &availableSize) |
| 30 | { |
| 31 | const auto visible = Children() |
| 32 | | std::views::transform([](const wux::UIElement& element) noexcept { return element.try_as<wux::FrameworkElement>(); }) |
| 33 | | std::views::filter([](const wux::FrameworkElement& element) { return element && element.Visibility() != wux::Visibility::Collapsed; }) |
| 34 | | std::ranges::to<std::vector>(); |
| 35 | |
| 36 | const auto [rows, columns] = GetDimensions(visible, Rows(), Columns(), FirstColumn()); |
| 37 | |
| 38 | // Now that we know size, setup automatic rows/columns |
| 39 | // to utilize Grid for UniformGrid behavior. |
| 40 | // We also interleave any specified rows/columns with fixed sizes. |
| 41 | SetupRowDefinitions(static_cast<uint32_t>(rows)); |
| 42 | SetupColumnDefinitions(static_cast<uint32_t>(columns)); |
| 43 | |
| 44 | m_TakenSpots.clear(); |
| 45 | m_TakenSpots.resize(rows * columns, false); |
| 46 | m_SpotsHeight = rows; |
| 47 | m_SpotsWidth = columns; |
| 48 | |
| 49 | // Figure out which children we should automatically layout and where available openings are. |
| 50 | for (const auto &child : visible) |
| 51 | { |
| 52 | const auto autoLayout = GetAutoLayout(child); |
| 53 | if (!autoLayout) |
| 54 | { |
| 55 | // If an element needs to be forced in the 0, 0 position, |
| 56 | // they should manually set UniformGrid.AutoLayout to False for that element. |
| 57 | const auto row = composable_base::GetRow(child); |
| 58 | const auto col = composable_base::GetColumn(child); |
| 59 | |
| 60 | if (row == 0 && col == 0) |
| 61 | { |
| 62 | SetAutoLayout(child, true); |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | SetAutoLayout(child, false); |
| 67 | FillSpots(true, row, col, composable_base::GetColumnSpan(child), composable_base::GetRowSpan(child)); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Setup available size with our known dimensions now. |
| 73 | // UniformGrid expands size based on largest singular item. |
| 74 | const float columnSpacingSize = static_cast<float>(ColumnSpacing()) * (columns - 1); |
| 75 | const float rowSpacingSize = static_cast<float>(RowSpacing()) * (rows - 1); |
| 76 | |
| 77 | const wf::Size childSize = { |
| 78 | (availableSize.Width - columnSpacingSize) / columns, |
| 79 | (availableSize.Height - rowSpacingSize) / rows |
| 80 | }; |
| 81 | |
| 82 | float maxWidth = 0.0; |
| 83 | float maxHeight = 0.0; |
| 84 | |
| 85 | // Set Grid Row/Col for every child with autolayout = true |
| 86 | // Backwards with FlowDirection |