From 3549349ffb55080620aa3ff2c35065c90e932be0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 14 Aug 2024 18:15:37 +0200 Subject: [PATCH] Improve layout for the first star reaction. --- .../payments/ui/payments_reaction_box.cpp | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/payments/ui/payments_reaction_box.cpp b/Telegram/SourceFiles/payments/ui/payments_reaction_box.cpp index c6aaf796f..a5091c019 100644 --- a/Telegram/SourceFiles/payments/ui/payments_reaction_box.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_reaction_box.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/continuous_sliders.h" +#include "ui/wrap/slide_wrap.h" #include "ui/dynamic_image.h" #include "ui/painter.h" #include "ui/vertical_list.h" @@ -242,8 +243,11 @@ void FillTopReactors( const auto height = st::paidReactTopNameSkip + st::normalFont->height; const auto wrap = container->add( - object_ptr(container, height), - st::paidReactTopMargin); + object_ptr>( + container, + object_ptr(container, height), + st::paidReactTopMargin)); + const auto parent = wrap->entity(); struct State { std::vector> widgets; rpl::event_stream<> updated; @@ -261,11 +265,6 @@ void FillTopReactors( } else if (*state->initialChosen != chosen) { state->chosenChanged = true; } - for (const auto &widget : state->widgets) { - delete widget; - } - state->widgets.clear(); - auto list = std::vector(); list.reserve(kMaxTopPaidShown + 1); for (const auto &entry : top) { @@ -283,14 +282,26 @@ void FillTopReactors( list, ranges::greater(), &PaidReactionTop::count); - while (list.size() > kMaxTopPaidShown) { + while (list.size() > kMaxTopPaidShown + || (!list.empty() && !list.back().count)) { list.pop_back(); } - for (const auto &entry : list) { - state->widgets.push_back(MakeTopReactor(wrap, entry)); + if (list.empty()) { + wrap->hide(anim::type::normal); + } else { + for (const auto &widget : state->widgets) { + delete widget; + } + state->widgets.clear(); + for (const auto &entry : list) { + state->widgets.push_back(MakeTopReactor(parent, entry)); + } + wrap->show(anim::type::normal); } + state->updated.fire({}); }, wrap->lifetime()); + wrap->finishAnimating(); rpl::combine( state->updated.events_starting_with({}),