From bcba2893bf00c2fbb0001b00bdba805c968f41d5 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 5 Mar 2021 15:55:36 +0300 Subject: [PATCH] Fix action offset in button children --- libs/ui/source/button.cpp | 12 ++---------- libs/ui/source/default_element_factory.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/libs/ui/source/button.cpp b/libs/ui/source/button.cpp index 4c4a0864..e1a87d8a 100644 --- a/libs/ui/source/button.cpp +++ b/libs/ui/source/button.cpp @@ -71,17 +71,9 @@ namespace psemek::ui void button::on_state_changed(state_t old) { - auto s = merged_style(); - - if (state() == state_t::mousedown) + if (state() == state_t::mousedown || old == state_t::mousedown) { - for (auto c : children()) - if (c) c->reshape(c->shape().bbox() + geom::cast(*s->action_offset)); - } - else if (old == state_t::mousedown) - { - for (auto c : children()) - if (c) c->reshape(c->shape().bbox() - geom::cast(*s->action_offset)); + post_reshape(); } } diff --git a/libs/ui/source/default_element_factory.cpp b/libs/ui/source/default_element_factory.cpp index c2c8caab..f4e8fcf4 100644 --- a/libs/ui/source/default_element_factory.cpp +++ b/libs/ui/source/default_element_factory.cpp @@ -24,8 +24,13 @@ namespace psemek::ui { shape_.box = bbox; auto st = merged_style(); + + geom::vector offset{0.f, 0.f}; + if (state() == state_t::mousedown) + offset = geom::cast(*st->action_offset); + 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