From 9a4b73b942bc42e3da010477bb66e972ae812a34 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 22 Apr 2025 15:53:50 +0300 Subject: [PATCH] Added ability to provide marked text to right label of settings button. --- .../SourceFiles/settings/settings_common.cpp | 56 +++++++++++++------ .../SourceFiles/settings/settings_common.h | 2 +- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/settings/settings_common.cpp b/Telegram/SourceFiles/settings/settings_common.cpp index 2cee2e2f56..f7e01594a2 100644 --- a/Telegram/SourceFiles/settings/settings_common.cpp +++ b/Telegram/SourceFiles/settings/settings_common.cpp @@ -128,30 +128,50 @@ not_null AddButtonWithIcon( void CreateRightLabel( not_null button, - rpl::producer label, + v::text::data &&label, const style::SettingsButton &st, rpl::producer buttonText) { const auto name = Ui::CreateChild( button.get(), st.rightLabel); name->show(); - rpl::combine( - button->widthValue(), - std::move(buttonText), - std::move(label) - ) | rpl::start_with_next([=, &st]( - int width, - const QString &button, - const QString &text) { - const auto available = width - - st.padding.left() - - st.padding.right() - - st.style.font->width(button) - - st::settingsButtonRightSkip; - name->setText(text); - name->resizeToNaturalWidth(available); - name->moveToRight(st::settingsButtonRightSkip, st.padding.top()); - }, name->lifetime()); + if (v::text::is_plain(label)) { + rpl::combine( + button->widthValue(), + std::move(buttonText), + v::text::take_plain(std::move(label)) + ) | rpl::start_with_next([=, &st]( + int width, + const QString &button, + const QString &text) { + const auto available = width + - st.padding.left() + - st.padding.right() + - st.style.font->width(button) + - st::settingsButtonRightSkip; + name->setText(text); + name->resizeToNaturalWidth(available); + name->moveToRight(st::settingsButtonRightSkip, st.padding.top()); + }, name->lifetime()); + } else if (v::text::is_marked(label)) { + rpl::combine( + button->widthValue(), + std::move(buttonText), + v::text::take_marked(std::move(label)) + ) | rpl::start_with_next([=, &st]( + int width, + const QString &button, + const TextWithEntities &text) { + const auto available = width + - st.padding.left() + - st.padding.right() + - st.style.font->width(button) + - st::settingsButtonRightSkip; + name->setMarkedText(text); + name->resizeToNaturalWidth(available); + name->moveToRight(st::settingsButtonRightSkip, st.padding.top()); + }, name->lifetime()); + } name->setAttribute(Qt::WA_TransparentForMouseEvents); } diff --git a/Telegram/SourceFiles/settings/settings_common.h b/Telegram/SourceFiles/settings/settings_common.h index 0f6c60e480..ce8c648e5a 100644 --- a/Telegram/SourceFiles/settings/settings_common.h +++ b/Telegram/SourceFiles/settings/settings_common.h @@ -178,7 +178,7 @@ not_null AddButtonWithLabel( IconDescriptor &&descriptor = {}); void CreateRightLabel( not_null button, - rpl::producer label, + v::text::data &&label, const style::SettingsButton &st, rpl::producer buttonText);