From 7346aff9f6576c671f13d5808c0a2089defe6aa7 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 30 Jul 2024 13:03:41 +0300 Subject: [PATCH] Fix ui::impl::box_layout_base handling added elements --- libs/ui/source/impl/box_layout_base.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/ui/source/impl/box_layout_base.cpp b/libs/ui/source/impl/box_layout_base.cpp index 16d7d7bc..62fc218d 100644 --- a/libs/ui/source/impl/box_layout_base.cpp +++ b/libs/ui/source/impl/box_layout_base.cpp @@ -14,14 +14,11 @@ namespace psemek::ui::impl size_constraints compute_size_constraints(std::vector const & size_policies, std::vector const & children_size_constraints, float padding) { - if (size_policies.size() != children_size_constraints.size()) - return size_constraints::max(); - size_constraints minimized = size_constraints::max(); size_constraints weight_unit = minimized; float weight_sum = 0.f; - for (std::size_t i = 0; i < size_policies.size(); ++i) + for (std::size_t i = 0; i < std::min(size_policies.size(), children_size_constraints.size()); ++i) { if (std::get_if(&size_policies[i])) { @@ -53,17 +50,20 @@ namespace psemek::ui::impl std::vector allocate(float total_size, std::vector> const & size_policies, util::span const> children, float padding) { - std::vector result(size_policies.size(), 0.f); + std::vector result(std::min(size_policies.size(), children.size()), 0.f); if (!size_policies.empty()) - total_size -= padding * (size_policies.size() - 1); + total_size -= padding * (result.size() - 1); float total_weight = 0.f; // First, allocate minimized elements // Also compute the total weight for weighted elements - for (std::size_t i = 0; i < size_policies.size(); ++i) + for (std::size_t i = 0; i < result.size(); ++i) { + if (!children[i]) + continue; + auto const policy = size_policies[i] ? *size_policies[i] : default_policy; if (std::get_if(&policy)) @@ -78,7 +78,7 @@ namespace psemek::ui::impl } // Next, allocate weighted elements - for (std::size_t i = 0; i < size_policies.size(); ++i) + for (std::size_t i = 0; i < result.size(); ++i) { auto const policy = size_policies[i] ? *size_policies[i] : default_policy;