#include #include #include #include namespace psemek::ui::impl { namespace { size_constraints compute_size_constraints(geom::vector, 2> const & size) { return { .box = {{ size[0] ? geom::interval::singleton(*(size[0])) : geom::interval(0.f, size_constraints::infinity), size[1] ? geom::interval::singleton(*(size[1])) : geom::interval(0.f, size_constraints::infinity), }}, }; } geom::box compute_shape(geom::box const & shape, geom::vector, 2> const & size) { return {{ size[0] ? align(shape[0], *(size[0]), halignment::center) : shape[0], size[1] ? align(shape[1], *(size[1]), valignment::center) : shape[1], }}; } } fixed_size_base::fixed_size_base() : size_({0.f, 0.f}) , size_constraints_(react::map(compute_size_constraints, react::join(size_))) {} void fixed_size_base::reshape(geom::box const & new_shape) { single_container::reshape(new_shape); if (auto child = this->child()) child->reshape(compute_shape(new_shape, **size_)); } react::value fixed_size_base::size_constraints() const { return size_constraints_; } void fixed_size_base::update(fixed_size const & value) { size_.set(react::map([](geom::vector const & size){ return geom::vector, 2>{size[0], size[1]}; }, value.size)); } void fixed_size_base::update(fixed_width const & value) { size_.set(react::map([](float width){ return geom::vector, 2>{width, std::nullopt}; }, value.width)); } void fixed_size_base::update(fixed_height const & value) { size_.set(react::map([](float height){ return geom::vector, 2>{std::nullopt, height}; }, value.height)); } }