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,
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<bool> SettingsButton::toggledValue() const {
return nullptr;
}
void SettingsButton::setColorOverride(std::optional<QColor> textColorOverride) {
void SettingsButton::setColorOverride(
std::optional<QColor> 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());
}

View file

@ -266,6 +266,9 @@ public:
rpl::producer<bool> toggledValue() const;
void setColorOverride(std::optional<QColor> 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;