Add "New" badge for affiliate programs.

This commit is contained in:
John Preston 2024-12-03 17:19:45 +04:00
parent 42a2de4bf0
commit f381005184
6 changed files with 57 additions and 12 deletions

View file

@ -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<Ui::SettingsButton> 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<Ui::SettingsButton> 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<Ui::SettingsButton> 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<Ui::FlatLabel>(
button,
std::move(labelText),
st.label);
label->setAttribute(Qt::WA_TransparentForMouseEvents);
label->show();
rpl::combine(
button->widthValue(),

View file

@ -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);

View file

@ -2165,14 +2165,13 @@ void ActionsFiller::addAffiliateProgram(not_null<UserData*> 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,

View file

@ -131,6 +131,7 @@ struct IconDescriptor {
IconType type = IconType::Rounded;
const style::color *background = nullptr;
std::optional<QBrush> backgroundBrush; // Can be useful for gradients.
bool newBadge = false;
explicit operator bool() const {
return (icon != nullptr);

View file

@ -14,9 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_settings.h"
namespace Ui::NewBadge {
namespace {
[[nodiscard]] not_null<Ui::RpWidget*> CreateNewBadge(
not_null<Ui::RpWidget*> CreateNewBadge(
not_null<Ui::RpWidget*> parent,
rpl::producer<QString> text) {
const auto badge = Ui::CreateChild<Ui::PaddingWrap<Ui::FlatLabel>>(
@ -38,8 +37,6 @@ namespace {
return badge;
}
} // namespace
void AddToRight(not_null<Ui::RpWidget*> parent) {
const auto badge = CreateNewBadge(parent, tr::lng_bot_side_menu_new());

View file

@ -13,6 +13,10 @@ class RpWidget;
namespace Ui::NewBadge {
[[nodiscard]] not_null<Ui::RpWidget*> CreateNewBadge(
not_null<Ui::RpWidget*> parent,
rpl::producer<QString> text);
void AddToRight(not_null<Ui::RpWidget*> parent);
void AddAfterLabel(
not_null<Ui::RpWidget*> parent,