Fix action offset in button children

This commit is contained in:
Nikita Lisitsa 2021-03-05 15:55:36 +03:00
parent e67b3f1fdc
commit bcba2893bf
2 changed files with 8 additions and 11 deletions

View file

@ -71,17 +71,9 @@ namespace psemek::ui
void button::on_state_changed(state_t old) void button::on_state_changed(state_t old)
{ {
auto s = merged_style(); if (state() == state_t::mousedown || old == state_t::mousedown)
if (state() == state_t::mousedown)
{ {
for (auto c : children()) post_reshape();
if (c) c->reshape(c->shape().bbox() + geom::cast<float>(*s->action_offset));
}
else if (old == state_t::mousedown)
{
for (auto c : children())
if (c) c->reshape(c->shape().bbox() - geom::cast<float>(*s->action_offset));
} }
} }

View file

@ -24,8 +24,13 @@ namespace psemek::ui
{ {
shape_.box = bbox; shape_.box = bbox;
auto st = merged_style(); auto st = merged_style();
geom::vector offset{0.f, 0.f};
if (state() == state_t::mousedown)
offset = geom::cast<float>(*st->action_offset);
element * c = label() ? (element *)label() : icon(); element * c = label() ? (element *)label() : icon();
if (st && c) c->reshape(geom::shrink(bbox, 1.f * (*st->border_width + *st->inner_margin))); if (c) c->reshape(geom::shrink(bbox, 1.f * (*st->border_width + *st->inner_margin)) + offset);
} }
void on_state_changed(state_t old) override void on_state_changed(state_t old) override