From 11986ac6982c59ed425c9ea70c21cda44364ea74 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 5 Jun 2025 11:33:43 +0400 Subject: [PATCH] Show star in channel direct messages settings. --- .../boxes/peers/edit_peer_info_box.cpp | 94 ++++++++++++------- .../boxes/peers/edit_peer_info_box.h | 7 ++ .../boosts/create_giveaway_box.cpp | 2 +- .../ui/widgets/expandable_peer_list.cpp | 4 +- 4 files changed, 72 insertions(+), 35 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 4604c4f6a7..19611e16e7 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -82,6 +82,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" #include "api/api_invite_links.h" #include "styles/style_chat_helpers.h" +#include "styles/style_credits.h" #include "styles/style_layers.h" #include "styles/style_menu_icons.h" #include "styles/style_settings.h" @@ -133,7 +134,7 @@ void AddButtonWithCount( not_null AddButtonWithText( not_null parent, rpl::producer &&text, - rpl::producer &&label, + rpl::producer &&label, Fn callback, Settings::IconDescriptor &&descriptor) { return parent->add(EditPeerInfoBox::CreateButton( @@ -145,6 +146,20 @@ not_null AddButtonWithText( std::move(descriptor))); } +not_null AddButtonWithText( + not_null parent, + rpl::producer &&text, + rpl::producer &&label, + Fn callback, + Settings::IconDescriptor &&descriptor) { + return AddButtonWithText( + parent, + std::move(text), + std::move(label) | Ui::Text::ToWithEntities(), + std::move(callback), + std::move(descriptor)); +} + void AddButtonDelete( not_null parent, rpl::producer &&text, @@ -1077,10 +1092,14 @@ void Controller::fillDirectMessagesButton() { auto label = _starsPerDirectMessageSavedValue->value( ) | rpl::map([](int starsPerMessage) { return (starsPerMessage < 0) - ? tr::lng_manage_monoforum_off() + ? tr::lng_manage_monoforum_off(Ui::Text::WithEntities) : !starsPerMessage - ? tr::lng_manage_monoforum_free() - : rpl::single(Lang::FormatCountDecimal(starsPerMessage)); + ? tr::lng_manage_monoforum_free(Ui::Text::WithEntities) + : rpl::single(Ui::Text::IconEmoji( + &st::starIconEmojiColored + ).append(' ').append( + Lang::FormatStarsAmountDecimal( + StarsAmount{ starsPerMessage }))); }) | rpl::flatten_latest(); AddButtonWithText( _controls.buttonsLayout, @@ -2866,6 +2885,22 @@ object_ptr EditPeerInfoBox::CreateButton( Fn callback, const style::SettingsCountButton &st, Settings::IconDescriptor &&descriptor) { + return CreateButton( + parent, + std::move(text), + std::move(count) | Ui::Text::ToWithEntities(), + std::move(callback), + st, + std::move(descriptor)); +} + +object_ptr EditPeerInfoBox::CreateButton( + not_null parent, + rpl::producer &&text, + rpl::producer &&labelText, + Fn callback, + const style::SettingsCountButton &st, + Settings::IconDescriptor &&descriptor) { auto result = object_ptr( parent, rpl::duplicate(text), @@ -2886,37 +2921,49 @@ object_ptr EditPeerInfoBox::CreateButton( std::move(descriptor)); } - auto labelText = rpl::combine( + const auto label = Ui::CreateChild( + button, + rpl::duplicate(labelText), + st.label); + label->setAttribute(Qt::WA_TransparentForMouseEvents); + label->show(); + + rpl::combine( rpl::duplicate(text), - std::move(count), + std::move(labelText), button->widthValue() - ) | rpl::map([&st](const QString &text, const QString &count, int width) { + ) | rpl::start_with_next([&st, label]( + const QString &text, + const TextWithEntities &labelText, + int width) { const auto available = width - st.button.padding.left() - (st.button.style.font->spacew * 2) - st.button.style.font->width(text) - st.labelPosition.x(); - const auto required = st.label.style.font->width(count); - return (required > available) - ? st.label.style.font->elided(count, std::max(available, 0)) - : count; - }); + const auto required = label->textMaxWidth(); + label->resizeToWidth(std::min(required, available)); + label->moveToRight( + st.labelPosition.x(), + st.labelPosition.y(), + width); + }, label->lifetime()); if (badge) { rpl::combine( std::move(text), - rpl::duplicate(labelText), + label->widthValue(), button->widthValue() ) | rpl::start_with_next([=]( const QString &text, - const QString &label, + int labelWidth, 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) + + labelWidth + (space * 2); const auto available = width - left - right; badge->setVisible(available >= badge->width()); @@ -2930,23 +2977,6 @@ object_ptr EditPeerInfoBox::CreateButton( }, badge->lifetime()); } - const auto label = Ui::CreateChild( - button, - std::move(labelText), - st.label); - label->setAttribute(Qt::WA_TransparentForMouseEvents); - label->show(); - - rpl::combine( - button->widthValue(), - label->widthValue() - ) | rpl::start_with_next([=, &st](int outerWidth, int width) { - label->moveToRight( - st.labelPosition.x(), - st.labelPosition.y(), - outerWidth); - }, label->lifetime()); - return result; } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h index b8787afac9..f918547c1b 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h @@ -46,6 +46,13 @@ public: Fn callback, const style::SettingsCountButton &st, Settings::IconDescriptor &&descriptor); + [[nodiscard]] static object_ptr CreateButton( + not_null parent, + rpl::producer &&text, + rpl::producer &&labelText, + Fn callback, + const style::SettingsCountButton &st, + Settings::IconDescriptor &&descriptor); protected: void prepare() override; diff --git a/Telegram/SourceFiles/info/channel_statistics/boosts/create_giveaway_box.cpp b/Telegram/SourceFiles/info/channel_statistics/boosts/create_giveaway_box.cpp index a5a73614e6..09f5cdeb60 100644 --- a/Telegram/SourceFiles/info/channel_statistics/boosts/create_giveaway_box.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/boosts/create_giveaway_box.cpp @@ -1250,7 +1250,7 @@ void CreateGiveawayBox( rpl::duplicate(creditsValueType), tr::lng_giveaway_additional_credits_about(), tr::lng_giveaway_additional_about() - ) | rpl::map(Ui::Text::WithEntities))); + ) | Ui::Text::ToWithEntities())); Ui::AddSkip(additionalWrap); } diff --git a/Telegram/SourceFiles/ui/widgets/expandable_peer_list.cpp b/Telegram/SourceFiles/ui/widgets/expandable_peer_list.cpp index fa43f4b920..a033a17b64 100644 --- a/Telegram/SourceFiles/ui/widgets/expandable_peer_list.cpp +++ b/Telegram/SourceFiles/ui/widgets/expandable_peer_list.cpp @@ -151,8 +151,8 @@ void AddExpandablePeerList( using namespace Info::Profile; auto name = controller->data.bold - ? NameValue(peer) | rpl::map(Ui::Text::Bold) - : NameValue(peer) | rpl::map(Ui::Text::WithEntities); + ? NameValue(peer) | Ui::Text::ToBold() + : NameValue(peer) | Ui::Text::ToWithEntities(); const auto userpic = Ui::CreateChild(line, peer, st); const auto checkbox = Ui::CreateChild(