Allow overriding Ui::SettingsButton padding.

This commit is contained in:
John Preston 2022-02-10 12:22:35 +03:00
parent c1f44ca8c7
commit 43c61172d8
2 changed files with 18 additions and 8 deletions

View file

@ -690,7 +690,8 @@ SettingsButton::SettingsButton(
rpl::producer<QString> &&text, rpl::producer<QString> &&text,
const style::SettingsButton &st) const style::SettingsButton &st)
: RippleButton(parent, st.ripple) : RippleButton(parent, st.ripple)
, _st(st) { , _st(st)
, _padding(_st.padding) {
std::move( std::move(
text text
) | rpl::start_with_next([this](QString &&value) { ) | rpl::start_with_next([this](QString &&value) {
@ -736,11 +737,17 @@ rpl::producer<bool> SettingsButton::toggledValue() const {
return nullptr; return nullptr;
} }
void SettingsButton::setColorOverride(std::optional<QColor> textColorOverride) { void SettingsButton::setColorOverride(
std::optional<QColor> textColorOverride) {
_textColorOverride = textColorOverride; _textColorOverride = textColorOverride;
update(); update();
} }
void SettingsButton::setPaddingOverride(style::margins padding) {
_padding = padding;
resizeToWidth(widthNoMargins());
}
const style::SettingsButton &SettingsButton::st() const { const style::SettingsButton &SettingsButton::st() const {
return _st; return _st;
} }
@ -773,8 +780,8 @@ void SettingsButton::paintText(Painter &p, bool over, int outerw) const {
? _st.textFgOver ? _st.textFgOver
: _st.textFg); : _st.textFg);
p.drawTextLeft( p.drawTextLeft(
_st.padding.left(), _padding.left(),
_st.padding.top(), _padding.top(),
outerw, outerw,
_text, _text,
_textWidth); _textWidth);
@ -798,7 +805,7 @@ QRect SettingsButton::toggleRect() const {
int SettingsButton::resizeGetHeight(int newWidth) { int SettingsButton::resizeGetHeight(int newWidth) {
updateVisibleText(newWidth); updateVisibleText(newWidth);
return _st.padding.top() + _st.height + _st.padding.bottom(); return _padding.top() + _st.height + _padding.bottom();
} }
void SettingsButton::onStateChanged( void SettingsButton::onStateChanged(
@ -821,8 +828,8 @@ void SettingsButton::setText(QString &&text) {
void SettingsButton::updateVisibleText(int newWidth) { void SettingsButton::updateVisibleText(int newWidth) {
auto availableWidth = newWidth auto availableWidth = newWidth
- _st.padding.left() - _padding.left()
- _st.padding.right(); - _padding.right();
if (_toggle) { if (_toggle) {
availableWidth -= (width() - toggleRect().x()); availableWidth -= (width() - toggleRect().x());
} }

View file

@ -266,6 +266,9 @@ public:
rpl::producer<bool> toggledValue() const; rpl::producer<bool> toggledValue() const;
void setColorOverride(std::optional<QColor> textColorOverride); void setColorOverride(std::optional<QColor> textColorOverride);
void setPaddingOverride(style::margins padding);
[[nodiscard]] const style::SettingsButton &st() const;
protected: protected:
int resizeGetHeight(int newWidth) override; int resizeGetHeight(int newWidth) override;
@ -275,7 +278,6 @@ protected:
void paintEvent(QPaintEvent *e) override; void paintEvent(QPaintEvent *e) override;
const style::SettingsButton &st() const;
void paintBg(Painter &p, const QRect &rect, bool over) const; void paintBg(Painter &p, const QRect &rect, bool over) const;
void paintText(Painter &p, bool over, int outerw) const; void paintText(Painter &p, bool over, int outerw) const;
void paintToggle(Painter &p, int outerw) const; void paintToggle(Painter &p, int outerw) const;
@ -286,6 +288,7 @@ private:
void updateVisibleText(int newWidth); void updateVisibleText(int newWidth);
const style::SettingsButton &_st; const style::SettingsButton &_st;
style::margins _padding;
QString _original; QString _original;
QString _text; QString _text;
int _originalWidth = 0; int _originalWidth = 0;