Fix ui::frame size constraints
This commit is contained in:
parent
2c39434f41
commit
3c851dfd60
3 changed files with 35 additions and 23 deletions
|
|
@ -17,7 +17,8 @@ namespace psemek::ui
|
|||
virtual void set_max_size(std::optional<geom::vector<float, 2>> const & size);
|
||||
virtual void set_fixed_size(geom::vector<float, 2> const & size);
|
||||
|
||||
geom::box<float, 2> size_constraints() const override;
|
||||
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_; }
|
||||
|
||||
private:
|
||||
std::optional<geom::vector<float, 2>> min_size_;
|
||||
|
|
|
|||
|
|
@ -87,6 +87,39 @@ namespace psemek::ui
|
|||
if (c) c->reshape(geom::shrink(bbox, 1.f * (st->border_width + st->outer_margin)));
|
||||
}
|
||||
|
||||
geom::box<float, 2> size_constraints() const override
|
||||
{
|
||||
geom::box<float, 2> r = element::size_constraints();
|
||||
|
||||
for (auto c : children())
|
||||
if (c)
|
||||
r = c->size_constraints();
|
||||
|
||||
auto st = style();
|
||||
if (st)
|
||||
{
|
||||
float extra = 2.f * (st->border_width + st->outer_margin);
|
||||
r[0] += extra;
|
||||
r[1] += extra;
|
||||
}
|
||||
|
||||
if (min_size())
|
||||
{
|
||||
auto s = *min_size();
|
||||
r[0].min = s[0];
|
||||
r[1].min = s[1];
|
||||
}
|
||||
|
||||
if (max_size())
|
||||
{
|
||||
auto s = *max_size();
|
||||
r[0].max = s[0];
|
||||
r[1].max = s[1];
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void draw(painter & p) const override
|
||||
{
|
||||
auto st = style();
|
||||
|
|
|
|||
|
|
@ -34,26 +34,4 @@ namespace psemek::ui
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue