From 43c61172d8d2ef08c2c190d6b3425823727ea9c9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 10 Feb 2022 12:22:35 +0300 Subject: [PATCH] Allow overriding Ui::SettingsButton padding. --- ui/widgets/buttons.cpp | 21 ++++++++++++++------- ui/widgets/buttons.h | 5 ++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ui/widgets/buttons.cpp b/ui/widgets/buttons.cpp index 4519357..b624afc 100644 --- a/ui/widgets/buttons.cpp +++ b/ui/widgets/buttons.cpp @@ -690,7 +690,8 @@ SettingsButton::SettingsButton( rpl::producer &&text, const style::SettingsButton &st) : RippleButton(parent, st.ripple) -, _st(st) { +, _st(st) +, _padding(_st.padding) { std::move( text ) | rpl::start_with_next([this](QString &&value) { @@ -736,11 +737,17 @@ rpl::producer SettingsButton::toggledValue() const { return nullptr; } -void SettingsButton::setColorOverride(std::optional textColorOverride) { +void SettingsButton::setColorOverride( + std::optional textColorOverride) { _textColorOverride = textColorOverride; update(); } +void SettingsButton::setPaddingOverride(style::margins padding) { + _padding = padding; + resizeToWidth(widthNoMargins()); +} + const style::SettingsButton &SettingsButton::st() const { return _st; } @@ -773,8 +780,8 @@ void SettingsButton::paintText(Painter &p, bool over, int outerw) const { ? _st.textFgOver : _st.textFg); p.drawTextLeft( - _st.padding.left(), - _st.padding.top(), + _padding.left(), + _padding.top(), outerw, _text, _textWidth); @@ -798,7 +805,7 @@ QRect SettingsButton::toggleRect() const { int SettingsButton::resizeGetHeight(int newWidth) { updateVisibleText(newWidth); - return _st.padding.top() + _st.height + _st.padding.bottom(); + return _padding.top() + _st.height + _padding.bottom(); } void SettingsButton::onStateChanged( @@ -821,8 +828,8 @@ void SettingsButton::setText(QString &&text) { void SettingsButton::updateVisibleText(int newWidth) { auto availableWidth = newWidth - - _st.padding.left() - - _st.padding.right(); + - _padding.left() + - _padding.right(); if (_toggle) { availableWidth -= (width() - toggleRect().x()); } diff --git a/ui/widgets/buttons.h b/ui/widgets/buttons.h index 0e0c835..8be2672 100644 --- a/ui/widgets/buttons.h +++ b/ui/widgets/buttons.h @@ -266,6 +266,9 @@ public: rpl::producer toggledValue() const; void setColorOverride(std::optional textColorOverride); + void setPaddingOverride(style::margins padding); + + [[nodiscard]] const style::SettingsButton &st() const; protected: int resizeGetHeight(int newWidth) override; @@ -275,7 +278,6 @@ protected: void paintEvent(QPaintEvent *e) override; - const style::SettingsButton &st() const; void paintBg(Painter &p, const QRect &rect, bool over) const; void paintText(Painter &p, bool over, int outerw) const; void paintToggle(Painter &p, int outerw) const; @@ -286,6 +288,7 @@ private: void updateVisibleText(int newWidth); const style::SettingsButton &_st; + style::margins _padding; QString _original; QString _text; int _originalWidth = 0;