From f381005184dca3e7e6fd8b5d9f8a6f568bd1f796 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 3 Dec 2024 17:19:45 +0400 Subject: [PATCH] Add "New" badge for affiliate programs. --- .../boxes/peers/edit_peer_info_box.cpp | 44 +++++++++++++++++-- Telegram/SourceFiles/info/info.style | 6 +++ .../info/profile/info_profile_actions.cpp | 9 ++-- .../SourceFiles/settings/settings_common.h | 1 + Telegram/SourceFiles/ui/new_badges.cpp | 5 +-- Telegram/SourceFiles/ui/new_badges.h | 4 ++ 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 5b2b49cda..f80f4e73d 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -62,6 +62,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/controls/emoji_button.h" #include "ui/controls/userpic_button.h" #include "ui/effects/premium_graphics.h" +#include "ui/new_badges.h" #include "ui/rect.h" #include "ui/rp_widget.h" #include "ui/vertical_list.h" @@ -80,6 +81,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_chat_helpers.h" #include "styles/style_layers.h" #include "styles/style_menu_icons.h" +#include "styles/style_settings.h" #include "styles/style_boxes.h" #include "styles/style_info.h" @@ -1440,7 +1442,7 @@ void Controller::fillManageSection() { tr::lng_manage_peer_star_ref(), rpl::single(QString()), // Empty count. std::move(callback), - { &st::menuIconSharing }); + { .icon = &st::menuIconStarRefShare, .newBadge = true }); } if (canEditStickers || canDeleteChannel) { @@ -1755,7 +1757,7 @@ void Controller::fillBotAffiliateProgram() { [controller = _navigation->parentController(), user] { controller->showSection(Info::BotStarRef::Setup::Make(user)); }, - { &st::menuIconSharing }); + { .icon = &st::menuIconSharing, .newBadge = true }); } void Controller::fillBotEditIntroButton() { @@ -2550,6 +2552,13 @@ object_ptr EditPeerInfoBox::CreateButton( st.button); const auto button = result.data(); button->addClickHandler(callback); + + const auto badge = descriptor.newBadge + ? Ui::NewBadge::CreateNewBadge( + button, + tr::lng_premium_summary_new_badge()).get() + : nullptr; + if (descriptor) { AddButtonIcon( button, @@ -2558,7 +2567,7 @@ object_ptr EditPeerInfoBox::CreateButton( } auto labelText = rpl::combine( - std::move(text), + rpl::duplicate(text), std::move(count), button->widthValue() ) | rpl::map([&st](const QString &text, const QString &count, int width) { @@ -2573,11 +2582,40 @@ object_ptr EditPeerInfoBox::CreateButton( : count; }); + if (badge) { + rpl::combine( + std::move(text), + rpl::duplicate(labelText), + button->widthValue() + ) | rpl::start_with_next([=]( + const QString &text, + const QString &label, + int width) { + const auto space = st.button.style.font->spacew; + const auto left = st.button.padding.left() + + st.button.style.font->width(text) + + space; + const auto right = st.labelPosition.x() + + st.label.style.font->width(label) + + (space * 2); + const auto available = width - left - right; + badge->setVisible(available >= badge->width()); + if (!badge->isHidden()) { + const auto top = st.button.padding.top() + + st.button.style.font->ascent + - st::settingsPremiumNewBadge.style.font->ascent + - st::settingsPremiumNewBadgePadding.top(); + badge->moveToLeft(left, top, width); + } + }, badge->lifetime()); + } + const auto label = Ui::CreateChild( button, std::move(labelText), st.label); label->setAttribute(Qt::WA_TransparentForMouseEvents); + label->show(); rpl::combine( button->widthValue(), diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index 05796c024..4302f7a30 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -674,6 +674,12 @@ manageGroupButton: SettingsCountButton(managePeerButton) { labelPosition: point(22px, 10px); iconPosition: point(20px, 4px); } +infoSharedMediaCountButton: SettingsCountButton(managePeerButton) { + button: infoSharedMediaButton; + iconPosition: point(20px, 4px); + label: defaultSettingsRightLabel; + labelPosition: point(24px, 10px); +} manageGroupTopButtonWithText: SettingsCountButton(manageGroupButton) { iconPosition: point(0px, 0px); diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 37bc7cab9..b9a19fafd 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -2165,14 +2165,13 @@ void ActionsFiller::addAffiliateProgram(not_null user) { } }; - Ui::AddSkip(inner); - ::Settings::AddButtonWithLabel( + inner->add(EditPeerInfoBox::CreateButton( inner, tr::lng_manage_peer_bot_star_ref(), rpl::duplicate(commission), - st::infoSharedMediaButton, - { &st::menuIconSharing } - )->setClickedCallback(recipients->open); + recipients->open, + st::infoSharedMediaCountButton, + { .icon = &st::menuIconSharing, .newBadge = true })); Ui::AddSkip(inner); Ui::AddDividerText( inner, diff --git a/Telegram/SourceFiles/settings/settings_common.h b/Telegram/SourceFiles/settings/settings_common.h index d3492b96f..0f6c60e48 100644 --- a/Telegram/SourceFiles/settings/settings_common.h +++ b/Telegram/SourceFiles/settings/settings_common.h @@ -131,6 +131,7 @@ struct IconDescriptor { IconType type = IconType::Rounded; const style::color *background = nullptr; std::optional backgroundBrush; // Can be useful for gradients. + bool newBadge = false; explicit operator bool() const { return (icon != nullptr); diff --git a/Telegram/SourceFiles/ui/new_badges.cpp b/Telegram/SourceFiles/ui/new_badges.cpp index aa1cadafa..664248feb 100644 --- a/Telegram/SourceFiles/ui/new_badges.cpp +++ b/Telegram/SourceFiles/ui/new_badges.cpp @@ -14,9 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_settings.h" namespace Ui::NewBadge { -namespace { -[[nodiscard]] not_null CreateNewBadge( +not_null CreateNewBadge( not_null parent, rpl::producer text) { const auto badge = Ui::CreateChild>( @@ -38,8 +37,6 @@ namespace { return badge; } -} // namespace - void AddToRight(not_null parent) { const auto badge = CreateNewBadge(parent, tr::lng_bot_side_menu_new()); diff --git a/Telegram/SourceFiles/ui/new_badges.h b/Telegram/SourceFiles/ui/new_badges.h index 0d2161251..d1f99a21e 100644 --- a/Telegram/SourceFiles/ui/new_badges.h +++ b/Telegram/SourceFiles/ui/new_badges.h @@ -13,6 +13,10 @@ class RpWidget; namespace Ui::NewBadge { +[[nodiscard]] not_null CreateNewBadge( + not_null parent, + rpl::producer text); + void AddToRight(not_null parent); void AddAfterLabel( not_null parent,