mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Add "New" badge for affiliate programs.
This commit is contained in:
parent
42a2de4bf0
commit
f381005184
6 changed files with 57 additions and 12 deletions
|
@ -62,6 +62,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/controls/emoji_button.h"
|
#include "ui/controls/emoji_button.h"
|
||||||
#include "ui/controls/userpic_button.h"
|
#include "ui/controls/userpic_button.h"
|
||||||
#include "ui/effects/premium_graphics.h"
|
#include "ui/effects/premium_graphics.h"
|
||||||
|
#include "ui/new_badges.h"
|
||||||
#include "ui/rect.h"
|
#include "ui/rect.h"
|
||||||
#include "ui/rp_widget.h"
|
#include "ui/rp_widget.h"
|
||||||
#include "ui/vertical_list.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_chat_helpers.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
#include "styles/style_settings.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_info.h"
|
#include "styles/style_info.h"
|
||||||
|
|
||||||
|
@ -1440,7 +1442,7 @@ void Controller::fillManageSection() {
|
||||||
tr::lng_manage_peer_star_ref(),
|
tr::lng_manage_peer_star_ref(),
|
||||||
rpl::single(QString()), // Empty count.
|
rpl::single(QString()), // Empty count.
|
||||||
std::move(callback),
|
std::move(callback),
|
||||||
{ &st::menuIconSharing });
|
{ .icon = &st::menuIconStarRefShare, .newBadge = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canEditStickers || canDeleteChannel) {
|
if (canEditStickers || canDeleteChannel) {
|
||||||
|
@ -1755,7 +1757,7 @@ void Controller::fillBotAffiliateProgram() {
|
||||||
[controller = _navigation->parentController(), user] {
|
[controller = _navigation->parentController(), user] {
|
||||||
controller->showSection(Info::BotStarRef::Setup::Make(user));
|
controller->showSection(Info::BotStarRef::Setup::Make(user));
|
||||||
},
|
},
|
||||||
{ &st::menuIconSharing });
|
{ .icon = &st::menuIconSharing, .newBadge = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::fillBotEditIntroButton() {
|
void Controller::fillBotEditIntroButton() {
|
||||||
|
@ -2550,6 +2552,13 @@ object_ptr<Ui::SettingsButton> EditPeerInfoBox::CreateButton(
|
||||||
st.button);
|
st.button);
|
||||||
const auto button = result.data();
|
const auto button = result.data();
|
||||||
button->addClickHandler(callback);
|
button->addClickHandler(callback);
|
||||||
|
|
||||||
|
const auto badge = descriptor.newBadge
|
||||||
|
? Ui::NewBadge::CreateNewBadge(
|
||||||
|
button,
|
||||||
|
tr::lng_premium_summary_new_badge()).get()
|
||||||
|
: nullptr;
|
||||||
|
|
||||||
if (descriptor) {
|
if (descriptor) {
|
||||||
AddButtonIcon(
|
AddButtonIcon(
|
||||||
button,
|
button,
|
||||||
|
@ -2558,7 +2567,7 @@ object_ptr<Ui::SettingsButton> EditPeerInfoBox::CreateButton(
|
||||||
}
|
}
|
||||||
|
|
||||||
auto labelText = rpl::combine(
|
auto labelText = rpl::combine(
|
||||||
std::move(text),
|
rpl::duplicate(text),
|
||||||
std::move(count),
|
std::move(count),
|
||||||
button->widthValue()
|
button->widthValue()
|
||||||
) | rpl::map([&st](const QString &text, const QString &count, int width) {
|
) | rpl::map([&st](const QString &text, const QString &count, int width) {
|
||||||
|
@ -2573,11 +2582,40 @@ object_ptr<Ui::SettingsButton> EditPeerInfoBox::CreateButton(
|
||||||
: count;
|
: 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>(
|
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
button,
|
button,
|
||||||
std::move(labelText),
|
std::move(labelText),
|
||||||
st.label);
|
st.label);
|
||||||
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
label->show();
|
||||||
|
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
button->widthValue(),
|
button->widthValue(),
|
||||||
|
|
|
@ -674,6 +674,12 @@ manageGroupButton: SettingsCountButton(managePeerButton) {
|
||||||
labelPosition: point(22px, 10px);
|
labelPosition: point(22px, 10px);
|
||||||
iconPosition: point(20px, 4px);
|
iconPosition: point(20px, 4px);
|
||||||
}
|
}
|
||||||
|
infoSharedMediaCountButton: SettingsCountButton(managePeerButton) {
|
||||||
|
button: infoSharedMediaButton;
|
||||||
|
iconPosition: point(20px, 4px);
|
||||||
|
label: defaultSettingsRightLabel;
|
||||||
|
labelPosition: point(24px, 10px);
|
||||||
|
}
|
||||||
|
|
||||||
manageGroupTopButtonWithText: SettingsCountButton(manageGroupButton) {
|
manageGroupTopButtonWithText: SettingsCountButton(manageGroupButton) {
|
||||||
iconPosition: point(0px, 0px);
|
iconPosition: point(0px, 0px);
|
||||||
|
|
|
@ -2165,14 +2165,13 @@ void ActionsFiller::addAffiliateProgram(not_null<UserData*> user) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ui::AddSkip(inner);
|
inner->add(EditPeerInfoBox::CreateButton(
|
||||||
::Settings::AddButtonWithLabel(
|
|
||||||
inner,
|
inner,
|
||||||
tr::lng_manage_peer_bot_star_ref(),
|
tr::lng_manage_peer_bot_star_ref(),
|
||||||
rpl::duplicate(commission),
|
rpl::duplicate(commission),
|
||||||
st::infoSharedMediaButton,
|
recipients->open,
|
||||||
{ &st::menuIconSharing }
|
st::infoSharedMediaCountButton,
|
||||||
)->setClickedCallback(recipients->open);
|
{ .icon = &st::menuIconSharing, .newBadge = true }));
|
||||||
Ui::AddSkip(inner);
|
Ui::AddSkip(inner);
|
||||||
Ui::AddDividerText(
|
Ui::AddDividerText(
|
||||||
inner,
|
inner,
|
||||||
|
|
|
@ -131,6 +131,7 @@ struct IconDescriptor {
|
||||||
IconType type = IconType::Rounded;
|
IconType type = IconType::Rounded;
|
||||||
const style::color *background = nullptr;
|
const style::color *background = nullptr;
|
||||||
std::optional<QBrush> backgroundBrush; // Can be useful for gradients.
|
std::optional<QBrush> backgroundBrush; // Can be useful for gradients.
|
||||||
|
bool newBadge = false;
|
||||||
|
|
||||||
explicit operator bool() const {
|
explicit operator bool() const {
|
||||||
return (icon != nullptr);
|
return (icon != nullptr);
|
||||||
|
|
|
@ -14,9 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_settings.h"
|
#include "styles/style_settings.h"
|
||||||
|
|
||||||
namespace Ui::NewBadge {
|
namespace Ui::NewBadge {
|
||||||
namespace {
|
|
||||||
|
|
||||||
[[nodiscard]] not_null<Ui::RpWidget*> CreateNewBadge(
|
not_null<Ui::RpWidget*> CreateNewBadge(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
rpl::producer<QString> text) {
|
rpl::producer<QString> text) {
|
||||||
const auto badge = Ui::CreateChild<Ui::PaddingWrap<Ui::FlatLabel>>(
|
const auto badge = Ui::CreateChild<Ui::PaddingWrap<Ui::FlatLabel>>(
|
||||||
|
@ -38,8 +37,6 @@ namespace {
|
||||||
return badge;
|
return badge;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void AddToRight(not_null<Ui::RpWidget*> parent) {
|
void AddToRight(not_null<Ui::RpWidget*> parent) {
|
||||||
const auto badge = CreateNewBadge(parent, tr::lng_bot_side_menu_new());
|
const auto badge = CreateNewBadge(parent, tr::lng_bot_side_menu_new());
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,10 @@ class RpWidget;
|
||||||
|
|
||||||
namespace Ui::NewBadge {
|
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 AddToRight(not_null<Ui::RpWidget*> parent);
|
||||||
void AddAfterLabel(
|
void AddAfterLabel(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
|
|
Loading…
Add table
Reference in a new issue