Moved out child centering within widget to single function.

This commit is contained in:
23rd 2023-12-19 01:52:33 +03:00
parent 431549c81a
commit 8bcb784f12
4 changed files with 18 additions and 14 deletions

View file

@ -647,13 +647,7 @@ void GiftsBox(
const auto loadingAnimation = InfiniteRadialAnimationWidget( const auto loadingAnimation = InfiniteRadialAnimationWidget(
raw, raw,
raw->height() / 2); raw->height() / 2);
raw->sizeValue( AddChildToWidgetCenter(raw, loadingAnimation);
) | rpl::start_with_next([=](const QSize &s) {
const auto size = loadingAnimation->size();
loadingAnimation->moveToLeft(
(s.width() - size.width()) / 2,
(s.height() - size.height()) / 2);
}, loadingAnimation->lifetime());
loadingAnimation->showOn(state->confirmButtonBusy.value()); loadingAnimation->showOn(state->confirmButtonBusy.value());
} }
auto button = object_ptr<Ui::GradientButton>::fromRaw(raw); auto button = object_ptr<Ui::GradientButton>::fromRaw(raw);

View file

@ -958,13 +958,7 @@ void CreateGiveawayBox(
const auto loadingAnimation = InfiniteRadialAnimationWidget( const auto loadingAnimation = InfiniteRadialAnimationWidget(
button, button,
st::giveawayGiftCodeStartButton.height / 2); st::giveawayGiftCodeStartButton.height / 2);
button->sizeValue( AddChildToWidgetCenter(button.data(), loadingAnimation);
) | rpl::start_with_next([=](const QSize &s) {
const auto size = loadingAnimation->size();
loadingAnimation->moveToLeft(
(s.width() - size.width()) / 2,
(s.height() - size.height()) / 2);
}, loadingAnimation->lifetime());
loadingAnimation->showOn(state->confirmButtonBusy.value()); loadingAnimation->showOn(state->confirmButtonBusy.value());
} }

View file

@ -52,6 +52,18 @@ not_null<Ui::RpWidget*> InfiniteRadialAnimationWidget(
return Ui::CreateChild<Widget>(parent.get(), size); return Ui::CreateChild<Widget>(parent.get(), size);
} }
void AddChildToWidgetCenter(
not_null<Ui::RpWidget*> parent,
not_null<Ui::RpWidget*> child) {
parent->sizeValue(
) | rpl::start_with_next([=](const QSize &s) {
const auto size = child->size();
child->moveToLeft(
(s.width() - size.width()) / 2,
(s.height() - size.height()) / 2);
}, child->lifetime());
}
QImage CreateBadge( QImage CreateBadge(
const style::TextStyle &textStyle, const style::TextStyle &textStyle,
const QString &text, const QString &text,

View file

@ -32,6 +32,10 @@ namespace Info::Statistics {
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
int size); int size);
void AddChildToWidgetCenter(
not_null<Ui::RpWidget*> parent,
not_null<Ui::RpWidget*> child);
void AddLabelWithBadgeToButton( void AddLabelWithBadgeToButton(
not_null<Ui::RpWidget*> parent, not_null<Ui::RpWidget*> parent,
rpl::producer<QString> text, rpl::producer<QString> text,