Added ability to provide marked text to right label of settings button.

This commit is contained in:
23rd 2025-04-22 15:53:50 +03:00 committed by John Preston
parent d73e0dd13c
commit 9a4b73b942
2 changed files with 39 additions and 19 deletions

View file

@ -128,30 +128,50 @@ not_null<Button*> AddButtonWithIcon(
void CreateRightLabel( void CreateRightLabel(
not_null<Button*> button, not_null<Button*> button,
rpl::producer<QString> label, v::text::data &&label,
const style::SettingsButton &st, const style::SettingsButton &st,
rpl::producer<QString> buttonText) { rpl::producer<QString> buttonText) {
const auto name = Ui::CreateChild<Ui::FlatLabel>( const auto name = Ui::CreateChild<Ui::FlatLabel>(
button.get(), button.get(),
st.rightLabel); st.rightLabel);
name->show(); name->show();
rpl::combine( if (v::text::is_plain(label)) {
button->widthValue(), rpl::combine(
std::move(buttonText), button->widthValue(),
std::move(label) std::move(buttonText),
) | rpl::start_with_next([=, &st]( v::text::take_plain(std::move(label))
int width, ) | rpl::start_with_next([=, &st](
const QString &button, int width,
const QString &text) { const QString &button,
const auto available = width const QString &text) {
- st.padding.left() const auto available = width
- st.padding.right() - st.padding.left()
- st.style.font->width(button) - st.padding.right()
- st::settingsButtonRightSkip; - st.style.font->width(button)
name->setText(text); - st::settingsButtonRightSkip;
name->resizeToNaturalWidth(available); name->setText(text);
name->moveToRight(st::settingsButtonRightSkip, st.padding.top()); name->resizeToNaturalWidth(available);
}, name->lifetime()); 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); name->setAttribute(Qt::WA_TransparentForMouseEvents);
} }

View file

@ -178,7 +178,7 @@ not_null<Button*> AddButtonWithLabel(
IconDescriptor &&descriptor = {}); IconDescriptor &&descriptor = {});
void CreateRightLabel( void CreateRightLabel(
not_null<Button*> button, not_null<Button*> button,
rpl::producer<QString> label, v::text::data &&label,
const style::SettingsButton &st, const style::SettingsButton &st,
rpl::producer<QString> buttonText); rpl::producer<QString> buttonText);