From 8bcb784f12e04dec052e947eb55e7d3b23fc2854 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 19 Dec 2023 01:52:33 +0300 Subject: [PATCH] Moved out child centering within widget to single function. --- Telegram/SourceFiles/boxes/gift_premium_box.cpp | 8 +------- .../SourceFiles/info/boosts/create_giveaway_box.cpp | 8 +------- .../SourceFiles/info/boosts/giveaway/boost_badge.cpp | 12 ++++++++++++ .../SourceFiles/info/boosts/giveaway/boost_badge.h | 4 ++++ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/boxes/gift_premium_box.cpp b/Telegram/SourceFiles/boxes/gift_premium_box.cpp index a1be8a334..0c7e728f5 100644 --- a/Telegram/SourceFiles/boxes/gift_premium_box.cpp +++ b/Telegram/SourceFiles/boxes/gift_premium_box.cpp @@ -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::fromRaw(raw); diff --git a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp index 927d08de0..3b06d0adb 100644 --- a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp +++ b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp @@ -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()); } diff --git a/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.cpp b/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.cpp index 13e8fb192..f6cc1f548 100644 --- a/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.cpp +++ b/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.cpp @@ -52,6 +52,18 @@ not_null InfiniteRadialAnimationWidget( return Ui::CreateChild(parent.get(), size); } +void AddChildToWidgetCenter( + not_null parent, + not_null 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, diff --git a/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.h b/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.h index fe2427e9c..221f6017f 100644 --- a/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.h +++ b/Telegram/SourceFiles/info/boosts/giveaway/boost_badge.h @@ -32,6 +32,10 @@ namespace Info::Statistics { not_null parent, int size); +void AddChildToWidgetCenter( + not_null parent, + not_null child); + void AddLabelWithBadgeToButton( not_null parent, rpl::producer text,