Fix default ui::button child & size constraints handling
This commit is contained in:
parent
5bf544d032
commit
932e64a991
1 changed files with 49 additions and 11 deletions
|
|
@ -40,7 +40,7 @@ namespace psemek::ui
|
||||||
if (state() == state_t::mousedown)
|
if (state() == state_t::mousedown)
|
||||||
offset = geom::cast<float>(*st->action_offset);
|
offset = geom::cast<float>(*st->action_offset);
|
||||||
|
|
||||||
element * c = label() ? (element *)label() : icon();
|
auto c = child_.get();
|
||||||
if (c) c->reshape(geom::shrink(bbox, geom::vector<float, 2>{*st->border_width + (*st->inner_margin)[0], *st->border_width + (*st->inner_margin)[1]}) + offset);
|
if (c) c->reshape(geom::shrink(bbox, geom::vector<float, 2>{*st->border_width + (*st->inner_margin)[0], *st->border_width + (*st->inner_margin)[1]}) + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,24 +92,62 @@ namespace psemek::ui
|
||||||
{
|
{
|
||||||
auto sc = element::size_constraints();
|
auto sc = element::size_constraints();
|
||||||
|
|
||||||
element const * c = label() ? (element const *)label() : icon();
|
if (child_)
|
||||||
|
|
||||||
if (c)
|
|
||||||
{
|
{
|
||||||
sc = c->size_constraints();
|
auto csc = child_->size_constraints();
|
||||||
|
sc[0].min = csc[0].min;
|
||||||
|
sc[1].min = csc[1].min;
|
||||||
|
}
|
||||||
|
|
||||||
if (auto st = merged_own_style())
|
if (auto st = merged_own_style())
|
||||||
{
|
{
|
||||||
sc[0] += 2.f * (*st->border_width);
|
sc[0] += 2.f * (*st->border_width);
|
||||||
sc[1] += 2.f * (*st->border_width);
|
sc[1] += 2.f * (*st->border_width);
|
||||||
|
|
||||||
sc += 2.f * geom::cast<float>(*st->inner_margin);
|
sc += 2.f * geom::cast<float>(*st->inner_margin);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sc;
|
return sc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
geom::interval<float> width_constraints(float height) const override
|
||||||
|
{
|
||||||
|
auto wc = element::width_constraints(height);
|
||||||
|
|
||||||
|
auto st = merged_own_style();
|
||||||
|
|
||||||
|
float extra = 2.f * (*st->border_width) + 2.f * geom::cast<float>(*st->inner_margin)[0];
|
||||||
|
|
||||||
|
if (child_)
|
||||||
|
{
|
||||||
|
auto cwc = child_->width_constraints(height - extra);
|
||||||
|
wc.min = cwc.min;
|
||||||
|
}
|
||||||
|
|
||||||
|
wc += extra;
|
||||||
|
|
||||||
|
return wc;
|
||||||
|
}
|
||||||
|
|
||||||
|
geom::interval<float> height_constraints(float width) const override
|
||||||
|
{
|
||||||
|
auto hc = element::height_constraints(width);
|
||||||
|
|
||||||
|
auto st = merged_own_style();
|
||||||
|
|
||||||
|
float extra = 2.f * (*st->border_width) + 2.f * geom::cast<float>(*st->inner_margin)[1];
|
||||||
|
|
||||||
|
if (child_)
|
||||||
|
{
|
||||||
|
auto chc = child_->height_constraints(width - extra);
|
||||||
|
hc.min = chc.min;
|
||||||
|
}
|
||||||
|
|
||||||
|
hc += extra;
|
||||||
|
|
||||||
|
return hc;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
box_shape shape_;
|
box_shape shape_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue