From eab785a1c87e933bc8a8356570ed3919a7fb2ea6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 19 Apr 2024 12:58:59 +0400 Subject: [PATCH] Fix resizing LinkButton with padding. --- ui/widgets/buttons.cpp | 12 ++++++++---- ui/widgets/buttons.h | 2 ++ ui/widgets/widgets.style | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ui/widgets/buttons.cpp b/ui/widgets/buttons.cpp index 389f957..bc1e439 100644 --- a/ui/widgets/buttons.cpp +++ b/ui/widgets/buttons.cpp @@ -25,9 +25,7 @@ LinkButton::LinkButton( , _st(st) , _text(text) , _textWidth(st.font->width(_text)) { - resize( - naturalWidth(), - _st.padding.top() + _st.font->height + _st.padding.bottom()); + resizeToText(); setCursor(style::cur_pointer); } @@ -59,10 +57,16 @@ void LinkButton::paintEvent(QPaintEvent *e) { void LinkButton::setText(const QString &text) { _text = text; _textWidth = _st.font->width(_text); - resize(naturalWidth(), _st.font->height); + resizeToText(); update(); } +void LinkButton::resizeToText() { + resize( + naturalWidth(), + _st.padding.top() + _st.font->height + _st.padding.bottom()); +} + void LinkButton::setColorOverride(std::optional textFg) { _textFgOverride = textFg; update(); diff --git a/ui/widgets/buttons.h b/ui/widgets/buttons.h index d39f65e..9f57206 100644 --- a/ui/widgets/buttons.h +++ b/ui/widgets/buttons.h @@ -37,6 +37,8 @@ protected: void onStateChanged(State was, StateChangeSource source) override; private: + void resizeToText(); + const style::LinkButton &_st; QString _text; int _textWidth = 0; diff --git a/ui/widgets/widgets.style b/ui/widgets/widgets.style index 436e852..5c23204 100644 --- a/ui/widgets/widgets.style +++ b/ui/widgets/widgets.style @@ -1016,6 +1016,7 @@ SettingsSlider { labelStyle: TextStyle; labelFg: color; labelFgActive: color; + strictSkip: pixels; duration: int; rippleBottomSkip: pixels; rippleBg: color;