Make ui::frame a non-abstract class

This commit is contained in:
Nikita Lisitsa 2022-03-17 15:24:06 +03:00
parent 036c1c543f
commit b3d770f019
2 changed files with 42 additions and 0 deletions

View file

@ -15,6 +15,12 @@ namespace psemek::ui
virtual std::optional<geom::vector<float, 2>> min_size() const { return min_size_; }
virtual std::optional<geom::vector<float, 2>> max_size() const { return max_size_; }
struct shape const & shape() const override;
void reshape(geom::box<float, 2> const & box) override;
geom::box<float, 2> size_constraints() const override;
void draw(painter &) const override {}
private:
std::optional<geom::vector<float, 2>> min_size_;
std::optional<geom::vector<float, 2>> max_size_;

View file

@ -1,4 +1,5 @@
#include <psemek/ui/frame.hpp>
#include <psemek/ui/null_shape.hpp>
namespace psemek::ui
{
@ -22,4 +23,39 @@ namespace psemek::ui
post_reshape();
}
shape const & frame::shape() const
{
static null_shape const fallback;
if (child_)
return child_->shape();
return fallback;
}
void frame::reshape(geom::box<float, 2> const & box)
{
if (child_)
child_->reshape(box);
}
geom::box<float, 2> frame::size_constraints() const
{
auto sc = element::size_constraints();
if (child_)
sc = child_->size_constraints();
if (min_size_)
{
sc[0].min = std::max(sc[0].min, (*min_size_)[0]);
sc[1].min = std::max(sc[1].min, (*min_size_)[1]);
}
if (max_size_)
{
sc[0].max = std::min(sc[0].max, (*max_size_)[0]);
sc[1].max = std::min(sc[1].max, (*max_size_)[1]);
}
return sc;
}
}