From b3d770f0191b9bf53bf04e922f52ceb307d10624 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Thu, 17 Mar 2022 15:24:06 +0300 Subject: [PATCH] Make ui::frame a non-abstract class --- libs/ui/include/psemek/ui/frame.hpp | 6 +++++ libs/ui/source/frame.cpp | 36 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/libs/ui/include/psemek/ui/frame.hpp b/libs/ui/include/psemek/ui/frame.hpp index 23440467..af8b0a2a 100644 --- a/libs/ui/include/psemek/ui/frame.hpp +++ b/libs/ui/include/psemek/ui/frame.hpp @@ -15,6 +15,12 @@ namespace psemek::ui virtual std::optional> min_size() const { return min_size_; } virtual std::optional> max_size() const { return max_size_; } + struct shape const & shape() const override; + void reshape(geom::box const & box) override; + geom::box size_constraints() const override; + + void draw(painter &) const override {} + private: std::optional> min_size_; std::optional> max_size_; diff --git a/libs/ui/source/frame.cpp b/libs/ui/source/frame.cpp index 4bdd081b..da7c456d 100644 --- a/libs/ui/source/frame.cpp +++ b/libs/ui/source/frame.cpp @@ -1,4 +1,5 @@ #include +#include 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 const & box) + { + if (child_) + child_->reshape(box); + } + + geom::box 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; + } + }