diff --git a/ui/widgets/buttons.cpp b/ui/widgets/buttons.cpp index b624afc..6a98811 100644 --- a/ui/widgets/buttons.cpp +++ b/ui/widgets/buttons.cpp @@ -703,6 +703,7 @@ SettingsButton::~SettingsButton() = default; SettingsButton *SettingsButton::toggleOn(rpl::producer &&toggled) { Expects(_toggle == nullptr); + _toggle = std::make_unique( isOver() ? _st.toggleOver : _st.toggle, false, @@ -773,18 +774,24 @@ void SettingsButton::paintBg(Painter &p, const QRect &rect, bool over) const { } void SettingsButton::paintText(Painter &p, bool over, int outerw) const { - p.setFont(_st.font); + auto available = outerw - _padding.left() - _padding.right(); + if (_toggle) { + available -= (width() - toggleRect().x()); + } + if (available <= 0) { + return; + } p.setPen(_textColorOverride ? QPen(*_textColorOverride) : over ? _st.textFgOver : _st.textFg); - p.drawTextLeft( + _text.drawLeftElided( + p, _padding.left(), _padding.top(), - outerw, - _text, - _textWidth); + available, + outerw); } void SettingsButton::paintToggle(Painter &p, int outerw) const { @@ -804,7 +811,6 @@ QRect SettingsButton::toggleRect() const { } int SettingsButton::resizeGetHeight(int newWidth) { - updateVisibleText(newWidth); return _padding.top() + _st.height + _padding.bottom(); } @@ -821,26 +827,7 @@ void SettingsButton::onStateChanged( } void SettingsButton::setText(QString &&text) { - _original = std::move(text); - _originalWidth = _st.font->width(_original); - updateVisibleText(width()); -} - -void SettingsButton::updateVisibleText(int newWidth) { - auto availableWidth = newWidth - - _padding.left() - - _padding.right(); - if (_toggle) { - availableWidth -= (width() - toggleRect().x()); - } - accumulate_max(availableWidth, 0); - if (availableWidth < _originalWidth) { - _text = _st.font->elided(_original, availableWidth); - _textWidth = _st.font->width(_text); - } else { - _text = _original; - _textWidth = _originalWidth; - } + _text.setText(_st.style, text); update(); } diff --git a/ui/widgets/buttons.h b/ui/widgets/buttons.h index 8be2672..da408f6 100644 --- a/ui/widgets/buttons.h +++ b/ui/widgets/buttons.h @@ -9,6 +9,7 @@ #include "ui/abstract_button.h" #include "ui/round_rect.h" #include "ui/effects/animations.h" +#include "ui/text/text.h" #include "styles/style_widgets.h" #include @@ -285,14 +286,10 @@ protected: private: void setText(QString &&text); QRect toggleRect() const; - void updateVisibleText(int newWidth); const style::SettingsButton &_st; style::margins _padding; - QString _original; - QString _text; - int _originalWidth = 0; - int _textWidth = 0; + Ui::Text::String _text; std::unique_ptr _toggle; std::optional _textColorOverride; diff --git a/ui/widgets/widgets.style b/ui/widgets/widgets.style index 173bc1b..f17cf40 100644 --- a/ui/widgets/widgets.style +++ b/ui/widgets/widgets.style @@ -520,7 +520,7 @@ SettingsButton { textBg: color; textBgOver: color; - font: font; + style: TextStyle; rightLabel: FlatLabel; height: pixels; @@ -1393,7 +1393,7 @@ defaultSettingsButton: SettingsButton { textBg: windowBg; textBgOver: windowBgOver; - font: boxTextFont; + style: boxTextStyle; rightLabel: defaultSettingsRightLabel; height: 20px;