65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
#include <psemek/ui/impl/stack_layout_base.hpp>
|
|
#include <psemek/ui/impl/size_polygon_utils.hpp>
|
|
#include <psemek/react/join.hpp>
|
|
#include <psemek/react/map.hpp>
|
|
|
|
namespace psemek::ui::impl
|
|
{
|
|
|
|
namespace
|
|
{
|
|
|
|
size_polygon compute_size_constraints(std::vector<size_polygon const *> const & children_size_constraints)
|
|
{
|
|
if (children_size_constraints.empty())
|
|
return component::default_size_polygon();
|
|
|
|
auto result = *children_size_constraints.front();
|
|
for (std::size_t i = 1; i < children_size_constraints.size(); ++i)
|
|
result = intersect(result, *children_size_constraints[i]);
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|
|
stack_layout_base::stack_layout_base()
|
|
: size_constraints_(react::map([](auto const & children_size_constraints){
|
|
return compute_size_constraints(children_size_constraints);
|
|
}, react::join(react::map(react::unpack_with_transform([](react::value<size_polygon> const & arg){ return &(*arg); }), children_size_constraints_))))
|
|
{}
|
|
|
|
void stack_layout_base::reshape(geom::box<float, 2> const & new_shape)
|
|
{
|
|
for (auto const & child : children())
|
|
if (child)
|
|
child->reshape(new_shape);
|
|
}
|
|
|
|
react::value<size_polygon> stack_layout_base::size_constraints() const
|
|
{
|
|
return size_constraints_;
|
|
}
|
|
|
|
void stack_layout_base::set_children(std::vector<std::unique_ptr<component>> children)
|
|
{
|
|
container::set_children(std::move(children));
|
|
std::vector<react::value<size_polygon>> children_size_constraints;
|
|
for (auto const & child : this->children())
|
|
{
|
|
if (child)
|
|
children_size_constraints.push_back(child->size_constraints());
|
|
else
|
|
children_size_constraints.push_back(default_size_constraints());
|
|
}
|
|
children_size_constraints_.set(std::move(children_size_constraints));
|
|
}
|
|
|
|
std::vector<std::unique_ptr<component>> stack_layout_base::release_children()
|
|
{
|
|
auto result = container::release_children();
|
|
children_size_constraints_.set({});
|
|
return result;
|
|
}
|
|
|
|
|
|
}
|