Fix ui::impl::box_layout_base handling added elements
This commit is contained in:
parent
9234a28344
commit
7346aff9f6
1 changed files with 8 additions and 8 deletions
|
|
@ -14,14 +14,11 @@ namespace psemek::ui::impl
|
|||
size_constraints compute_size_constraints(std::vector<box_layout::size_policy> const & size_policies,
|
||||
std::vector<size_constraints> 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<box_layout::minimized>(&size_policies[i]))
|
||||
{
|
||||
|
|
@ -53,17 +50,20 @@ namespace psemek::ui::impl
|
|||
std::vector<float> allocate(float total_size, std::vector<react::value<box_layout::size_policy>> const & size_policies,
|
||||
util::span<std::unique_ptr<component> const> children, float padding)
|
||||
{
|
||||
std::vector<float> result(size_policies.size(), 0.f);
|
||||
std::vector<float> 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<box_layout::minimized>(&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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue