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(
raw,
raw->height() / 2);
raw->sizeValue(
) | 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());
AddChildToWidgetCenter(raw, loadingAnimation);
loadingAnimation->showOn(state->confirmButtonBusy.value());
}
auto button = object_ptr<Ui::GradientButton>::fromRaw(raw);

View File

@ -958,13 +958,7 @@ void CreateGiveawayBox(
const auto loadingAnimation = InfiniteRadialAnimationWidget(
button,
st::giveawayGiftCodeStartButton.height / 2);
button->sizeValue(
) | 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());
AddChildToWidgetCenter(button.data(), loadingAnimation);
loadingAnimation->showOn(state->confirmButtonBusy.value());
}

View File

@ -52,6 +52,18 @@ not_null<Ui::RpWidget*> InfiniteRadialAnimationWidget(
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(
const style::TextStyle &textStyle,
const QString &text,

View File

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