Implement width/height_constraints for default ui::frame implementation
This commit is contained in:
parent
83559aba51
commit
83cb71d2c0
1 changed files with 26 additions and 16 deletions
|
|
@ -128,35 +128,45 @@ namespace psemek::ui
|
||||||
|
|
||||||
geom::box<float, 2> size_constraints() const override
|
geom::box<float, 2> size_constraints() const override
|
||||||
{
|
{
|
||||||
geom::box<float, 2> r = element::size_constraints();
|
geom::box<float, 2> sc = frame::size_constraints();
|
||||||
|
|
||||||
for (auto c : children())
|
|
||||||
if (c)
|
|
||||||
r = c->size_constraints();
|
|
||||||
|
|
||||||
auto st = merged_own_style();
|
auto st = merged_own_style();
|
||||||
if (st)
|
if (st)
|
||||||
{
|
{
|
||||||
float extra = 2.f * (*st->border_width + *st->bevel_width + *st->outer_margin);
|
float extra = 2.f * (*st->border_width + *st->bevel_width + *st->outer_margin);
|
||||||
r[0] += extra;
|
sc[0] += extra;
|
||||||
r[1] += extra;
|
sc[1] += extra;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min_size())
|
return sc;
|
||||||
|
}
|
||||||
|
|
||||||
|
geom::interval<float> width_constraints(float height) const override
|
||||||
{
|
{
|
||||||
auto s = *min_size();
|
auto wc = frame::width_constraints(height);
|
||||||
r[0].min = std::max(r[0].min, s[0]);
|
|
||||||
r[1].min = std::max(r[1].min, s[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (max_size())
|
auto st = merged_own_style();
|
||||||
|
if (st)
|
||||||
{
|
{
|
||||||
auto s = *max_size();
|
float extra = 2.f * (*st->border_width + *st->bevel_width + *st->outer_margin);
|
||||||
r[0].max = std::min(r[0].max, s[0]);
|
wc += extra;
|
||||||
r[1].max = std::min(r[1].max, s[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return wc;
|
||||||
|
}
|
||||||
|
|
||||||
|
geom::interval<float> height_constraints(float width) const override
|
||||||
|
{
|
||||||
|
auto hc = frame::height_constraints(width);
|
||||||
|
|
||||||
|
auto st = merged_own_style();
|
||||||
|
if (st)
|
||||||
|
{
|
||||||
|
float extra = 2.f * (*st->border_width + *st->bevel_width + *st->outer_margin);
|
||||||
|
hc += extra;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(painter & p) const override
|
void draw(painter & p) const override
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue