From c9fb97cd7cc5ffc16a4b6bd774fdd7b17bff9634 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 7 Mar 2025 14:17:39 +0400 Subject: [PATCH] Simplify marked text context logic. --- Telegram/Resources/langs/lang.strings | 2 + Telegram/SourceFiles/api/api_chat_filters.cpp | 48 ++++------- .../SourceFiles/boxes/choose_filter_box.cpp | 18 ++--- .../boxes/filters/edit_filter_box.cpp | 16 ++-- .../boxes/filters/edit_filter_chats_list.cpp | 6 +- .../boxes/filters/edit_filter_links.cpp | 12 +-- .../SourceFiles/boxes/gift_credits_box.cpp | 10 +-- .../SourceFiles/boxes/gift_premium_box.cpp | 20 +---- .../boxes/moderate_messages_box.cpp | 5 +- Telegram/SourceFiles/boxes/passcode_box.cpp | 3 +- .../boxes/peers/edit_peer_color_box.cpp | 9 ++- .../boxes/peers/edit_peer_invite_link.cpp | 13 ++- .../boxes/peers/edit_peer_permissions_box.cpp | 5 +- .../boxes/peers/edit_peer_reactions.cpp | 23 +++--- .../SourceFiles/boxes/send_credits_box.cpp | 18 ++--- Telegram/SourceFiles/boxes/send_credits_box.h | 2 +- Telegram/SourceFiles/boxes/send_files_box.cpp | 5 +- Telegram/SourceFiles/boxes/star_gift_box.cpp | 24 ++---- Telegram/SourceFiles/boxes/translate_box.cpp | 10 +-- .../chat_helpers/message_field.cpp | 9 +-- Telegram/SourceFiles/core/ui_integration.cpp | 79 ++++++++++--------- Telegram/SourceFiles/core/ui_integration.h | 16 ++-- .../data/stickers/data_custom_emoji.cpp | 13 +-- .../dialogs/dialogs_inner_widget.cpp | 5 +- .../dialogs/dialogs_search_tags.cpp | 5 +- .../SourceFiles/dialogs/ui/dialogs_layout.cpp | 6 +- .../dialogs/ui/dialogs_message_view.cpp | 6 +- .../dialogs/ui/dialogs_topics_view.cpp | 6 +- Telegram/SourceFiles/history/history.cpp | 10 +-- .../history/history_item_components.cpp | 15 ++-- .../history/history_view_top_toast.cpp | 8 +- .../SourceFiles/history/history_widget.cpp | 11 ++- .../history_view_compose_controls.cpp | 11 ++- .../controls/history_view_forward_panel.cpp | 6 +- .../history/view/history_view_about_view.cpp | 6 +- .../view/history_view_contact_status.cpp | 14 ++-- .../view/history_view_contact_status.h | 2 +- .../history/view/history_view_element.cpp | 6 +- .../history/view/history_view_message.cpp | 11 ++- .../history/view/history_view_pinned_bar.cpp | 6 +- .../history/view/history_view_reply.cpp | 11 ++- .../history/view/media/history_view_game.cpp | 12 +-- .../history/view/media/history_view_media.cpp | 20 +++-- .../view/media/history_view_media_generic.cpp | 2 +- .../view/media/history_view_media_generic.h | 2 +- .../history/view/media/history_view_poll.cpp | 18 ++--- .../view/media/history_view_service_box.cpp | 12 +-- .../view/media/history_view_unique_gift.cpp | 4 +- .../view/media/history_view_unique_gift.h | 4 +- .../view/media/history_view_web_page.cpp | 25 +++--- .../reactions/history_view_reactions_list.cpp | 2 +- .../reactions/history_view_reactions_tabs.cpp | 2 +- .../bot/starref/info_bot_starref_common.cpp | 8 +- .../earn/info_channel_earn_list.cpp | 22 ++---- .../peer_gifts/info_peer_gifts_common.cpp | 7 +- .../info/peer_gifts/info_peer_gifts_common.h | 4 +- .../info/profile/info_profile_actions.cpp | 12 +-- .../info_statistics_list_controllers.cpp | 30 +++---- .../info_statistics_recent_message.cpp | 12 +-- .../inline_bots/bot_attach_web_view.cpp | 18 +---- Telegram/SourceFiles/intro/intro_step.cpp | 8 +- .../media_stories_caption_full_view.cpp | 5 +- .../media/stories/media_stories_header.cpp | 5 +- .../stories/media_stories_repost_view.cpp | 9 +-- .../media/view/media_view_overlay_widget.cpp | 6 +- Telegram/SourceFiles/menu/menu_sponsored.cpp | 9 +-- .../SourceFiles/overview/overview_layout.cpp | 8 +- .../payments/payments_reaction_process.cpp | 7 +- .../payments/ui/payments_reaction_box.h | 2 +- .../settings/business/settings_chat_links.cpp | 6 +- .../settings_cloud_password_common.cpp | 5 +- .../settings/settings_business.cpp | 9 +-- .../settings/settings_credits_graphics.cpp | 51 +++++------- .../SourceFiles/settings/settings_folders.cpp | 6 +- .../SourceFiles/settings/settings_premium.cpp | 10 +-- .../ui/boxes/collectible_info_box.cpp | 4 +- .../ui/boxes/collectible_info_box.h | 2 +- .../ui/boxes/edit_invite_link_session.cpp | 10 +-- .../SourceFiles/ui/chat/chats_filter_tag.cpp | 5 +- .../SourceFiles/ui/chat/chats_filter_tag.h | 7 +- Telegram/SourceFiles/ui/chat/message_bar.h | 2 +- .../ui/chat/sponsored_message_bar.cpp | 8 +- .../ui/controls/filter_link_header.cpp | 39 +++++---- .../ui/controls/filter_link_header.h | 4 +- .../SourceFiles/ui/controls/tabbed_search.cpp | 2 +- .../controls/who_reacted_context_action.cpp | 6 +- Telegram/SourceFiles/ui/unread_badge.cpp | 2 +- .../ui/widgets/chat_filters_tabs_slider.cpp | 2 +- .../ui/widgets/chat_filters_tabs_slider.h | 2 +- .../ui/widgets/chat_filters_tabs_strip.cpp | 11 +-- .../ui/widgets/discrete_sliders.cpp | 9 ++- .../SourceFiles/ui/widgets/discrete_sliders.h | 9 ++- .../ui/widgets/label_with_custom_emoji.cpp | 7 +- .../ui/widgets/label_with_custom_emoji.h | 12 +-- .../window/notifications_manager_default.cpp | 12 +-- .../window/window_filters_menu.cpp | 12 +-- .../window/window_session_controller.cpp | 8 +- Telegram/lib_ui | 2 +- 98 files changed, 441 insertions(+), 609 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 0748ac25d..5f59ce1b3 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3646,6 +3646,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_new_contact_phone_number" = "Phone number"; "lng_new_contact_registration" = "Registration"; "lng_new_contact_common_groups" = "Common groups"; +"lng_new_contact_groups#one" = "{count} group {emoji} {arrow}"; +"lng_new_contact_groups#other" = "{count} groups {emoji} {arrow}"; "lng_new_contact_not_official" = "Not an official account"; "lng_new_contact_updated_name" = "User updated name {when}"; "lng_new_contact_updated_photo" = "User updated photo {when}"; diff --git a/Telegram/SourceFiles/api/api_chat_filters.cpp b/Telegram/SourceFiles/api/api_chat_filters.cpp index d7a1636b3..55bbabbc5 100644 --- a/Telegram/SourceFiles/api/api_chat_filters.cpp +++ b/Telegram/SourceFiles/api/api_chat_filters.cpp @@ -149,18 +149,14 @@ void InitFilterLinkHeader( iconEmoji ).value_or(Ui::FilterIcon::Custom)).active; const auto isStatic = title.isStatic; - const auto makeContext = [=](Fn repaint) { - return Core::MarkedTextContext{ - .session = &box->peerListUiShow()->session(), - .customEmojiRepaint = std::move(repaint), - .customEmojiLoopLimit = isStatic ? -1 : 0, - }; - }; auto header = Ui::MakeFilterLinkHeader(box, { .type = type, .title = TitleText(type)(tr::now), .about = AboutText(type, title.text), - .makeAboutContext = makeContext, + .aboutContext = Core::TextContext({ + .session = &box->peerListUiShow()->session(), + .customEmojiLoopLimit = isStatic ? -1 : 0, + }), .folderTitle = title.text, .folderIcon = icon, .badge = (type == Ui::FilterLinkHeaderType::AddingChats @@ -560,16 +556,12 @@ void ShowImportToast( text.append('\n').append(phrase(tr::now, lt_count, added)); } const auto isStatic = title.isStatic; - const auto makeContext = [=](not_null widget) { - return Core::MarkedTextContext{ - .session = &strong->session(), - .customEmojiRepaint = [=] { widget->update(); }, - .customEmojiLoopLimit = isStatic ? -1 : 0, - }; - }; strong->showToast({ .text = std::move(text), - .textContext = makeContext, + .textContext = Core::TextContext({ + .session = &strong->session(), + .customEmojiLoopLimit = isStatic ? -1 : 0, + }) }); } @@ -640,18 +632,14 @@ void ProcessFilterInvite( raw->setRealContentHeight(box->heightValue()); const auto isStatic = title.isStatic; - const auto makeContext = [=](Fn update) { - return Core::MarkedTextContext{ - .session = &strong->session(), - .customEmojiRepaint = update, - .customEmojiLoopLimit = isStatic ? -1 : 0, - }; - }; auto owned = Ui::FilterLinkProcessButton( box, type, title.text, - makeContext, + Core::TextContext({ + .session = &strong->session(), + .customEmojiLoopLimit = isStatic ? -1 : 0, + }), std::move(badge)); const auto button = owned.data(); @@ -873,18 +861,14 @@ void ProcessFilterRemove( }, type, title, iconEmoji, rpl::single(0), horizontalFilters); const auto isStatic = title.isStatic; - const auto makeContext = [=](Fn update) { - return Core::MarkedTextContext{ - .session = &strong->session(), - .customEmojiRepaint = update, - .customEmojiLoopLimit = isStatic ? -1 : 0, - }; - }; auto owned = Ui::FilterLinkProcessButton( box, type, title.text, - makeContext, + Core::TextContext({ + .session = &strong->session(), + .customEmojiLoopLimit = isStatic ? -1 : 0, + }), std::move(badge)); const auto button = owned.data(); diff --git a/Telegram/SourceFiles/boxes/choose_filter_box.cpp b/Telegram/SourceFiles/boxes/choose_filter_box.cpp index 7448332d3..93164126b 100644 --- a/Telegram/SourceFiles/boxes/choose_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/choose_filter_box.cpp @@ -172,13 +172,6 @@ void ChangeFilterById( const auto account = not_null(&history->session().account()); if (const auto controller = Core::App().windowFor(account)) { const auto isStatic = name.isStatic; - const auto textContext = [=](not_null widget) { - return Core::MarkedTextContext{ - .session = &history->session(), - .customEmojiRepaint = [=] { widget->update(); }, - .customEmojiLoopLimit = isStatic ? -1 : 0, - }; - }; controller->showToast({ .text = (add ? tr::lng_filters_toast_add @@ -189,7 +182,10 @@ void ChangeFilterById( lt_folder, Ui::Text::Wrapped(name.text, EntityType::Bold), Ui::Text::WithEntities), - .textContext = textContext, + .textContext = Core::TextContext({ + .session = &history->session(), + .customEmojiLoopLimit = isStatic ? -1 : 0, + }), }); } }).fail([=](const MTP::Error &error) { @@ -297,12 +293,10 @@ void FillChooseFilterMenu( std::move(callback)), contains ? &st::mediaPlayerMenuCheck : nullptr, contains ? &st::mediaPlayerMenuCheck : nullptr); - const auto context = Core::MarkedTextContext{ + item->setMarkedText(title.text, QString(), Core::TextContext({ .session = &history->session(), - .customEmojiRepaint = [raw = item.get()] { raw->update(); }, .customEmojiLoopLimit = title.isStatic ? -1 : 0, - }; - item->setMarkedText(title.text, QString(), context); + })); item->setIcon(Icon(showColors ? filter : filter.withColorIndex({}))); const auto action = menu->addAction(std::move(item)); diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp index f9a05a557..be4531aec 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp @@ -441,13 +441,10 @@ void EditFilterBox( using namespace Window; return window->isGifPausedAtLeastFor(GifPauseReason::Layer); }; - name->setCustomTextContext([=](Fn repaint) { - return std::any(Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = std::move(repaint), - .customEmojiLoopLimit = value ? -1 : 0, - }); - }, [paused] { + name->setCustomTextContext(Core::TextContext({ + .session = session, + .customEmojiLoopLimit = value ? -1 : 0, + }), [paused] { return On(PowerSaving::kEmojiChat) || paused(); }, [paused] { return On(PowerSaving::kChatSpoiler) || paused(); @@ -609,10 +606,7 @@ void EditFilterBox( float64 alpha = 1.; }; const auto tag = preview->lifetime().make_state(); - tag->context.textContext = Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [] {}, - }; + tag->context.textContext = Core::TextContext({ .session = session }); preview->paintRequest() | rpl::start_with_next([=] { auto p = QPainter(preview); p.setOpacity(tag->alpha); diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_chats_list.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_chats_list.cpp index 2ed72aa25..a200bcecb 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_chats_list.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_chats_list.cpp @@ -163,10 +163,10 @@ ExceptionRow::ExceptionRow( st::defaultTextStyle, filters, kMarkupTextOptions, - Core::MarkedTextContext{ + Core::TextContext({ .session = &history->session(), - .customEmojiRepaint = repaint, - }); + .repaint = repaint, + })); } else if (peer()->isSelf()) { setCustomStatus(tr::lng_saved_forward_here(tr::now)); } diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp index 61bbd85a0..90dd083bd 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp @@ -537,13 +537,6 @@ void LinkController::addHeader(not_null container) { verticalLayout->add(std::move(icon.widget)); const auto isStatic = _filterTitle.isStatic; - const auto makeContext = [=](Fn update) { - return Core::MarkedTextContext{ - .session = &_window->session(), - .customEmojiRepaint = update, - .customEmojiLoopLimit = isStatic ? -1 : 0, - }; - }; verticalLayout->add( object_ptr>( verticalLayout, @@ -559,7 +552,10 @@ void LinkController::addHeader(not_null container) { Ui::Text::WithEntities)), st::settingsFilterDividerLabel, st::defaultPopupMenu, - makeContext)), + Core::TextContext({ + .session = &_window->session(), + .customEmojiLoopLimit = isStatic ? -1 : 0, + }))), st::filterLinkDividerLabelPadding); verticalLayout->geometryValue( diff --git a/Telegram/SourceFiles/boxes/gift_credits_box.cpp b/Telegram/SourceFiles/boxes/gift_credits_box.cpp index 80e859eb1..761b387e5 100644 --- a/Telegram/SourceFiles/boxes/gift_credits_box.cpp +++ b/Telegram/SourceFiles/boxes/gift_credits_box.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_credits.h" #include "boxes/peer_list_controllers.h" +#include "core/ui_integration.h" // TextContext. #include "data/data_peer.h" #include "data/data_session.h" #include "data/data_user.h" @@ -67,14 +68,9 @@ void GiftCreditsBox( 2.); { Ui::AddSkip(content); - const auto arrow = Ui::Text::SingleCustomEmoji( - peer->owner().customEmojiManager().registerInternalEmoji( - st::topicButtonArrow, - st::channelEarnLearnArrowMargins, - true)); auto link = tr::lng_credits_box_history_entry_gift_about_link( lt_emoji, - rpl::single(arrow), + rpl::single(Ui::Text::IconEmoji(&st::textMoreIconEmoji)), Ui::Text::RichLangValue ) | rpl::map([](TextWithEntities text) { return Ui::Text::Link( @@ -92,7 +88,7 @@ void GiftCreditsBox( lt_link, std::move(link), Ui::Text::RichLangValue), - { .session = &peer->session() }, + Core::TextContext({ .session = &peer->session() }), st::creditsBoxAbout)), st::boxRowPadding); } diff --git a/Telegram/SourceFiles/boxes/gift_premium_box.cpp b/Telegram/SourceFiles/boxes/gift_premium_box.cpp index 1d12e7f81..691821c16 100644 --- a/Telegram/SourceFiles/boxes/gift_premium_box.cpp +++ b/Telegram/SourceFiles/boxes/gift_premium_box.cpp @@ -517,13 +517,13 @@ not_null AddTableRow( not_null table, rpl::producer label, rpl::producer value, - const Fn)> &makeContext = nullptr) { + const Ui::Text::MarkedContext &context = {}) { auto widget = object_ptr( table, std::move(value), table->st().defaultValue, st::defaultPopupMenu, - std::move(makeContext)); + context); const auto result = widget.data(); AddTableRow( table, @@ -1527,12 +1527,6 @@ void AddStarGiftTable( : nullptr; const auto date = base::unixtime::parse(original.date).date(); const auto dateText = TextWithEntities{ langDayOfMonth(date) }; - const auto makeContext = [=](Fn update) { - return Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = std::move(update), - }; - }; auto label = object_ptr( table, (from @@ -1574,7 +1568,7 @@ void AddStarGiftTable( ? *st.tableValueMessage : st::giveawayGiftMessage), st::defaultPopupMenu, - makeContext); + Core::TextContext({ .session = session })); const auto showBoxLink = [=](not_null peer) { return std::make_shared([=] { show->showBox(PrepareShortInfoBox(peer, show)); @@ -1592,12 +1586,6 @@ void AddStarGiftTable( st::giveawayGiftCodeValueMargin); } } else if (!entry.description.empty()) { - const auto makeContext = [=](Fn update) { - return Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = std::move(update), - }; - }; auto label = object_ptr( table, rpl::single(entry.description), @@ -1605,7 +1593,7 @@ void AddStarGiftTable( ? *st.tableValueMessage : st::giveawayGiftMessage), st::defaultPopupMenu, - makeContext); + Core::TextContext({ .session = session })); label->setSelectable(true); table->addRow( nullptr, diff --git a/Telegram/SourceFiles/boxes/moderate_messages_box.cpp b/Telegram/SourceFiles/boxes/moderate_messages_box.cpp index 8007b9383..d278d2681 100644 --- a/Telegram/SourceFiles/boxes/moderate_messages_box.cpp +++ b/Telegram/SourceFiles/boxes/moderate_messages_box.cpp @@ -453,10 +453,7 @@ void CreateModerateMessagesBox( ) | rpl::start_with_next([=](const TextWithEntities &text) { raw->setMarkedText( Ui::Text::Link(text, u"internal:"_q), - Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [=] { raw->update(); }, - }); + Core::TextContext({ .session = session })); }, label->lifetime()); Ui::AddSkip(inner); diff --git a/Telegram/SourceFiles/boxes/passcode_box.cpp b/Telegram/SourceFiles/boxes/passcode_box.cpp index 308384e16..96d5f2d33 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.cpp +++ b/Telegram/SourceFiles/boxes/passcode_box.cpp @@ -1154,8 +1154,7 @@ RecoverBox::RecoverBox( rpl::single(Ui::Text::WrapEmailPattern(pattern)), Ui::Text::WithEntities), st::termsContent, - st::defaultPopupMenu, - [=](Fn update) { return CommonTextContext{ std::move(update) }; }) + st::defaultPopupMenu) , _closeParent(std::move(closeParent)) { _patternLabel->setAttribute(Qt::WA_TransparentForMouseEvents); if (_cloudFields.pendingResetDate != 0 || !session) { diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp index 73b3004f0..c457ce579 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_color_box.cpp @@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/background_box.h" #include "boxes/stickers_box.h" #include "chat_helpers/compose/compose_show.h" -#include "core/ui_integration.h" // Core::MarkedTextContext. +#include "core/ui_integration.h" // TextContext #include "data/stickers/data_custom_emoji.h" #include "data/stickers/data_stickers.h" #include "data/data_changes.h" @@ -165,7 +165,7 @@ private: const uint32 _level; const TextWithEntities _icon; - const Core::MarkedTextContext _context; + const Ui::Text::MarkedContext _context; Ui::Text::String _text; bool _minimal = false; @@ -466,7 +466,10 @@ LevelBadge::LevelBadge( st::settingsLevelBadgeLock, QMargins(0, st::settingsLevelBadgeLockSkip, 0, 0), false))) -, _context({ .session = session }) { +, _context(Core::TextContext({ + .session = session, + .repaint = [this] { update(); }, +})) { updateText(); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp index 38eb775f6..70ad41acb 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp @@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peer_list_controllers.h" #include "boxes/share_box.h" #include "core/application.h" -#include "core/ui_integration.h" // Core::MarkedTextContext. +#include "core/ui_integration.h" // TextContext #include "data/components/credits.h" #include "data/data_changes.h" #include "data/data_channel.h" @@ -740,10 +740,10 @@ void Controller::setupAboveJoinedWidget() { { QString::number(current.subscription.credits) }, Ui::Text::WithEntities), kMarkupTextOptions, - Core::MarkedTextContext{ + Core::TextContext({ .session = &session(), - .customEmojiRepaint = [=] { widget->update(); }, - }); + .repaint = [=] { widget->update(); }, + })); auto &lifetime = widget->lifetime(); const auto rateValue = lifetime.make_state>( session().credits().rateValue(_peer)); @@ -994,10 +994,7 @@ void Controller::rowClicked(not_null row) { lt_cost, { QString::number(data.subscription.credits) }, Ui::Text::WithEntities), - Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [=] { subtitle1->update(); }, - }); + Core::TextContext({ .session = session })); const auto subtitle2 = box->addRow( object_ptr>( box, diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index 486383f0b..6e824ac35 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -890,11 +890,10 @@ void AddBoostsUnrestrictLabels( manager->registerInternalEmoji( st::boostsMessageIcon, st::boostsMessageIconPadding)); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = session, - .customEmojiRepaint = [] {}, .customEmojiLoopLimit = 1, - }; + }); for (auto i = 0; i != kBoostsUnrestrictValues; ++i) { const auto label = Ui::CreateChild( labels, diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp index 96ed8c949..5313a2ae3 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp @@ -363,12 +363,15 @@ object_ptr AddReactionsSelector( const auto customEmojiPaused = [controller = args.controller] { return controller->isGifPausedAtLeastFor(PauseReason::Layer); }; - auto factory = [=](QStringView data, Fn update) - -> std::unique_ptr { + auto context = Core::TextContext({ + .session = session, + }); + context.customEmojiFactory = [=]( + QStringView data, + const Ui::Text::MarkedContext &context + ) -> std::unique_ptr { const auto id = Data::ParseCustomEmojiData(data); - auto result = owner->customEmojiManager().create( - data, - std::move(update)); + auto result = Ui::Text::MakeCustomEmoji(data, context); if (state->unifiedFactoryOwner->lookupReactionId(id).custom()) { return std::make_unique( std::move(result), @@ -377,12 +380,10 @@ object_ptr AddReactionsSelector( using namespace Ui::Text; return std::make_unique(std::move(result)); }; - raw->setCustomTextContext([=](Fn repaint) { - return std::any(Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = std::move(repaint), - }); - }, customEmojiPaused, customEmojiPaused, std::move(factory)); + raw->setCustomTextContext( + std::move(context), + customEmojiPaused, + customEmojiPaused); const auto callback = args.callback; const auto isCustom = [=](DocumentId id) { diff --git a/Telegram/SourceFiles/boxes/send_credits_box.cpp b/Telegram/SourceFiles/boxes/send_credits_box.cpp index 8091e7ea4..2a4e4f242 100644 --- a/Telegram/SourceFiles/boxes/send_credits_box.cpp +++ b/Telegram/SourceFiles/boxes/send_credits_box.cpp @@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_credits.h" #include "apiwrap.h" -#include "core/ui_integration.h" // Core::MarkedTextContext. +#include "core/ui_integration.h" // TextContext #include "data/components/credits.h" #include "data/data_credits.h" #include "data/data_photo.h" @@ -519,21 +519,20 @@ TextWithEntities CreditsEmojiSmall(not_null session) { not_null SetButtonMarkedLabel( not_null button, rpl::producer text, - Fn update)> context, + Text::MarkedContext context, const style::FlatLabel &st, const style::color *textFg) { const auto buttonLabel = Ui::CreateChild( button, rpl::single(QString()), st); + context.repaint = [=] { buttonLabel->update(); }; rpl::duplicate( text ) | rpl::filter([=](const TextWithEntities &text) { return !text.text.isEmpty(); }) | rpl::start_with_next([=](const TextWithEntities &text) { - buttonLabel->setMarkedText( - text, - context([=] { buttonLabel->update(); })); + buttonLabel->setMarkedText(text, context); }, buttonLabel->lifetime()); if (textFg) { buttonLabel->setTextColorOverride((*textFg)->c); @@ -562,12 +561,9 @@ not_null SetButtonMarkedLabel( not_null session, const style::FlatLabel &st, const style::color *textFg) { - return SetButtonMarkedLabel(button, text, [=](Fn update) { - return Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = update, - }; - }, st, textFg); + return SetButtonMarkedLabel(button, text, Core::TextContext({ + .session = session, + }), st, textFg); } void SendStarsForm( diff --git a/Telegram/SourceFiles/boxes/send_credits_box.h b/Telegram/SourceFiles/boxes/send_credits_box.h index e51dc39b3..6dcaef1f8 100644 --- a/Telegram/SourceFiles/boxes/send_credits_box.h +++ b/Telegram/SourceFiles/boxes/send_credits_box.h @@ -41,7 +41,7 @@ void SendCreditsBox( not_null SetButtonMarkedLabel( not_null button, rpl::producer text, - Fn update)> context, + Text::MarkedContext context, const style::FlatLabel &st, const style::color *textFg = nullptr); diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index a269f83bd..e9d04211d 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -859,10 +859,9 @@ void SendFilesBox::refreshPriceTag() { QString(), st::paidTagLabel); std::move(text) | rpl::start_with_next([=](TextWithEntities &&text) { - label->setMarkedText(text, Core::MarkedTextContext{ + label->setMarkedText(text, Core::TextContext({ .session = session, - .customEmojiRepaint = [=] { label->update(); }, - }); + })); }, label->lifetime()); label->show(); label->sizeValue() | rpl::start_with_next([=](QSize size) { diff --git a/Telegram/SourceFiles/boxes/star_gift_box.cpp b/Telegram/SourceFiles/boxes/star_gift_box.cpp index 0107b2fbc..bc15e9059 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_box.cpp @@ -231,7 +231,7 @@ auto GenerateGiftMedia( TextWithEntities text, QMargins margins = {}, const base::flat_map &links = {}, - const std::any &context = {}) { + Ui::Text::MarkedContext context = {}) { if (text.empty()) { return; } @@ -240,7 +240,7 @@ auto GenerateGiftMedia( margins, st::defaultTextStyle, links, - context)); + std::move(context))); }; const auto sticker = [=] { @@ -310,10 +310,10 @@ auto GenerateGiftMedia( auto description = data.text.empty() ? std::move(textFallback) : data.text; - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &parent->history()->session(), - .customEmojiRepaint = [parent] { parent->repaint(); }, - }; + .repaint = [parent] { parent->repaint(); }, + }); pushText( std::move(title), st::giftBoxPreviewTitlePadding, @@ -759,15 +759,11 @@ void PreviewWrap::paintEvent(QPaintEvent *e) { } auto &manager = session->data().customEmojiManager(); auto result = Text::String(); - const auto context = Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [] {}, - }; result.setMarkedText( st::semiboldTextStyle, manager.creditsEmoji().append(QString::number(price)), kMarkupTextOptions, - context); + Core::TextContext({ .session = session })); return result; } @@ -1322,12 +1318,6 @@ void AddUpgradeButton( button->toggleOn(rpl::single(false))->toggledValue( ) | rpl::start_with_next(toggled, button->lifetime()); - const auto makeContext = [session](Fn update) { - return Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = std::move(update), - }; - }; auto star = session->data().customEmojiManager().creditsEmoji(); const auto label = Ui::CreateChild( button, @@ -1339,7 +1329,7 @@ void AddUpgradeButton( Text::WithEntities), st::boxLabel, st::defaultPopupMenu, - std::move(makeContext)); + Core::TextContext({ .session = session })); label->show(); label->setAttribute(Qt::WA_TransparentForMouseEvents); button->widthValue() | rpl::start_with_next([=](int outer) { diff --git a/Telegram/SourceFiles/boxes/translate_box.cpp b/Telegram/SourceFiles/boxes/translate_box.cpp index 39380bd3e..b79a417ee 100644 --- a/Telegram/SourceFiles/boxes/translate_box.cpp +++ b/Telegram/SourceFiles/boxes/translate_box.cpp @@ -150,10 +150,7 @@ void TranslateBox( original->entity()->setAnimationsPausedCallback(animationsPaused); original->entity()->setMarkedText( text, - Core::MarkedTextContext{ - .session = &peer->session(), - .customEmojiRepaint = [=] { original->entity()->update(); }, - }); + Core::TextContext({ .session = &peer->session() })); original->setMinimalHeight(lineHeight); original->hide(anim::type::instant); @@ -221,10 +218,7 @@ void TranslateBox( const auto label = translated->entity(); label->setMarkedText( text, - Core::MarkedTextContext{ - .session = &peer->session(), - .customEmojiRepaint = [=] { label->update(); }, - }); + Core::TextContext({ .session = &peer->session() })); translated->show(anim::type::instant); loading->hide(anim::type::instant); }; diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 927f1359c..1e783b452 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -433,12 +433,9 @@ void InitMessageFieldHandlers(MessageFieldHandlersArgs &&args) { const auto session = args.session; field->setTagMimeProcessor( FieldTagMimeProcessor(session, args.allowPremiumEmoji)); - field->setCustomTextContext([=](Fn repaint) { - return std::any(Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = std::move(repaint), - }); - }, [paused] { + field->setCustomTextContext(Core::TextContext({ + .session = session + }), [paused] { return On(PowerSaving::kEmojiChat) || paused(); }, [paused] { return On(PowerSaving::kChatSpoiler) || paused(); diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index 48325cafb..83d287a16 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -109,6 +109,40 @@ const auto kBadPrefix = u"http://"_q; } // namespace +Ui::Text::MarkedContext TextContext(TextContextArgs &&args) { + using Context = Ui::Text::MarkedContext; + using Factory = Ui::Text::CustomEmojiFactory; + + const auto session = args.session; + auto simple = [session](QStringView data, const Context &context) { + return session->data().customEmojiManager().create( + data, + context.repaint); + }; + auto factory = !args.customEmojiLoopLimit + ? Factory(simple) + : (args.customEmojiLoopLimit > 0) + ? Factory([simple, loop = args.customEmojiLoopLimit]( + QStringView data, + const Context &context) { + return std::make_unique( + simple(data, context), + loop); + }) + : Factory([simple]( + QStringView data, + const Context &context) { + return std::make_unique( + simple(data, context)); + }); + args.details.session = session; + return { + .repaint = std::move(args.repaint), + .customEmojiFactory = std::move(factory), + .other = std::move(args.details), + }; +} + void UiIntegration::postponeCall(FnMut &&callable) { Sandbox::Instance().postponeCall(std::move(callable)); } @@ -149,8 +183,8 @@ bool UiIntegration::screenIsLocked() { std::shared_ptr UiIntegration::createLinkHandler( const EntityLinkData &data, - const std::any &context) { - const auto my = std::any_cast(&context); + const Ui::Text::MarkedContext &context) { + const auto my = std::any_cast(&context.other); switch (data.type) { case EntityType::Url: return (!data.data.isEmpty() @@ -167,7 +201,7 @@ std::shared_ptr UiIntegration::createLinkHandler( return std::make_shared(data.data); case EntityType::Hashtag: - using HashtagMentionType = MarkedTextContext::HashtagMentionType; + using HashtagMentionType = TextContextDetails::HashtagMentionType; if (my && my->type == HashtagMentionType::Twitter) { return std::make_shared( (u"https://twitter.com/hashtag/"_q @@ -187,7 +221,7 @@ std::shared_ptr UiIntegration::createLinkHandler( return std::make_shared(data.data); case EntityType::Mention: - using HashtagMentionType = MarkedTextContext::HashtagMentionType; + using HashtagMentionType = TextContextDetails::HashtagMentionType; if (my && my->type == HashtagMentionType::Twitter) { return std::make_shared( u"https://twitter.com/"_q + data.data.mid(1), @@ -219,7 +253,9 @@ std::shared_ptr UiIntegration::createLinkHandler( case EntityType::Pre: return std::make_shared(data.text, data.type); case EntityType::Phone: - return std::make_shared(my->session, data.text); + return my->session + ? std::make_shared(my->session, data.text) + : nullptr; } return Integration::createLinkHandler(data, context); } @@ -273,39 +309,6 @@ bool UiIntegration::copyPreOnClick(const QVariant &context) { return true; } -std::unique_ptr UiIntegration::createCustomEmoji( - QStringView data, - const std::any &context) { - if (auto simple = Ui::Text::TryMakeSimpleEmoji(data)) { - return simple; - } - const auto my = std::any_cast(&context); - if (!my || !my->session) { - return nullptr; - } - auto result = my->session->data().customEmojiManager().create( - data, - my->customEmojiRepaint); - if (my->customEmojiLoopLimit > 0) { - return std::make_unique( - std::move(result), - my->customEmojiLoopLimit); - } else if (my->customEmojiLoopLimit) { - return std::make_unique( - std::move(result)); - } - return result; -} - -Fn UiIntegration::createSpoilerRepaint(const std::any &context) { - const auto my = std::any_cast(&context); - if (my) { - return my->customEmojiRepaint; - } - const auto common = std::any_cast(&context); - return common ? common->repaint : nullptr; -} - rpl::producer<> UiIntegration::forcePopupMenuHideRequests() { return Core::App().passcodeLockChanges() | rpl::to_empty; } diff --git a/Telegram/SourceFiles/core/ui_integration.h b/Telegram/SourceFiles/core/ui_integration.h index 330d7a84c..fcb9db5ee 100644 --- a/Telegram/SourceFiles/core/ui_integration.h +++ b/Telegram/SourceFiles/core/ui_integration.h @@ -19,7 +19,7 @@ class ElementDelegate; namespace Core { -struct MarkedTextContext { +struct TextContextDetails { enum class HashtagMentionType : uchar { Telegram, Twitter, @@ -28,9 +28,15 @@ struct MarkedTextContext { Main::Session *session = nullptr; HashtagMentionType type = HashtagMentionType::Telegram; - Fn customEmojiRepaint; +}; + +struct TextContextArgs { + not_null session; + TextContextDetails details; + Fn repaint; int customEmojiLoopLimit = 0; }; +[[nodiscard]] Ui::Text::MarkedContext TextContext(TextContextArgs &&args); class UiIntegration final : public Ui::Integration { public: @@ -49,7 +55,7 @@ public: std::shared_ptr createLinkHandler( const EntityLinkData &data, - const std::any &context) override; + const Ui::Text::MarkedContext &context) override; bool handleUrlClick( const QString &url, const QVariant &context) override; @@ -57,10 +63,6 @@ public: rpl::producer<> forcePopupMenuHideRequests() override; const Ui::Emoji::One *defaultEmojiVariant( const Ui::Emoji::One *emoji) override; - std::unique_ptr createCustomEmoji( - QStringView data, - const std::any &context) override; - Fn createSpoilerRepaint(const std::any &context) override; QString phraseContextCopyText() override; QString phraseContextCopyEmail() override; diff --git a/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp b/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp index f541fda01..eb34f30df 100644 --- a/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp +++ b/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp @@ -519,8 +519,8 @@ std::unique_ptr CustomEmojiManager::create( Ui::Text::CustomEmojiFactory CustomEmojiManager::factory( SizeTag tag, int sizeOverride) { - return [=](QStringView data, Fn update) { - return create(data, std::move(update), tag, sizeOverride); + return [=](QStringView data, const Ui::Text::MarkedContext &context) { + return create(data, context.repaint, tag, sizeOverride); }; } @@ -1145,8 +1145,9 @@ void InsertCustomEmoji( Ui::Text::CustomEmojiFactory ReactedMenuFactory( not_null session) { return [owner = &session->data()]( - QStringView data, - Fn repaint) -> std::unique_ptr { + QStringView data, + const Ui::Text::MarkedContext &context + ) -> std::unique_ptr { const auto prefix = u"default:"_q; if (data.startsWith(prefix)) { const auto &list = owner->reactions().list( @@ -1166,13 +1167,13 @@ Ui::Text::CustomEmojiFactory ReactedMenuFactory( std::make_unique( owner->customEmojiManager().create( document, - std::move(repaint), + context.repaint, tag, size), QPoint(skip, skip))); } } - return owner->customEmojiManager().create(data, std::move(repaint)); + return owner->customEmojiManager().create(data, context.repaint); }; } diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 54ea9eb48..42e67637b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -4308,10 +4308,7 @@ QImage *InnerWidget::cacheChatsFilterTag( const auto color = Ui::EmptyUserpic::UserpicColor(colorIndex).color2; entry.context.color = color->c; entry.context.active = active; - entry.context.textContext = Core::MarkedTextContext{ - .session = &session(), - .customEmojiRepaint = [] {}, - }; + entry.context.textContext = Core::TextContext({ .session = &session() }); entry.frame = Ui::ChatsFilterTag(roundedText, entry.context); return &entry.frame; } diff --git a/Telegram/SourceFiles/dialogs/dialogs_search_tags.cpp b/Telegram/SourceFiles/dialogs/dialogs_search_tags.cpp index c7e85c94e..6b105f094 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_search_tags.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_search_tags.cpp @@ -60,11 +60,10 @@ namespace { st::dialogsSearchTagArrow, st::dialogsSearchTagArrowPadding)); auto result = Ui::Text::String(); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &owner->session(), - .customEmojiRepaint = [] {}, .customEmojiLoopLimit = 1, - }; + }); const auto attempt = [&](const auto &phrase) { result.setMarkedText( st::dialogsSearchTagPromo, diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp index 729224305..39a8e3826 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp @@ -580,10 +580,10 @@ void PaintRow( {}, true))).append(std::move(draftText)); } - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &thread->session(), - .customEmojiRepaint = customEmojiRepaint, - }; + .repaint = customEmojiRepaint, + }); cache.setMarkedText( st::dialogsTextStyle, std::move(draftText), diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp index caed2612e..51fb657cd 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp @@ -174,11 +174,11 @@ void MessageView::prepare( : nullptr; const auto hasImages = !preview.images.empty(); const auto history = item->history(); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &history->session(), - .customEmojiRepaint = customEmojiRepaint, + .repaint = customEmojiRepaint, .customEmojiLoopLimit = kEmojiLoopCount, - }; + }); const auto senderTill = (preview.arrowInTextPosition > 0) ? preview.arrowInTextPosition : preview.imagesInTextPosition; diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp index cd312fd85..82fc64a7a 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp @@ -63,11 +63,11 @@ void TopicsView::prepare(MsgId frontRootId, Fn customEmojiRepaint) { && title.version == topic->titleVersion()) { continue; } - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &topic->session(), - .customEmojiRepaint = customEmojiRepaint, + .repaint = customEmojiRepaint, .customEmojiLoopLimit = kIconLoopCount, - }; + }); auto topicTitle = topic->titleWithIcon(); title.topicRootId = rootId; title.version = topic->titleVersion(); diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index a62fa7b48..129eed4de 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1169,12 +1169,6 @@ void History::applyServiceChanges( } if (paid) { // Toast on a current active window. - const auto context = [=](not_null toast) { - return Core::MarkedTextContext{ - .session = &session(), - .customEmojiRepaint = [=] { toast->update(); }, - }; - }; Ui::Toast::Show({ .text = tr::lng_payments_success( tr::now, @@ -1185,7 +1179,9 @@ void History::applyServiceChanges( lt_title, Ui::Text::Bold(paid->title), Ui::Text::WithEntities), - .textContext = context, + .textContext = Core::TextContext({ + .session = &session(), + }), }); } } diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index d71e861f5..9b3f23fb1 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -205,7 +205,9 @@ void HistoryMessageForwarded::create( const HistoryMessageVia *via, not_null item) const { auto phrase = TextWithEntities(); - auto context = Core::MarkedTextContext{}; + auto context = Core::TextContext({ + .session = &item->history()->session(), + }); const auto fromChannel = originalSender && originalSender->isChannel() && !originalSender->isMegagroup(); @@ -215,8 +217,7 @@ void HistoryMessageForwarded::create( : originalHiddenSenderInfo->name) }; if (const auto copy = originalSender) { - context.session = ©->owner().session(); - context.customEmojiRepaint = [=] { + context.repaint = [=] { // It is important to capture here originalSender by value, // not capture the HistoryMessageForwarded* and read the // originalSender field, because the components themselves @@ -225,7 +226,7 @@ void HistoryMessageForwarded::create( copy->owner().requestItemRepaint(item); }; phrase = Ui::Text::SingleCustomEmoji( - context.session->data().customEmojiManager().peerUserpicEmojiData( + copy->owner().customEmojiManager().peerUserpicEmojiData( copy, st::fwdTextUserpicPadding)); } @@ -755,10 +756,10 @@ ReplyKeyboard::ReplyKeyboard( _st->textStyle(), TextUtilities::SingleLine(textWithEntities), kMarkupTextOptions, - Core::MarkedTextContext{ + Core::TextContext({ .session = &item->history()->owner().session(), - .customEmojiRepaint = [=] { _st->repaint(item); }, - }); + .repaint = [=] { _st->repaint(item); }, + })); } else { button.text.setText( _st->textStyle(), diff --git a/Telegram/SourceFiles/history/history_view_top_toast.cpp b/Telegram/SourceFiles/history/history_view_top_toast.cpp index 7736f971d..a68061b9f 100644 --- a/Telegram/SourceFiles/history/history_view_top_toast.cpp +++ b/Telegram/SourceFiles/history/history_view_top_toast.cpp @@ -31,16 +31,10 @@ void InfoTooltip::show( not_null session, const TextWithEntities &text, Fn hiddenCallback) { - const auto context = [=](not_null toast) { - return Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [=] { toast->update(); }, - }; - }; hide(anim::type::normal); _topToast = Ui::Toast::Show(parent, Ui::Toast::Config{ .text = text, - .textContext = context, + .textContext = Core::TextContext({ .session = session }), .st = &st::historyInfoToast, .attach = RectPart::Top, .duration = CountToastDuration(text), diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 76353c79f..ca5be0a39 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -8829,10 +8829,10 @@ void HistoryWidget::messageDataReceived( } void HistoryWidget::updateReplyEditText(not_null item) { - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &session(), - .customEmojiRepaint = [=] { updateField(); }, - }; + .repaint = [=] { updateField(); }, + }); _replyEditMsgText.setMarkedText( st::defaultTextStyle, ((_editMsgId || _replyTo.quote.empty()) @@ -8918,11 +8918,10 @@ void HistoryWidget::updateReplyToName() { } else if (!_replyEditMsg && (_replyTo || !_kbReplyTo)) { return; } - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &_history->session(), - .customEmojiRepaint = [] {}, .customEmojiLoopLimit = 1, - }; + }); const auto to = _replyEditMsg ? _replyEditMsg : _kbReplyTo; const auto replyToQuote = _replyTo && !_replyTo.quote.empty(); _replyToName.setMarkedText( diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 0d277b016..a0b676e44 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -428,10 +428,10 @@ void FieldHeader::init() { void FieldHeader::updateShownMessageText() { Expects(_shownMessage != nullptr); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &_data->session(), - .customEmojiRepaint = [=] { customEmojiRepaint(); }, - }; + .repaint = [=] { customEmojiRepaint(); }, + }); const auto reply = replyingToMessage(); _shownMessageText.setMarkedText( st::messageTextStyle, @@ -464,11 +464,10 @@ void FieldHeader::setShownMessage(HistoryItem *item) { tr::lng_edit_message(tr::now), Ui::NameTextOptions()); } else if (item) { - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &_history->session(), - .customEmojiRepaint = [] {}, .customEmojiLoopLimit = 1, - }; + }); const auto replyTo = _replyTo.current(); const auto quote = replyTo && !replyTo.quote.empty(); _shownMessageName.setMarkedText( diff --git a/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp b/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp index 022b124ab..7502a93c8 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp @@ -190,10 +190,10 @@ void ForwardPanel::updateTexts() { } } _from.setText(st::msgNameStyle, from, Ui::NameTextOptions()); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &_to->session(), - .customEmojiRepaint = _repaint, - }; + .repaint = _repaint, + }); _text.setMarkedText( st::defaultTextStyle, text, diff --git a/Telegram/SourceFiles/history/view/history_view_about_view.cpp b/Telegram/SourceFiles/history/view/history_view_about_view.cpp index f97e94355..ca6eb9a83 100644 --- a/Telegram/SourceFiles/history/view/history_view_about_view.cpp +++ b/Telegram/SourceFiles/history/view/history_view_about_view.cpp @@ -234,10 +234,10 @@ auto GenerateNewPeerInfo( fadedFg, normalFg)); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &parent->history()->session(), - .customEmojiRepaint = [parent] { parent->repaint(); }, - }; + .repaint = [parent] { parent->repaint(); }, + }); const auto details = user->botVerifyDetails(); const auto text = details ? Data::SingleCustomEmoji( diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index 60e1b4e86..71e711ad0 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -163,7 +163,7 @@ public: void showState( State state, TextWithEntities status, - Fn customEmojiRepaint)> context); + Ui::Text::MarkedContext context); [[nodiscard]] rpl::producer<> unarchiveClicks() const; [[nodiscard]] rpl::producer<> addClicks() const; @@ -272,7 +272,7 @@ ContactStatus::Bar::Bar( void ContactStatus::Bar::showState( State state, TextWithEntities status, - Fn customEmojiRepaint)> context) { + Ui::Text::MarkedContext context) { using Type = State::Type; const auto type = state.type; _add->setVisible(type == Type::AddOrBlock || type == Type::Add); @@ -294,6 +294,7 @@ void ContactStatus::Bar::showState( _emojiStatusShadow->setVisible( has && (type == Type::AddOrBlock || type == Type::UnarchiveOrBlock)); if (has) { + context.repaint = [=] { emojiStatusRepaint(); }; _emojiStatusInfo->entity()->setMarkedText( tr::lng_new_contact_about_status( tr::now, @@ -303,7 +304,7 @@ void ContactStatus::Bar::showState( Ui::Text::Link( tr::lng_new_contact_about_status_link(tr::now)), Ui::Text::WithEntities), - context([=] { emojiStatusRepaint(); })); + context); _emojiStatusInfo->entity()->overrideLinkClickHandler([=] { _emojiStatusClicks.fire({}); }); @@ -628,12 +629,7 @@ void ContactStatus::setupState(not_null peer, bool showInForum) { peer->session().api().requestPeerSettings(peer); } - _context = [=](Fn customEmojiRepaint) { - return Core::MarkedTextContext{ - .session = &peer->session(), - .customEmojiRepaint = customEmojiRepaint, - }; - }; + _context = Core::TextContext({ .session = &peer->session() }); _inner->showState({}, {}, _context); const auto channel = peer->asChannel(); rpl::combine( diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.h b/Telegram/SourceFiles/history/view/history_view_contact_status.h index 56be475a8..0c540a36c 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.h +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.h @@ -117,7 +117,7 @@ private: const not_null _controller; State _state; TextWithEntities _status; - Fn customEmojiRepaint)> _context; + Ui::Text::MarkedContext _context; QPointer _inner; SlidingBar _bar; bool _hiddenByForum = false; diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 44e9e658f..cd8139c9e 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -1171,10 +1171,10 @@ void Element::validateText() { void Element::setTextWithLinks( const TextWithEntities &text, const std::vector &links) { - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &history()->session(), - .customEmojiRepaint = [=] { customEmojiRepaint(); }, - }; + .repaint = [=] { customEmojiRepaint(); }, + }); if (_flags & Flag::ServiceMessage) { const auto &options = Ui::ItemTextServiceOptions(); _text.setMarkedText(st::serviceTextStyle, text, options, context); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index b9a4b0a1e..5e8d1c05b 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -550,11 +550,10 @@ void Message::refreshRightBadge() { if (badge.empty()) { _rightBadge.clear(); } else { - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &item->history()->session(), - .customEmojiRepaint = [] {}, .customEmojiLoopLimit = 1, - }; + }); _rightBadge.setMarkedText( st::defaultTextStyle, badge, @@ -1049,11 +1048,11 @@ void Message::refreshTopicButton() { _topicButton->link = MakeTopicButtonLink(topic, jumpToId); if (_topicButton->nameVersion != topic->titleVersion()) { _topicButton->nameVersion = topic->titleVersion(); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &history()->session(), - .customEmojiRepaint = [=] { customEmojiRepaint(); }, + .repaint = [=] { customEmojiRepaint(); }, .customEmojiLoopLimit = 1, - }; + }); _topicButton->name.setMarkedText( st::fwdTextStyle, topic->titleWithIcon(), diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp index eebbb1848..9564b94c5 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp @@ -29,10 +29,10 @@ namespace { Fn repaint) { return Ui::MessageBarContent{ .text = item->inReplyText(), - .context = Core::MarkedTextContext{ + .context = Core::TextContext({ .session = &item->history()->session(), - .customEmojiRepaint = std::move(repaint), - }, + .repaint = std::move(repaint), + }), }; } diff --git a/Telegram/SourceFiles/history/view/history_view_reply.cpp b/Telegram/SourceFiles/history/view/history_view_reply.cpp index d2043b027..3d29c806f 100644 --- a/Telegram/SourceFiles/history/view/history_view_reply.cpp +++ b/Telegram/SourceFiles/history/view/history_view_reply.cpp @@ -244,10 +244,10 @@ void Reply::update( }).text : TextWithEntities(); const auto repaint = [=] { item->customEmojiRepaint(); }; - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &view->history()->session(), - .customEmojiRepaint = repaint, - }; + .repaint = repaint, + }); _text.setMarkedText( st::defaultTextStyle, text, @@ -463,11 +463,10 @@ void Reply::updateName( if (!viaBotUsername.isEmpty()) { nameFull.append(u" @"_q).append(viaBotUsername); } - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &history->session(), - .customEmojiRepaint = [] {}, .customEmojiLoopLimit = 1, - }; + }); _name.setMarkedText( st::fwdTextStyle, nameFull, diff --git a/Telegram/SourceFiles/history/view/media/history_view_game.cpp b/Telegram/SourceFiles/history/view/media/history_view_game.cpp index 5bd71f4e4..cd3950bbe 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_game.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_game.cpp @@ -38,10 +38,10 @@ Game::Game( , _title(st::msgMinWidth - _st.padding.left() - _st.padding.right()) , _description(st::msgMinWidth - _st.padding.left() - _st.padding.right()) { if (!consumed.text.isEmpty()) { - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &history()->session(), - .customEmojiRepaint = [=] { _parent->customEmojiRepaint(); }, - }; + .repaint = [=] { _parent->customEmojiRepaint(); }, + }); _description.setMarkedText( st::webPageDescriptionStyle, consumed, @@ -503,10 +503,10 @@ void Game::parentTextUpdated() { if (const auto media = _parent->data()->media()) { const auto consumed = media->consumedMessageText(); if (!consumed.text.isEmpty()) { - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &history()->session(), - .customEmojiRepaint = [=] { _parent->customEmojiRepaint(); }, - }; + .repaint = [=] { _parent->customEmojiRepaint(); }, + }); _description.setMarkedText( st::webPageDescriptionStyle, consumed, diff --git a/Telegram/SourceFiles/history/view/media/history_view_media.cpp b/Telegram/SourceFiles/history/view/media/history_view_media.cpp index d41c93feb..1d3554972 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media.cpp @@ -244,10 +244,11 @@ void Media::drawPurchasedTag( const auto session = &item->history()->session(); auto text = Ui::Text::Colorized(Ui::CreditsEmojiSmall(session)); text.append(Lang::FormatCountDecimal(amount)); - purchased->text.setMarkedText(st::defaultTextStyle, text, kMarkupTextOptions, Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [] {}, - }); + purchased->text.setMarkedText( + st::defaultTextStyle, + text, + kMarkupTextOptions, + Core::TextContext({ .session = session })); } const auto st = context.st; @@ -413,10 +414,7 @@ void Media::drawSpoilerTag( price, Ui::Text::WithEntities), kMarkupTextOptions, - Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [] {}, - }); + Core::TextContext({ .session = session })); } const auto width = iconSkip + text.maxWidth(); const auto inner = QRect(0, 0, width, text.minHeight()); @@ -541,10 +539,10 @@ Ui::Text::String Media::createCaption(not_null item) const { - st::msgPadding.left() - st::msgPadding.right(); auto result = Ui::Text::String(minResizeWidth); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &history()->session(), - .customEmojiRepaint = [=] { _parent->customEmojiRepaint(); }, - }; + .repaint = [=] { _parent->customEmojiRepaint(); }, + }); result.setMarkedText( st::messageTextStyle, item->translatedTextWithLocalEntities(), diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_generic.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_generic.cpp index f2c970e40..3b70d6282 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_generic.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_generic.cpp @@ -236,7 +236,7 @@ MediaGenericTextPart::MediaGenericTextPart( QMargins margins, const style::TextStyle &st, const base::flat_map &links, - const std::any &context) + const Ui::Text::MarkedContext &context) : _text(st::msgMinWidth) , _margins(margins) { _text.setMarkedText( diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_generic.h b/Telegram/SourceFiles/history/view/media/history_view_media_generic.h index 437c665a4..0fd011914 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_generic.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media_generic.h @@ -141,7 +141,7 @@ public: QMargins margins, const style::TextStyle &st = st::defaultTextStyle, const base::flat_map &links = {}, - const std::any &context = {}); + const Ui::Text::MarkedContext &context = {}); void draw( Painter &p, diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index 72b1df9ba..bc9386a1d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/media/history_view_poll.h" -#include "core/ui_integration.h" // Core::MarkedTextContext. +#include "core/ui_integration.h" // TextContext #include "lang/lang_keys.h" #include "history/history.h" #include "history/history_item.h" @@ -158,7 +158,7 @@ struct Poll::Answer { void fillData( not_null poll, const PollAnswer &original, - Core::MarkedTextContext context); + Ui::Text::MarkedContext context); Ui::Text::String text; QByteArray option; @@ -206,7 +206,7 @@ Poll::Answer::Answer() : text(st::msgMinWidth / 2) { void Poll::Answer::fillData( not_null poll, const PollAnswer &original, - Core::MarkedTextContext context) { + Ui::Text::MarkedContext context) { chosen = original.chosen; correct = poll->quiz() ? original.correct : chosen; if (!text.isEmpty() && text.toTextWithEntities() == original.text) { @@ -396,11 +396,11 @@ void Poll::updateTexts() { st::historyPollQuestionStyle, _poll->question, options, - Core::MarkedTextContext{ + Core::TextContext({ .session = &_poll->session(), - .customEmojiRepaint = [=] { repaint(); }, + .repaint = [=] { repaint(); }, .customEmojiLoopLimit = 2, - }); + })); } if (_flags != _poll->flags() || _subtitle.isEmpty()) { using Flag = PollData::Flag; @@ -525,11 +525,11 @@ void Poll::updateRecentVoters() { } void Poll::updateAnswers() { - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &_poll->session(), - .customEmojiRepaint = [=] { repaint(); }, + .repaint = [=] { repaint(); }, .customEmojiLoopLimit = 2, - }; + }); const auto changed = !ranges::equal( _answers, _poll->answers, diff --git a/Telegram/SourceFiles/history/view/media/history_view_service_box.cpp b/Telegram/SourceFiles/history/view/media/history_view_service_box.cpp index 08444c490..3cf6d7b77 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_service_box.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_service_box.cpp @@ -47,10 +47,10 @@ ServiceBox::ServiceBox( _content->title(), kMarkupTextOptions, _maxWidth, - Core::MarkedTextContext{ + Core::TextContext({ .session = &parent->history()->session(), - .customEmojiRepaint = [parent] { parent->customEmojiRepaint(); }, - }) + .repaint = [parent] { parent->customEmojiRepaint(); }, + })) , _subtitle( st::premiumPreviewAbout.style, Ui::Text::Filtered( @@ -65,10 +65,10 @@ ServiceBox::ServiceBox( }), kMarkupTextOptions, _maxWidth, - Core::MarkedTextContext{ + Core::TextContext({ .session = &parent->history()->session(), - .customEmojiRepaint = [parent] { parent->customEmojiRepaint(); }, - }) + .repaint = [parent] { parent->customEmojiRepaint(); }, + })) , _size( _content->width(), (st::msgServiceGiftBoxTopSkip diff --git a/Telegram/SourceFiles/history/view/media/history_view_unique_gift.cpp b/Telegram/SourceFiles/history/view/media/history_view_unique_gift.cpp index 015ef507a..287fbc9f1 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_unique_gift.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_unique_gift.cpp @@ -441,7 +441,7 @@ TextPartColored::TextPartColored( Fn color, const style::TextStyle &st, const base::flat_map &links, - const std::any &context) + const Ui::Text::MarkedContext &context) : MediaGenericTextPart(text, margins, st, links, context) , _color(std::move(color)) { } @@ -458,7 +458,7 @@ AttributeTable::AttributeTable( QMargins margins, Fn labelColor, Fn valueColor, - const std::any &context) + const Ui::Text::MarkedContext &context) : _margins(margins) , _labelColor(std::move(labelColor)) , _valueColor(std::move(valueColor)) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_unique_gift.h b/Telegram/SourceFiles/history/view/media/history_view_unique_gift.h index 269065076..3110a618e 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_unique_gift.h +++ b/Telegram/SourceFiles/history/view/media/history_view_unique_gift.h @@ -66,7 +66,7 @@ public: Fn color, const style::TextStyle &st = st::defaultTextStyle, const base::flat_map &links = {}, - const std::any &context = {}); + const Ui::Text::MarkedContext &context = {}); private: void setupPen( @@ -90,7 +90,7 @@ public: QMargins margins, Fn labelColor, Fn valueColor, - const std::any &context = {}); + const Ui::Text::MarkedContext &context = {}); void draw( Painter &p, diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp index b0ab08952..160962ee5 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp @@ -379,11 +379,10 @@ QSize WebPage::countOptimalSize() { // Detect _openButtonWidth before counting paddings. _openButton = Ui::Text::String(); if (HasButton(_data)) { - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &_data->session(), - .customEmojiRepaint = [] {}, .customEmojiLoopLimit = 1, - }; + }); _openButton.setMarkedText( st::semiboldTextStyle, PageToPhrase(_data), @@ -539,16 +538,18 @@ QSize WebPage::countOptimalSize() { _description = Ui::Text::String(st::minPhotoSize - rect::m::sum::h(padding)); } - using MarkedTextContext = Core::MarkedTextContext; - auto context = MarkedTextContext{ + using Type = Core::TextContextDetails::HashtagMentionType; + auto context = Core::TextContext({ .session = &history()->session(), - .customEmojiRepaint = [=] { _parent->customEmojiRepaint(); }, - }; - if (_data->siteName == u"Twitter"_q) { - context.type = MarkedTextContext::HashtagMentionType::Twitter; - } else if (_data->siteName == u"Instagram"_q) { - context.type = MarkedTextContext::HashtagMentionType::Instagram; - } + .details = { + .type = ((_data->siteName == u"Twitter"_q) + ? Type::Twitter + : (_data->siteName == u"Instagram"_q) + ? Type::Instagram + : Type::Telegram), + }, + .repaint = [=] { _parent->customEmojiRepaint(); }, + }); _description.setMarkedText( st::webPageDescriptionStyle, text, diff --git a/Telegram/SourceFiles/history/view/reactions/history_view_reactions_list.cpp b/Telegram/SourceFiles/history/view/reactions/history_view_reactions_list.cpp index 209e73e3c..90c6d52fa 100644 --- a/Telegram/SourceFiles/history/view/reactions/history_view_reactions_list.cpp +++ b/Telegram/SourceFiles/history/view/reactions/history_view_reactions_list.cpp @@ -154,7 +154,7 @@ Row::Row( : PeerListRow(peer, id) , _custom(reactionEntityData.isEmpty() ? nullptr - : factory(reactionEntityData, [=] { repaint(this); })) + : factory(reactionEntityData, { .repaint = [=] { repaint(this); } })) , _paused(std::move(paused)) { } diff --git a/Telegram/SourceFiles/history/view/reactions/history_view_reactions_tabs.cpp b/Telegram/SourceFiles/history/view/reactions/history_view_reactions_tabs.cpp index f3b23804f..df06ba49f 100644 --- a/Telegram/SourceFiles/history/view/reactions/history_view_reactions_tabs.cpp +++ b/Telegram/SourceFiles/history/view/reactions/history_view_reactions_tabs.cpp @@ -58,7 +58,7 @@ not_null CreateTab( ? nullptr : factory( Data::ReactionEntityData(reaction), - [=] { result->update(); }); + { .repaint = [=] { result->update(); } }); result->paintRequest( ) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp index acc7fa153..a088bc958 100644 --- a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp +++ b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp @@ -600,12 +600,6 @@ object_ptr JoinStarRefBox( if (const auto average = program.revenuePerUser) { const auto layout = box->verticalLayout(); const auto session = &initialRecipient->session(); - const auto makeContext = [session](Fn update) { - return Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = std::move(update), - }; - }; auto text = Ui::Text::Colorized(Ui::CreditsEmoji(session)); text.append(Lang::FormatStarsAmountRounded(average)); layout->add( @@ -618,7 +612,7 @@ object_ptr JoinStarRefBox( Ui::Text::WithEntities), st::starrefRevenueText, st::defaultPopupMenu, - makeContext), + Core::TextContext({ .session = session })), st::boxRowPadding); Ui::AddSkip(layout, st::defaultVerticalListSkip); } diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp index b39200c7e..4b319c310 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_list.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peers/edit_peer_color_box.h" // AddLevelBadge. #include "chat_helpers/stickers_emoji_pack.h" #include "core/application.h" +#include "core/ui_integration.h" // TextContext. #include "data/components/credits.h" #include "data/data_channel.h" #include "data/data_premium_limits.h" @@ -402,12 +403,6 @@ void InnerWidget::fill() { const auto session = &_peer->session(); const auto withdrawalEnabled = WithdrawalEnabled(session); - const auto makeContext = [=](not_null l) { - return Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [=] { l->update(); }, - }; - }; const auto addEmojiToMajor = [=]( not_null label, rpl::producer value, @@ -433,7 +428,7 @@ void InnerWidget::fill() { ) | rpl::start_with_next([=](EarnInt v) { label->setMarkedText( base::duplicate(prepended).append(icon).append(MajorPart(v)), - makeContext(label)); + Core::TextContext({ .session = session })); }, label->lifetime()); }; @@ -445,11 +440,7 @@ void InnerWidget::fill() { st::channelEarnCurrencyLearnMargins, false)); - const auto arrow = Ui::Text::SingleCustomEmoji( - session->data().customEmojiManager().registerInternalEmoji( - st::topicButtonArrow, - st::channelEarnLearnArrowMargins, - true)); + const auto arrow = Ui::Text::IconEmoji(&st::textMoreIconEmoji); const auto addAboutWithLearn = [&](const tr::phrase &text) { auto label = Ui::CreateLabelWithCustomEmoji( container, @@ -463,7 +454,7 @@ void InnerWidget::fill() { return Ui::Text::Link(std::move(text), 1); }), Ui::Text::RichLangValue), - { .session = session }, + Core::TextContext({ .session = session }), st::boxDividerLabel); label->setLink(1, std::make_shared([=] { _show->showBox(Box([=](not_null box) { @@ -580,7 +571,7 @@ void InnerWidget::fill() { Ui::Text::Link(bigCurrencyIcon, 1)), Ui::Text::RichLangValue ), - { .session = session }, + Core::TextContext({ .session = session }), st::boxTitle)))->entity(); const auto diamonds = l->lifetime().make_state(0); l->setLink(1, std::make_shared([=] { @@ -610,7 +601,7 @@ void InnerWidget::fill() { }), Ui::Text::RichLangValue ), - { .session = session }, + Core::TextContext({ .session = session }), st::channelEarnLearnDescription)); label->resizeToWidth(box->width() - rect::m::sum::h(st::boxRowPadding)); @@ -1522,4 +1513,3 @@ not_null InnerWidget::peer() const { } } // namespace Info::ChannelEarn - diff --git a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp index 45d424fc0..803e7c433 100644 --- a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp +++ b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp @@ -573,11 +573,8 @@ TextWithEntities Delegate::ministar() { return owner->customEmojiManager().ministarEmoji({ 0, top, 0, 0 }); } -std::any Delegate::textContext() { - return Core::MarkedTextContext{ - .session = &_window->session(), - .customEmojiRepaint = [] {}, - }; +Ui::Text::MarkedContext Delegate::textContext() { + return Core::TextContext({ .session = &_window->session() }); } QSize Delegate::buttonSize() { diff --git a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.h b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.h index ddd800b3d..0d93a8bf2 100644 --- a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.h +++ b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.h @@ -105,7 +105,7 @@ class GiftButtonDelegate { public: [[nodiscard]] virtual TextWithEntities star() = 0; [[nodiscard]] virtual TextWithEntities ministar() = 0; - [[nodiscard]] virtual std::any textContext() = 0; + [[nodiscard]] virtual Ui::Text::MarkedContext textContext() = 0; [[nodiscard]] virtual QSize buttonSize() = 0; [[nodiscard]] virtual QMargins buttonExtend() = 0; [[nodiscard]] virtual auto buttonPatternEmoji( @@ -181,7 +181,7 @@ public: TextWithEntities star() override; TextWithEntities ministar() override; - std::any textContext() override; + Ui::Text::MarkedContext textContext() override; QSize buttonSize() override; QMargins buttonExtend() override; auto buttonPatternEmoji( diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index b313aee0e..5f1f66b78 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -895,10 +895,10 @@ rpl::producer AddCurrencyAction( .append(QChar(' ')) .append(Info::ChannelEarn::MajorPart(balance)) .append(Info::ChannelEarn::MinorPart(balance)), - Core::MarkedTextContext{ + Core::TextContext({ .session = &user->session(), - .customEmojiRepaint = [=] { name->update(); }, - }); + .repaint = [=] { name->update(); }, + })); name->resizeToNaturalWidth(available); name->moveToRight(st::settingsButtonRightSkip, st.padding.top()); }, name->lifetime()); @@ -968,10 +968,10 @@ rpl::producer AddCreditsAction( base::duplicate(icon) .append(QChar(' ')) .append(Lang::FormatStarsAmountDecimal(balance)), - Core::MarkedTextContext{ + Core::TextContext({ .session = &user->session(), - .customEmojiRepaint = [=] { name->update(); }, - }); + .repaint = [=] { name->update(); }, + })); name->resizeToNaturalWidth(available); name->moveToRight(st::settingsButtonRightSkip, st.padding.top()); }, name->lifetime()); diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp index e08bc563e..6a5e27cf0 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp @@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peer_list_controllers.h" #include "boxes/peer_list_widgets.h" #include "chat_helpers/stickers_gift_box_pack.h" -#include "core/ui_integration.h" // Core::MarkedTextContext. +#include "core/ui_integration.h" // TextContext #include "data/data_channel.h" #include "data/data_credits.h" #include "data/data_session.h" @@ -747,9 +747,10 @@ rpl::producer BoostsController::totalBoostsValue() const { class CreditsRow final : public PeerListRow { public: struct Descriptor final { + not_null session; Data::CreditsHistoryEntry entry; Data::SubscriptionEntry subscription; - Core::MarkedTextContext context; + Ui::Text::MarkedContext context; int rowHeight = 0; Fn)> updateCallback; }; @@ -790,9 +791,10 @@ public: private: void init(); + const not_null _session; const Data::CreditsHistoryEntry _entry; const Data::SubscriptionEntry _subscription; - const Core::MarkedTextContext _context; + const Ui::Text::MarkedContext _context; const int _rowHeight; PaintRoundImageCallback _paintUserpicCallback; @@ -812,6 +814,7 @@ CreditsRow::CreditsRow( not_null peer, const Descriptor &descriptor) : PeerListRow(peer, UniqueRowIdFromEntry(descriptor.entry)) +, _session(descriptor.session) , _entry(descriptor.entry) , _subscription(descriptor.subscription) , _context(descriptor.context) @@ -837,6 +840,7 @@ CreditsRow::CreditsRow( CreditsRow::CreditsRow(const Descriptor &descriptor) : PeerListRow(UniqueRowIdFromEntry(descriptor.entry)) +, _session(descriptor.session) , _entry(descriptor.entry) , _subscription(descriptor.subscription) , _context(descriptor.context) @@ -902,19 +906,19 @@ void CreditsRow::init() { : _subscription.photoId; if (descriptionPhotoId) { _descriptionThumbnail = Ui::MakePhotoThumbnail( - _context.session->data().photo(descriptionPhotoId), + _session->data().photo(descriptionPhotoId), {}); _descriptionThumbnail->subscribeToUpdates([this] { const auto thumbnailSide = st::defaultTextStyle.font->height; _descriptionThumbnailCache = Images::Round( _descriptionThumbnail->image(thumbnailSide), ImageRoundRadius::Large); - if (_context.customEmojiRepaint) { - _context.customEmojiRepaint(); + if (_context.repaint) { + _context.repaint(); } }); } - auto &manager = _context.session->data().customEmojiManager(); + auto &manager = _session->data().customEmojiManager(); if (_entry) { constexpr auto kMinus = QChar(0x2212); _rightText.setMarkedText( @@ -930,9 +934,9 @@ void CreditsRow::init() { if (!_paintUserpicCallback) { _paintUserpicCallback = _entry.stargift ? Ui::GenerateGiftStickerUserpicCallback( - _context.session, + _session, _entry.bareGiftStickerId, - _context.customEmojiRepaint) + _context.repaint) : !isSpecial ? PeerListRow::generatePaintUserpicCallback(false) : Ui::GenerateCreditsPaintUserpicCallback(_entry); @@ -1110,7 +1114,7 @@ private: Api::CreditsHistory _api; Data::CreditsStatusSlice _firstSlice; Data::CreditsStatusSlice::OffsetToken _apiToken; - Core::MarkedTextContext _context; + Ui::Text::MarkedContext _context; rpl::variable _allLoaded = false; bool _requesting = false; @@ -1123,10 +1127,7 @@ CreditsController::CreditsController(CreditsDescriptor d) , _entryClickedCallback(std::move(d.entryClickedCallback)) , _api(d.peer, d.in, d.out) , _firstSlice(std::move(d.firstSlice)) -, _context(Core::MarkedTextContext{ - .session = _session, - .customEmojiRepaint = [] {}, -}) { +, _context(Core::TextContext({ .session = _session })) { PeerListController::setStyleOverrides(&st::creditsHistoryEntriesList); } @@ -1166,6 +1167,7 @@ void CreditsController::applySlice(const Data::CreditsStatusSlice &slice) { const Data::CreditsHistoryEntry &i, const Data::SubscriptionEntry &s) { const auto descriptor = CreditsRow::Descriptor{ + .session = &session(), .entry = i, .subscription = s, .context = _context, diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_recent_message.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_recent_message.cpp index 2f8b1d069..1a5da3a0d 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_recent_message.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_recent_message.cpp @@ -87,10 +87,10 @@ MessagePreview::MessagePreview( st::defaultPeerListItem.nameStyle, item->toPreview({ .generateImages = false }).text, Ui::DialogTextOptions(), - Core::MarkedTextContext{ + Core::TextContext({ .session = &item->history()->session(), - .customEmojiRepaint = [=] { update(); }, - }); + .repaint = [=] { update(); }, + })); if (item->media() && item->media()->hasSpoiler()) { _spoiler = std::make_unique([=] { update(); }); } @@ -131,10 +131,10 @@ MessagePreview::MessagePreview( st::defaultPeerListItem.nameStyle, { tr::lng_in_dlg_story(tr::now) }, Ui::DialogTextOptions(), - Core::MarkedTextContext{ + Core::TextContext({ .session = &story->peer()->session(), - .customEmojiRepaint = [=] { update(); }, - }); + .repaint = [=] { update(); }, + })); if (_preview.isNull()) { if (const auto photo = story->photo()) { _photoMedia = photo->createMediaView(); diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index 6d112e5d3..d7fad9222 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" #include "core/local_url_handlers.h" #include "core/shortcuts.h" +#include "core/ui_integration.h" // TextContext #include "data/components/location_pickers.h" #include "data/data_bot_app.h" #include "data/data_changes.h" @@ -380,21 +381,16 @@ void FillBotUsepic( not_null box, not_null bot, base::weak_ptr weak) { - auto arrow = Ui::Text::SingleCustomEmoji( - bot->owner().customEmojiManager().registerInternalEmoji( - st::topicButtonArrow, - st::channelEarnLearnArrowMargins, - true)); auto aboutLabel = Ui::CreateLabelWithCustomEmoji( box->verticalLayout(), tr::lng_allow_bot_webview_details( lt_emoji, - rpl::single(std::move(arrow)), + rpl::single(Ui::Text::IconEmoji(&st::textMoreIconEmoji)), Ui::Text::RichLangValue ) | rpl::map([](TextWithEntities text) { return Ui::Text::Link(std::move(text), u"internal:"_q); }), - { .session = &bot->session() }, + Core::TextContext({ .session = &bot->session() }), st::defaultFlatLabel); const auto userpic = Ui::CreateChild( box->verticalLayout(), @@ -446,12 +442,6 @@ std::unique_ptr MakeEmojiSetStatusPreview( not_null parent, not_null peer, not_null document) { - const auto makeContext = [=](Fn update) { - return Core::MarkedTextContext{ - .session = &peer->session(), - .customEmojiRepaint = update, - }; - }; const auto emoji = Ui::CreateChild>( parent, object_ptr( @@ -464,7 +454,7 @@ std::unique_ptr MakeEmojiSetStatusPreview( : QString()))), st::botEmojiStatusEmoji, st::defaultPopupMenu, - makeContext), + Core::TextContext({ .session = &peer->session() })), style::margins(st::normalFont->spacew, 0, 0, 0)); emoji->entity()->resizeToWidth(emoji->entity()->textMaxWidth()); diff --git a/Telegram/SourceFiles/intro/intro_step.cpp b/Telegram/SourceFiles/intro/intro_step.cpp index c8d9a3d59..969aecbb0 100644 --- a/Telegram/SourceFiles/intro/intro_step.cpp +++ b/Telegram/SourceFiles/intro/intro_step.cpp @@ -104,13 +104,7 @@ Step::Step( text.entities, EntityType::Spoiler, &EntityInText::type); - if (hasSpoiler) { - label->setMarkedText( - text, - CommonTextContext{ [=] { label->update(); } }); - } else { - label->setMarkedText(text); - } + label->setMarkedText(text); label->setAttribute(Qt::WA_TransparentForMouseEvents, hasSpoiler); updateLabelsPosition(); }, lifetime()); diff --git a/Telegram/SourceFiles/media/stories/media_stories_caption_full_view.cpp b/Telegram/SourceFiles/media/stories/media_stories_caption_full_view.cpp index f3c4a112f..218add340 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_caption_full_view.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_caption_full_view.cpp @@ -30,10 +30,9 @@ CaptionFullView::CaptionFullView(not_null controller) object_ptr(_scroll.get(), st::storiesCaptionFull), st::mediaviewCaptionPadding + _controller->repostCaptionPadding()))) , _text(_wrap->entity()) { - _text->setMarkedText(controller->captionText(), Core::MarkedTextContext{ + _text->setMarkedText(controller->captionText(), Core::TextContext({ .session = &controller->uiShow()->session(), - .customEmojiRepaint = [=] { _text->update(); }, - }); + })); startAnimation(); _controller->layoutValue( diff --git a/Telegram/SourceFiles/media/stories/media_stories_header.cpp b/Telegram/SourceFiles/media/stories/media_stories_header.cpp index 7277109c3..a77c700b2 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_header.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_header.cpp @@ -403,10 +403,7 @@ void Header::show(HeaderData data) { const auto prefix = data.fromPeer ? data.fromPeer : data.repostPeer; _repost->setMarkedText( (prefix ? Ui::Text::Link(prefixName) : prefixName), - Core::MarkedTextContext{ - .session = &data.peer->session(), - .customEmojiRepaint = [=] { _repost->update(); }, - }); + Core::TextContext({ .session = &data.peer->session() })); if (prefix) { _repost->setClickHandlerFilter([=](const auto &...) { _controller->uiShow()->show(PrepareShortInfoBox(prefix)); diff --git a/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp b/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp index 4dfdd6a56..0b8065b46 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp @@ -242,19 +242,18 @@ void RepostView::recountDimensions() { auto nameFull = TextWithEntities(); nameFull.append(HistoryView::Reply::PeerEmoji(owner, _sourcePeer)); nameFull.append(name); - auto context = Core::MarkedTextContext{ + auto context = Core::TextContext({ .session = &_story->session(), - .customEmojiRepaint = [] {}, .customEmojiLoopLimit = 1, - }; + }); _name.setMarkedText( st::semiboldTextStyle, nameFull, Ui::NameTextOptions(), context); - context.customEmojiRepaint = crl::guard(this, [=] { + context.repaint = crl::guard(this, [=] { _controller->repaint(); - }), + }); _text.setMarkedText( st::defaultTextStyle, text, diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 289376216..f5cf304fd 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -3346,12 +3346,12 @@ void OverlayWidget::refreshCaption() { } update(captionGeometry()); }; - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = (_stories ? _storiesSession : &_message->history()->session()), - .customEmojiRepaint = captionRepaint, - }; + .repaint = captionRepaint, + }); _caption.setMarkedText( st::mediaviewCaptionStyle, (base.isEmpty() diff --git a/Telegram/SourceFiles/menu/menu_sponsored.cpp b/Telegram/SourceFiles/menu/menu_sponsored.cpp index a1b51ed75..231da1ee0 100644 --- a/Telegram/SourceFiles/menu/menu_sponsored.cpp +++ b/Telegram/SourceFiles/menu/menu_sponsored.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/premium_preview_box.h" #include "chat_helpers/compose/compose_show.h" +#include "core/ui_integration.h" // TextContext #include "data/components/sponsored_messages.h" #include "data/data_premium_limits.h" #include "data/data_session.h" @@ -191,11 +192,7 @@ void AboutBox( } Ui::AddSkip(content); { - const auto arrow = Ui::Text::SingleCustomEmoji( - session->data().customEmojiManager().registerInternalEmoji( - st::topicButtonArrow, - st::channelEarnLearnArrowMargins, - true)); + const auto arrow = Ui::Text::IconEmoji(&st::textMoreIconEmoji); const auto available = box->width() - rect::m::sum::h(st::boxRowPadding); box->addRow( @@ -213,7 +210,7 @@ void AboutBox( return Ui::Text::Link(std::move(t), kUrl.utf16()); }), Ui::Text::RichLangValue), - { .session = session }, + Core::TextContext({ .session = session }), st::channelEarnLearnDescription))->resizeToWidth(available); } Ui::AddSkip(content); diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index fd8468a53..05e1c0ad7 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "overview/overview_layout.h" #include "overview/overview_layout_delegate.h" -#include "core/ui_integration.h" // Core::MarkedTextContext. +#include "core/ui_integration.h" // TextContext #include "data/data_document.h" #include "data/data_document_resolver.h" #include "data/data_session.h" @@ -1042,10 +1042,10 @@ void Voice::updateName() { st::defaultTextStyle, parent()->originalText(), Ui::DialogTextOptions(), - Core::MarkedTextContext{ + Core::TextContext({ .session = &parent()->history()->session(), - .customEmojiRepaint = [=] { delegate()->repaintItem(this); }, - }); + .repaint = [=] { delegate()->repaintItem(this); }, + })); } bool Voice::updateStatusText() { diff --git a/Telegram/SourceFiles/payments/payments_reaction_process.cpp b/Telegram/SourceFiles/payments/payments_reaction_process.cpp index 94d527471..b585bab60 100644 --- a/Telegram/SourceFiles/payments/payments_reaction_process.cpp +++ b/Telegram/SourceFiles/payments/payments_reaction_process.cpp @@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_global_privacy.h" #include "apiwrap.h" #include "boxes/send_credits_box.h" // CreditsEmojiSmall. -#include "core/ui_integration.h" // MarkedTextContext. +#include "core/ui_integration.h" // TextContext. #include "data/components/credits.h" #include "data/data_channel.h" #include "data/data_message_reactions.h" @@ -186,10 +186,7 @@ void ShowPaidReactionDetails( ) | rpl::map([=](TextWithEntities &&text) { return Ui::TextWithContext{ .text = std::move(text), - .context = Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [] {}, - }, + .context = Core::TextContext({ .session = session }), }; }); }; diff --git a/Telegram/SourceFiles/payments/ui/payments_reaction_box.h b/Telegram/SourceFiles/payments/ui/payments_reaction_box.h index 34f67e066..1468d53ba 100644 --- a/Telegram/SourceFiles/payments/ui/payments_reaction_box.h +++ b/Telegram/SourceFiles/payments/ui/payments_reaction_box.h @@ -21,7 +21,7 @@ class DynamicImage; struct TextWithContext { TextWithEntities text; - std::any context; + Text::MarkedContext context; }; struct PaidReactionTop { diff --git a/Telegram/SourceFiles/settings/business/settings_chat_links.cpp b/Telegram/SourceFiles/settings/business/settings_chat_links.cpp index e0d35efca..44025db44 100644 --- a/Telegram/SourceFiles/settings/business/settings_chat_links.cpp +++ b/Telegram/SourceFiles/settings/business/settings_chat_links.cpp @@ -164,10 +164,10 @@ Row::Row(not_null delegate, const ChatLinkData &data) } void Row::updateStatus(const ChatLinkData &data) { - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = _delegate->rowSession(), - .customEmojiRepaint = [=] { _delegate->rowUpdateRow(this); }, - }; + .repaint = [=] { _delegate->rowUpdateRow(this); }, + }); _status.setMarkedText( st::messageTextStyle, data.message, diff --git a/Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.cpp b/Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.cpp index 4b6c8024f..e8bb2607a 100644 --- a/Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.cpp +++ b/Telegram/SourceFiles/settings/cloud_password/settings_cloud_password_common.cpp @@ -143,10 +143,7 @@ void SetupHeader( content, v::text::take_marked(std::move(about)), st, - st::defaultPopupMenu, - [=](Fn update) { - return CommonTextContext{ std::move(update) }; - })), + st::defaultPopupMenu)), st::changePhoneDescriptionPadding); wrap->setAttribute(Qt::WA_TransparentForMouseEvents); wrap->resize( diff --git a/Telegram/SourceFiles/settings/settings_business.cpp b/Telegram/SourceFiles/settings/settings_business.cpp index 82c0b9964..b1bee4942 100644 --- a/Telegram/SourceFiles/settings/settings_business.cpp +++ b/Telegram/SourceFiles/settings/settings_business.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_chat_links.h" #include "boxes/premium_preview_box.h" #include "core/click_handler_types.h" +#include "core/ui_integration.h" // TextContext #include "data/business/data_business_info.h" #include "data/business/data_business_chatbots.h" #include "data/business/data_shortcut_messages.h" @@ -526,11 +527,7 @@ void Business::setupContent() { const auto session = &_controller->session(); { - const auto arrow = Ui::Text::SingleCustomEmoji( - session->data().customEmojiManager().registerInternalEmoji( - st::topicButtonArrow, - st::channelEarnLearnArrowMargins, - true)); + const auto arrow = Ui::Text::IconEmoji(&st::textMoreIconEmoji); inner->add(object_ptr( inner, Ui::CreateLabelWithCustomEmoji( @@ -547,7 +544,7 @@ void Business::setupContent() { return Ui::Text::Link(text, url); }), Ui::Text::RichLangValue), - { .session = session }, + Core::TextContext({ .session = session }), st::boxDividerLabel), st::defaultBoxDividerLabelPadding, RectPart::Top | RectPart::Bottom)); diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index 8e9c87bf3..4056c3bfb 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -469,10 +469,7 @@ SubscriptionRightLabel PaintSubscriptionRightLabelCallback( .append(QChar::Space) .append(Lang::FormatCountDecimal(amount)), kMarkupTextOptions, - Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [] {}, - }); + Core::TextContext({ .session = session })); const auto &font = text->style()->font; const auto &statusFont = st::contactsStatusFont; const auto status = tr::lng_group_invite_joined_right(tr::now); @@ -821,10 +818,10 @@ void BoostCreditsBox( st, std::move(textWithEntities), kMarkupTextOptions, - Core::MarkedTextContext{ + Core::TextContext({ .session = session, - .customEmojiRepaint = [=] { badge->update(); }, - }); + .repaint = [=] { badge->update(); }, + })); badge->paintRequest( ) | rpl::start_with_next([=] { auto p = QPainter(badge); @@ -1328,10 +1325,10 @@ void GenericCreditsEntryBox( object_ptr( content, st::defaultTextStyle.font->height)); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = session, - .customEmojiRepaint = [=] { amount->update(); }, - }; + .repaint = [=] { amount->update(); }, + }); if (e.soldOutInfo) { text->setText( st::defaultTextStyle, @@ -1438,11 +1435,7 @@ void GenericCreditsEntryBox( st::creditsBoxAbout))); } - const auto arrowEmoji = Ui::Text::SingleCustomEmoji( - owner->customEmojiManager().registerInternalEmoji( - st::topicButtonArrow, - st::channelEarnLearnArrowMargins, - true)); + const auto arrow = Ui::Text::IconEmoji(&st::textMoreIconEmoji); if (!uniqueGift && starGiftCanManage) { Ui::AddSkip(content); const auto about = box->addRow( @@ -1510,7 +1503,7 @@ void GenericCreditsEntryBox( Ui::AddSkip(content); auto link = tr::lng_credits_box_history_entry_gift_about_link( lt_emoji, - rpl::single(arrowEmoji), + rpl::single(arrow), Ui::Text::RichLangValue ) | rpl::map([](TextWithEntities text) { return Ui::Text::Link( @@ -1532,13 +1525,13 @@ void GenericCreditsEntryBox( lt_link, std::move(link), Ui::Text::RichLangValue), - { .session = session }, + Core::TextContext({ .session = session }), st::creditsBoxAbout))); } else if (e.paidMessagesCommission && e.barePeerId) { Ui::AddSkip(content); auto link = tr::lng_credits_paid_messages_fee_about_link( lt_emoji, - rpl::single(arrowEmoji), + rpl::single(arrow), Ui::Text::RichLangValue ) | rpl::map([id = e.barePeerId](TextWithEntities text) { return Ui::Text::Link( @@ -1557,7 +1550,7 @@ void GenericCreditsEntryBox( lt_link, std::move(link), Ui::Text::RichLangValue), - { .session = session }, + Core::TextContext({ .session = session }), st::creditsBoxAbout))); } @@ -2475,10 +2468,6 @@ void AddWithdrawalWidget( st::settingsPremiumIconStar, { 0, -st::moderateBoxExpandInnerSkip, 0, 0 }, true)); - const auto context = Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [=] { label->update(); }, - }; using Balance = rpl::variable; const auto currentBalance = input->lifetime().make_state( rpl::duplicate(availableBalanceValue)); @@ -2496,7 +2485,7 @@ void AddWithdrawalWidget( lt_emoji, buttonEmoji, Ui::Text::RichLangValue), - context); + Core::TextContext({ .session = session })); } }; QObject::connect(input, &Ui::MaskedInputField::changed, process); @@ -2564,10 +2553,10 @@ void AddWithdrawalWidget( constexpr auto kDateUpdateInterval = crl::time(250); const auto was = base::unixtime::serialize(dt); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = session, - .customEmojiRepaint = [=] { lockedLabel->update(); }, - }; + .repaint = [=] { lockedLabel->update(); }, + }); const auto emoji = Ui::Text::SingleCustomEmoji( session->data().customEmojiManager().registerInternalEmoji( st::chatSimilarLockedIcon, @@ -2644,11 +2633,7 @@ void AddWithdrawalWidget( Ui::AddSkip(container); Ui::AddSkip(container); - const auto arrow = Ui::Text::SingleCustomEmoji( - session->data().customEmojiManager().registerInternalEmoji( - st::topicButtonArrow, - st::channelEarnLearnArrowMargins, - true)); + const auto arrow = Ui::Text::IconEmoji(&st::textMoreIconEmoji); auto about = Ui::CreateLabelWithCustomEmoji( container, tr::lng_bot_earn_learn_credits_out_about( @@ -2663,7 +2648,7 @@ void AddWithdrawalWidget( tr::lng_bot_earn_balance_about_url(tr::now)); }), Ui::Text::RichLangValue), - { .session = session }, + Core::TextContext({ .session = session }), st::boxDividerLabel); Ui::AddSkip(container); container->add(object_ptr( diff --git a/Telegram/SourceFiles/settings/settings_folders.cpp b/Telegram/SourceFiles/settings/settings_folders.cpp index ddcc9071c..995591894 100644 --- a/Telegram/SourceFiles/settings/settings_folders.cpp +++ b/Telegram/SourceFiles/settings/settings_folders.cpp @@ -199,11 +199,11 @@ void FilterRowButton::updateData( st::contactsNameStyle, title.text, kMarkupTextOptions, - Core::MarkedTextContext{ + Core::TextContext({ .session = _session, - .customEmojiRepaint = [=] { update(); }, + .repaint = [=] { update(); }, .customEmojiLoopLimit = title.isStatic ? -1 : 0, - }); + })); _icon = Ui::ComputeFilterIcon(filter); _colorIndex = filter.colorIndex(); if (!ignoreCount) { diff --git a/Telegram/SourceFiles/settings/settings_premium.cpp b/Telegram/SourceFiles/settings/settings_premium.cpp index 343bbefc2..a834f9a6d 100644 --- a/Telegram/SourceFiles/settings/settings_premium.cpp +++ b/Telegram/SourceFiles/settings/settings_premium.cpp @@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/click_handler_types.h" #include "core/local_url_handlers.h" // Core::TryConvertUrlToLocal. -#include "core/ui_integration.h" // MarkedTextContext. +#include "core/ui_integration.h" // TextContext. #include "data/data_document.h" #include "data/data_document_media.h" #include "data/data_emoji_statuses.h" @@ -788,11 +788,9 @@ void TopBarUser::updateTitle( lt_link, { .text = text, .entities = entities, }, Ui::Text::WithEntities); - const auto context = Core::MarkedTextContext{ - .session = &controller->session(), - .customEmojiRepaint = [=] { _title->update(); }, - }; - _title->setMarkedText(std::move(title), context); + _title->setMarkedText( + std::move(title), + Core::TextContext({ .session = &controller->session() })); auto link = std::make_shared([=, stickerSetIdentifier = stickerInfo->set] { setPaused(true); diff --git a/Telegram/SourceFiles/ui/boxes/collectible_info_box.cpp b/Telegram/SourceFiles/ui/boxes/collectible_info_box.cpp index d76d6802d..fb0300664 100644 --- a/Telegram/SourceFiles/ui/boxes/collectible_info_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/collectible_info_box.cpp @@ -224,7 +224,9 @@ void CollectibleInfoBox( object_ptr(box, st::collectibleInfo), st::collectibleInfoPadding); label->setAttribute(Qt::WA_TransparentForMouseEvents); - label->setMarkedText(text, details.tonEmojiContext()); + auto context = details.tonEmojiContext; + context.repaint = [label] { label->update(); }; + label->setMarkedText(text, context); const auto more = box->addRow( object_ptr( diff --git a/Telegram/SourceFiles/ui/boxes/collectible_info_box.h b/Telegram/SourceFiles/ui/boxes/collectible_info_box.h index 8b80b9650..9080819c9 100644 --- a/Telegram/SourceFiles/ui/boxes/collectible_info_box.h +++ b/Telegram/SourceFiles/ui/boxes/collectible_info_box.h @@ -34,7 +34,7 @@ struct CollectibleInfo { struct CollectibleDetails { TextWithEntities tonEmoji; - Fn tonEmojiContext; + Text::MarkedContext tonEmojiContext; }; void CollectibleInfoBox( diff --git a/Telegram/SourceFiles/ui/boxes/edit_invite_link_session.cpp b/Telegram/SourceFiles/ui/boxes/edit_invite_link_session.cpp index 8c1a68b20..f868cc3e9 100644 --- a/Telegram/SourceFiles/ui/boxes/edit_invite_link_session.cpp +++ b/Telegram/SourceFiles/ui/boxes/edit_invite_link_session.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/boxes/edit_invite_link_session.h" +#include "core/ui_integration.h" // TextContext #include "data/components/credits.h" #include "data/data_peer.h" #include "data/data_session.h" @@ -128,18 +129,13 @@ InviteLinkSubscriptionToggle FillCreateInviteLinkSubscriptionToggle( state->usdRate = peer->session().credits().rateValue(peer); - const auto arrow = Ui::Text::SingleCustomEmoji( - peer->owner().customEmojiManager().registerInternalEmoji( - st::topicButtonArrow, - st::channelEarnLearnArrowMargins, - true)); auto about = Ui::CreateLabelWithCustomEmoji( container, tr::lng_group_invite_subscription_about( lt_link, tr::lng_group_invite_subscription_about_link( lt_emoji, - rpl::single(arrow), + rpl::single(Ui::Text::IconEmoji(&st::textMoreIconEmoji)), Ui::Text::RichLangValue ) | rpl::map([](TextWithEntities text) { return Ui::Text::Link( @@ -147,7 +143,7 @@ InviteLinkSubscriptionToggle FillCreateInviteLinkSubscriptionToggle( tr::lng_group_invite_subscription_about_url(tr::now)); }), Ui::Text::RichLangValue), - { .session = &peer->session() }, + Core::TextContext({ .session = &peer->session() }), st::boxDividerLabel); Ui::AddSkip(wrap->entity()); Ui::AddSkip(wrap->entity()); diff --git a/Telegram/SourceFiles/ui/chat/chats_filter_tag.cpp b/Telegram/SourceFiles/ui/chat/chats_filter_tag.cpp index 077de4f32..020ffa4b0 100644 --- a/Telegram/SourceFiles/ui/chat/chats_filter_tag.cpp +++ b/Telegram/SourceFiles/ui/chat/chats_filter_tag.cpp @@ -174,7 +174,6 @@ bool ScaledCustomEmoji::readyInDefaultState() { ChatsFilterTagContext &context) { auto i = text.entities.begin(); auto ch = text.text.constData(); - auto &integration = Integration::Instance(); context.loading = false; const auto end = text.text.constData() + text.text.size(); const auto adjust = [&](EntityInText &entity) { @@ -187,9 +186,7 @@ bool ScaledCustomEmoji::readyInDefaultState() { } auto &emoji = context.emoji[data]; if (!emoji) { - emoji = integration.createCustomEmoji( - data, - context.textContext); + emoji = Text::MakeCustomEmoji(data, context.textContext); } if (!emoji->ready()) { context.loading = true; diff --git a/Telegram/SourceFiles/ui/chat/chats_filter_tag.h b/Telegram/SourceFiles/ui/chat/chats_filter_tag.h index 28da74c80..8291b5e33 100644 --- a/Telegram/SourceFiles/ui/chat/chats_filter_tag.h +++ b/Telegram/SourceFiles/ui/chat/chats_filter_tag.h @@ -8,16 +8,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "emoji.h" - -namespace Ui::Text { -class CustomEmoji; -} // namespace Ui::Text +#include "ui/text/text.h" namespace Ui { struct ChatsFilterTagContext { base::flat_map> emoji; - std::any textContext; + Text::MarkedContext textContext; QColor color; bool active = false; bool loading = false; diff --git a/Telegram/SourceFiles/ui/chat/message_bar.h b/Telegram/SourceFiles/ui/chat/message_bar.h index 36b96658e..6132ae446 100644 --- a/Telegram/SourceFiles/ui/chat/message_bar.h +++ b/Telegram/SourceFiles/ui/chat/message_bar.h @@ -26,7 +26,7 @@ struct MessageBarContent { int count = 1; QString title; TextWithEntities text; - std::any context; + Text::MarkedContext context; QImage preview; Fn spoilerRepaint; style::margins margins; diff --git a/Telegram/SourceFiles/ui/chat/sponsored_message_bar.cpp b/Telegram/SourceFiles/ui/chat/sponsored_message_bar.cpp index adce1fcd7..1f2fd2417 100644 --- a/Telegram/SourceFiles/ui/chat/sponsored_message_bar.cpp +++ b/Telegram/SourceFiles/ui/chat/sponsored_message_bar.cpp @@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/click_handler_types.h" -#include "core/ui_integration.h" // Core::MarkedTextContext. +#include "core/ui_integration.h" // TextContext #include "data/components/sponsored_messages.h" #include "data/data_session.h" #include "history/history_item_helpers.h" @@ -202,10 +202,10 @@ void FillSponsoredMessageBar( contentTextSt, textWithEntities, kMarkupTextOptions, - Core::MarkedTextContext{ + Core::TextContext({ .session = session, - .customEmojiRepaint = [=] { widget->update(); }, - }); + .repaint = [=] { widget->update(); }, + })); const auto hostedClick = [=](ClickHandlerPtr handler) { return [=] { if (const auto controller = FindSessionController(widget)) { diff --git a/Telegram/SourceFiles/ui/controls/filter_link_header.cpp b/Telegram/SourceFiles/ui/controls/filter_link_header.cpp index 16c6cf398..e6a02ef66 100644 --- a/Telegram/SourceFiles/ui/controls/filter_link_header.cpp +++ b/Telegram/SourceFiles/ui/controls/filter_link_header.cpp @@ -77,7 +77,7 @@ private: QPainterPath _titlePath; TextWithEntities _folderTitle; - Fn)> _makeContext; + Text::MarkedContext _aboutContext; not_null _folderIcon; bool _horizontalFilters = false; @@ -90,7 +90,7 @@ private: [[nodiscard]] PreviewState GeneratePreview( not_null parent, const TextWithEntities &title, - Fn)> makeContext, + Text::MarkedContext aboutContext, int badge) { using Tabs = Ui::ChatsFiltersTabs; auto preview = PreviewState(); @@ -126,14 +126,14 @@ private: return state->cache; }; const auto raw = &state->tabs; - const auto repaint = [=] { - state->dirty = true; - }; + const auto repaint = [=] { state->dirty = true; }; + auto context = aboutContext; + context.repaint = repaint; raw->setSections({ TextWithEntities{ tr::lng_filters_name_people(tr::now) }, title, TextWithEntities{ tr::lng_filters_name_unread(tr::now) }, - }, makeContext(repaint)); + }, context); raw->fitWidthToSections(); raw->setActiveSectionFast(1); raw->stopAnimation(); @@ -153,7 +153,7 @@ private: [[nodiscard]] PreviewState GeneratePreview( const TextWithEntities &title, - Fn)> makeContext, + Text::MarkedContext context, not_null icon, int badge) { auto preview = PreviewState(); @@ -165,7 +165,7 @@ private: bool dirty = true; }; const auto state = preview.lifetime.make_state(); - const auto repaint = [=] { + context.repaint = [=] { state->dirty = true; }; @@ -201,7 +201,7 @@ private: text, kMarkupTextOptions, available, - makeContext(repaint)); + context); }; const auto paintName = [=](QPainter &p, int top) { state->string.draw(p, { @@ -299,7 +299,7 @@ Widget::Widget( rpl::single(descriptor.about.value()), st::filterLinkAbout, st::defaultPopupMenu, - descriptor.makeAboutContext)) + descriptor.aboutContext)) , _close(CreateChild(this, st::boxTitleClose)) , _aboutPadding(st::boxRowPadding) , _badge(std::move(descriptor.badge)) @@ -307,7 +307,7 @@ Widget::Widget( , _titleFont(st::boxTitle.style.font) , _titlePadding(st::filterLinkTitlePadding) , _folderTitle(descriptor.folderTitle) -, _makeContext(descriptor.makeAboutContext) +, _aboutContext(descriptor.aboutContext) , _folderIcon(descriptor.folderIcon) , _horizontalFilters(descriptor.horizontalFilters) { setMinimumHeight(st::boxTitleHeight); @@ -417,20 +417,24 @@ void Widget::paintEvent(QPaintEvent *e) { auto hq = PainterHighQualityEnabler(p); if (!_preview.frame) { const auto badge = _badge.current(); - const auto makeContext = [=](Fn repaint) { - return _makeContext([=] { repaint(); update(); }); + auto context = _aboutContext; + context.repaint = [this, copy = context.repaint] { + if (const auto &repaint = copy) { + repaint(); + } + update(); }; if (_horizontalFilters) { _preview = GeneratePreview( this, _folderTitle, - makeContext, + context, badge); Widget::resizeEvent(nullptr); } else { _preview = GeneratePreview( _folderTitle, - makeContext, + context, _folderIcon, badge); } @@ -486,7 +490,7 @@ object_ptr FilterLinkProcessButton( not_null parent, FilterLinkHeaderType type, TextWithEntities title, - Fn)> makeContext, + Text::MarkedContext context, rpl::producer badge) { const auto st = &st::filterInviteBox.button; const auto badgeSt = &st::filterInviteButtonBadgeStyle; @@ -600,12 +604,13 @@ object_ptr FilterLinkProcessButton( } }, label->lifetime()); + context.repaint = [=] { label->update(); }; std::move(data) | rpl::start_with_next([=](Data data) { label->text.setMarkedText( st::filterInviteButtonStyle, data.text, kMarkupTextOptions, - makeContext([=] { label->update(); })); + context); label->badge.setText(st::filterInviteButtonBadgeStyle, data.badge); label->update(); }, label->lifetime()); diff --git a/Telegram/SourceFiles/ui/controls/filter_link_header.h b/Telegram/SourceFiles/ui/controls/filter_link_header.h index 55d092387..a530de23a 100644 --- a/Telegram/SourceFiles/ui/controls/filter_link_header.h +++ b/Telegram/SourceFiles/ui/controls/filter_link_header.h @@ -26,7 +26,7 @@ struct FilterLinkHeaderDescriptor { base::required type; base::required title; base::required about; - Fn)> makeAboutContext; + Text::MarkedContext aboutContext; base::required folderTitle; not_null folderIcon; rpl::producer badge; @@ -47,7 +47,7 @@ struct FilterLinkHeader { not_null parent, FilterLinkHeaderType type, TextWithEntities title, - Fn)> makeContext, + Text::MarkedContext context, rpl::producer badge); } // namespace Ui diff --git a/Telegram/SourceFiles/ui/controls/tabbed_search.cpp b/Telegram/SourceFiles/ui/controls/tabbed_search.cpp index 59a1f6cf0..ea9f1e70f 100644 --- a/Telegram/SourceFiles/ui/controls/tabbed_search.cpp +++ b/Telegram/SourceFiles/ui/controls/tabbed_search.cpp @@ -149,7 +149,7 @@ void GroupsStrip::set(std::vector list) { .icon = std::make_unique( _factory( group.iconId, - updater(group.iconId)), + { .repaint = updater(group.iconId) }), loopCount, stopAtLastFrame), }); diff --git a/Telegram/SourceFiles/ui/controls/who_reacted_context_action.cpp b/Telegram/SourceFiles/ui/controls/who_reacted_context_action.cpp index 9834489b1..3fe236355 100644 --- a/Telegram/SourceFiles/ui/controls/who_reacted_context_action.cpp +++ b/Telegram/SourceFiles/ui/controls/who_reacted_context_action.cpp @@ -359,7 +359,7 @@ void Action::paint(Painter &p) { if (!_custom && !_content.singleCustomEntityData.isEmpty()) { _custom = _customEmojiFactory( _content.singleCustomEntityData, - [=] { update(); }); + { .repaint = [=] { update(); } }); } if (_custom) { const auto ratio = style::DevicePixelRatio(); @@ -772,7 +772,9 @@ void WhoReactedEntryAction::setData(Data &&data) { } _type = data.type; _custom = _customEmojiFactory - ? _customEmojiFactory(data.customEntityData, [=] { update(); }) + ? _customEmojiFactory( + data.customEntityData, + { .repaint = [=] { update(); } }) : nullptr; const auto ratio = style::DevicePixelRatio(); const auto size = Emoji::GetSizeNormal() / ratio; diff --git a/Telegram/SourceFiles/ui/unread_badge.cpp b/Telegram/SourceFiles/ui/unread_badge.cpp index b01dcb198..233ff51a9 100644 --- a/Telegram/SourceFiles/ui/unread_badge.cpp +++ b/Telegram/SourceFiles/ui/unread_badge.cpp @@ -298,7 +298,7 @@ void PeerBadge::set( if (details->iconId) { _botVerifiedData->icon = factory( Data::SerializeCustomEmojiId(details->iconId), - repaint); + { .repaint = repaint }); } } diff --git a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.cpp b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.cpp index 8149ffca5..5fddc9e79 100644 --- a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.cpp +++ b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.cpp @@ -54,7 +54,7 @@ ChatsFiltersTabs::ChatsFiltersTabs( bool ChatsFiltersTabs::setSectionsAndCheckChanged( std::vector &§ions, - const std::any &context, + const Text::MarkedContext &context, Fn paused) { const auto &was = sectionsRef(); const auto changed = [&] { diff --git a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.h b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.h index 64c66c062..1375b70dc 100644 --- a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.h +++ b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_slider.h @@ -29,7 +29,7 @@ public: bool setSectionsAndCheckChanged( std::vector &§ions, - const std::any &context, + const Text::MarkedContext &context, Fn paused); void fitWidthToSections() override; diff --git a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp index 64cd5eb39..176b5644c 100644 --- a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp +++ b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp @@ -175,11 +175,11 @@ void ShowFiltersListMenu( icon); action->setEnabled(i < premiumFrom); if (!title.text.empty()) { - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = session, - .customEmojiRepaint = [raw = item.get()] { raw->update(); }, + .repaint = [raw = item.get()] { raw->update(); }, .customEmojiLoopLimit = title.isStatic ? -1 : 0, - }; + }); item->setMarkedText(title.text, QString(), context); } state->menu->addAction(std::move(item)); @@ -344,10 +344,7 @@ not_null AddChatFiltersTabsStrip( if ((list.size() <= 1 && !slider->width()) || state->ignoreRefresh) { return; } - const auto context = Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [=] { slider->update(); }, - }; + const auto context = Core::TextContext({ .session = session }); const auto paused = [=] { return On(PowerSaving::kEmojiChat) || controller->isGifPausedAtLeastFor(pauseLevel); diff --git a/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp b/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp index e11ea96d0..77874b58d 100644 --- a/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp +++ b/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp @@ -79,7 +79,8 @@ void DiscreteSlider::addSection(const QString &label) { void DiscreteSlider::addSection( const TextWithEntities &label, - const std::any &context) { + Text::MarkedContext context) { + context.repaint = [this] { update(); }; _sections.push_back(Section(label, getLabelStyle(), context)); resizeToWidth(width()); } @@ -96,9 +97,11 @@ void DiscreteSlider::setSections(const std::vector &labels) { void DiscreteSlider::setSections( const std::vector &labels, - const std::any &context) { + Text::MarkedContext context) { Assert(!labels.empty()); + context.repaint = [this] { update(); }; + _sections.clear(); for (const auto &label : labels) { _sections.push_back(Section(label, getLabelStyle(), context)); @@ -225,7 +228,7 @@ DiscreteSlider::Section::Section( DiscreteSlider::Section::Section( const TextWithEntities &label, const style::TextStyle &st, - const std::any &context) { + const Text::MarkedContext &context) { this->label.setMarkedText(st, label, kMarkupTextOptions, context); contentWidth = Section::label.maxWidth(); } diff --git a/Telegram/SourceFiles/ui/widgets/discrete_sliders.h b/Telegram/SourceFiles/ui/widgets/discrete_sliders.h index 2ff6f771c..4e9476bb0 100644 --- a/Telegram/SourceFiles/ui/widgets/discrete_sliders.h +++ b/Telegram/SourceFiles/ui/widgets/discrete_sliders.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" #include "ui/round_rect.h" #include "ui/effects/animations.h" +#include "ui/text/text.h" namespace style { struct TextStyle; @@ -32,11 +33,11 @@ public: void addSection(const QString &label); void addSection( const TextWithEntities &label, - const std::any &context = {}); + Text::MarkedContext context = {}); void setSections(const std::vector &labels); void setSections( const std::vector &labels, - const std::any &context = {}); + Text::MarkedContext context = {}); int activeSection() const { return _activeIndex; } @@ -63,9 +64,9 @@ protected: Section( const TextWithEntities &label, const style::TextStyle &st, - const std::any &context); + const Text::MarkedContext &context); - Ui::Text::String label; + Text::String label; std::unique_ptr ripple; int left = 0; int width = 0; diff --git a/Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.cpp b/Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.cpp index 4502d6553..69f1d5f14 100644 --- a/Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.cpp +++ b/Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.cpp @@ -16,13 +16,12 @@ namespace Ui { object_ptr CreateLabelWithCustomEmoji( QWidget *parent, rpl::producer &&text, - Core::MarkedTextContext context, + Text::MarkedContext context, const style::FlatLabel &st) { auto label = object_ptr(parent, st); const auto raw = label.data(); - if (!context.customEmojiRepaint) { - context.customEmojiRepaint = [=] { raw->update(); }; - } + + context.repaint = [=] { raw->update(); }; std::move(text) | rpl::start_with_next([=](const TextWithEntities &text) { raw->setMarkedText(text, context); }, label->lifetime()); diff --git a/Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.h b/Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.h index f22e4e801..662ce0fa7 100644 --- a/Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.h +++ b/Telegram/SourceFiles/ui/widgets/label_with_custom_emoji.h @@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "core/ui_integration.h" // Core::MarkedTextContext. - template class object_ptr; @@ -20,16 +18,18 @@ namespace style { struct FlatLabel; } // namespace style -namespace Ui { -class FlatLabel; -} // namespace Ui +namespace Ui::Text { +struct MarkedContext; +} // namespace Ui::Text namespace Ui { +class FlatLabel; + [[nodiscard]] object_ptr CreateLabelWithCustomEmoji( QWidget *parent, rpl::producer &&text, - Core::MarkedTextContext context, + Text::MarkedContext context, const style::FlatLabel &st); } // namespace Ui diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 19d557e72..8a8ccea36 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -949,10 +949,10 @@ void Notification::updateNotifyDisplay() { 0, Qt::LayoutDirectionAuto, }; - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &_history->session(), - .customEmojiRepaint = [=] { customEmojiCallback(); }, - }; + .repaint = [=] { customEmojiCallback(); }, + }); _textCache.setMarkedText( st::dialogsTextStyle, text, @@ -988,10 +988,10 @@ void Notification::updateNotifyDisplay() { const auto fullTitle = manager()->addTargetAccountName( std::move(title), &_history->session()); - const auto context = Core::MarkedTextContext{ + const auto context = Core::TextContext({ .session = &_history->session(), - .customEmojiRepaint = [=] { customEmojiCallback(); }, - }; + .repaint = [=] { customEmojiCallback(); }, + }); _titleCache.setMarkedText( st::semiboldTextStyle, fullTitle, diff --git a/Telegram/SourceFiles/window/window_filters_menu.cpp b/Telegram/SourceFiles/window/window_filters_menu.cpp index 829a84856..1e71a84b7 100644 --- a/Telegram/SourceFiles/window/window_filters_menu.cpp +++ b/Telegram/SourceFiles/window/window_filters_menu.cpp @@ -253,13 +253,6 @@ base::unique_qptr FiltersMenu::prepareButton( Ui::FilterIcon icon, bool toBeginning) { const auto isStatic = title.isStatic; - const auto makeContext = [=](Fn update) { - return Core::MarkedTextContext{ - .session = &_session->session(), - .customEmojiRepaint = std::move(update), - .customEmojiLoopLimit = isStatic ? -1 : 0, - }; - }; const auto paused = [=] { return On(PowerSaving::kEmojiChat) || _session->isGifPausedAtLeastFor(Window::GifPauseReason::Any); @@ -268,7 +261,10 @@ base::unique_qptr FiltersMenu::prepareButton( container, id ? title.text : TextWithEntities{ tr::lng_filters_all(tr::now) }, st::windowFiltersButton, - makeContext, + Core::TextContext({ + .session = &_session->session(), + .customEmojiLoopLimit = isStatic ? -1 : 0, + }), paused); auto added = toBeginning ? container->insert(0, std::move(prepared)) diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index cf75dc76d..18783480e 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -172,12 +172,6 @@ private: [[nodiscard]] Ui::CollectibleDetails PrepareCollectibleDetails( not_null session) { - const auto makeContext = [=] { - return Core::MarkedTextContext{ - .session = session, - .customEmojiRepaint = [] {}, - }; - }; return { .tonEmoji = Ui::Text::SingleCustomEmoji( session->data().customEmojiManager().registerInternalEmoji( @@ -186,7 +180,7 @@ private: st::collectibleInfo.textFg->c), st::collectibleInfoTonMargins, true)), - .tonEmojiContext = makeContext, + .tonEmojiContext = Core::TextContext({ .session = session }), }; } diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 76f254814..e51fe382b 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 76f25481470faee2e0a24aa7be8c6d58564addea +Subproject commit e51fe382bda9f2944412078da70f04de5dd821f3