psemek/libs/ui/source/frame.cpp
2021-02-25 21:09:26 +03:00

59 lines
1 KiB
C++

#include <psemek/ui/frame.hpp>
namespace psemek::ui
{
std::shared_ptr<element> frame::set_child(std::shared_ptr<element> c)
{
auto old = std::move(child_);
if (old) old->set_parent(nullptr);
child_ = std::move(c);
if (child_) child_->set_parent(this);
children_[0] = child_.get();
return old;
}
void frame::set_min_size(std::optional<geom::vector<float, 2>> const & size)
{
min_size_ = size;
post_reshape();
}
void frame::set_max_size(std::optional<geom::vector<float, 2>> const & size)
{
max_size_ = size;
post_reshape();
}
void frame::set_fixed_size(geom::vector<float, 2> const & size)
{
min_size_ = size;
max_size_ = size;
post_reshape();
}
geom::box<float, 2> frame::size_constraints() const
{
geom::box<float, 2> r = element::size_constraints();
if (child_)
r = child_->size_constraints();
if (min_size_)
{
r[0].min = (*min_size_)[0];
r[1].min = (*min_size_)[1];
}
if (max_size_)
{
r[0].max = (*max_size_)[0];
r[1].max = (*max_size_)[1];
}
return r;
}
}