67 lines
1.5 KiB
C++
67 lines
1.5 KiB
C++
#include <psemek/ui/impl/extend_base.hpp>
|
|
#include <psemek/react/join.hpp>
|
|
#include <psemek/react/map.hpp>
|
|
|
|
namespace psemek::ui::impl
|
|
{
|
|
|
|
namespace
|
|
{
|
|
|
|
geom::box<float, 2> compute_child_shape(geom::box<float, 2> shape, float left, float right, float top, float bottom)
|
|
{
|
|
shape[0].min -= left;
|
|
shape[0].max += right;
|
|
shape[1].min -= top;
|
|
shape[1].max += bottom;
|
|
return shape;
|
|
}
|
|
|
|
}
|
|
|
|
extend_base::extend_base()
|
|
: left_(0.f)
|
|
, right_(0.f)
|
|
, top_(0.f)
|
|
, bottom_(0.f)
|
|
, child_size_constraints_(size_constraints::max())
|
|
, size_constraints_(react::join(child_size_constraints_))
|
|
{}
|
|
|
|
void extend_base::reshape(geom::box<float, 2> const & new_shape)
|
|
{
|
|
single_container::reshape(new_shape);
|
|
|
|
if (auto child = this->child())
|
|
child->reshape(compute_child_shape(new_shape, **left_, **right_, **top_, **bottom_));
|
|
}
|
|
|
|
react::value<struct size_constraints> extend_base::size_constraints() const
|
|
{
|
|
return size_constraints_;
|
|
}
|
|
|
|
void extend_base::set_child(std::unique_ptr<component> child)
|
|
{
|
|
if (child)
|
|
child_size_constraints_.set(child->size_constraints());
|
|
else
|
|
child_size_constraints_.set(size_constraints::max());
|
|
single_container::set_child(std::move(child));
|
|
}
|
|
|
|
std::unique_ptr<component> extend_base::release_child()
|
|
{
|
|
child_size_constraints_.set(size_constraints::max());
|
|
return single_container::release_child();
|
|
}
|
|
|
|
void extend_base::update(extend const & value)
|
|
{
|
|
left_.set(value.left);
|
|
right_.set(value.right);
|
|
top_.set(value.top);
|
|
bottom_.set(value.bottom);
|
|
}
|
|
|
|
}
|