From 7e01b1282585f5783d0bae77a6fa212c8a242a49 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 12 Jun 2024 17:50:30 +0300 Subject: [PATCH] Replaced credits currency with icon in buttons of reply keyboard. --- .../history/history_item_components.cpp | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 60c29e7ee4..dde906494d 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/spoiler_mess.h" #include "ui/image/image.h" #include "ui/toast/toast.h" +#include "ui/text/format_values.h" #include "ui/text/text_options.h" #include "ui/text/text_utilities.h" #include "ui/chat/chat_style.h" @@ -48,9 +49,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "window/window_session_controller.h" #include "api/api_bot.h" -#include "styles/style_widgets.h" +#include "styles/style_boxes.h" #include "styles/style_chat.h" #include "styles/style_dialogs.h" // dialogsMiniReplyStory. +#include "styles/style_settings.h" +#include "styles/style_widgets.h" #include @@ -679,6 +682,11 @@ ReplyKeyboard::ReplyKeyboard( const auto context = _item->fullId(); const auto rowCount = int(markup->data.rows.size()); _rows.reserve(rowCount); + const auto buttonEmoji = Ui::Text::SingleCustomEmoji( + owner->customEmojiManager().registerInternalEmoji( + st::settingsPremiumIconStar, + QMargins(0, -st::moderateBoxExpandInnerSkip, 0, 0), + true)); for (auto i = 0; i != rowCount; ++i) { const auto &row = markup->data.rows[i]; const auto rowSize = int(row.size()); @@ -686,17 +694,44 @@ ReplyKeyboard::ReplyKeyboard( newRow.reserve(rowSize); for (auto j = 0; j != rowSize; ++j) { auto button = Button(); - const auto text = row[j].text; + const auto text = base::duplicate(row[j].text).replace( + Ui::kCreditsCurrency, + QChar(0x2B50)); + const auto textWithEntities = [&] { + auto result = TextWithEntities(); + auto firstPart = true; + for (const auto &part : text.split(QChar(0x2B50))) { + if (!firstPart) { + result.append(buttonEmoji); + } + result.append(part); + firstPart = false; + } + return result.entities.empty() + ? TextWithEntities() + : result; + }(); button.type = row.at(j).type; button.link = std::make_shared( owner, i, j, context); - button.text.setText( - _st->textStyle(), - TextUtilities::SingleLine(text), - kPlainTextOptions); + if (!textWithEntities.text.isEmpty()) { + button.text.setMarkedText( + _st->textStyle(), + TextUtilities::SingleLine(textWithEntities), + kMarkupTextOptions, + Core::MarkedTextContext{ + .session = &item->history()->owner().session(), + .customEmojiRepaint = [=] { _st->repaint(item); }, + }); + } else { + button.text.setText( + _st->textStyle(), + TextUtilities::SingleLine(text), + kPlainTextOptions); + } button.characters = text.isEmpty() ? 1 : text.size(); newRow.push_back(std::move(button)); }