From 68b1b595a5142180682a08e7ba8110d990b619b8 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 21 Dec 2022 19:07:29 +0300 Subject: [PATCH] Fixed height of top bar with large subtext in premium settings. --- .../SourceFiles/settings/settings_premium.cpp | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/settings/settings_premium.cpp b/Telegram/SourceFiles/settings/settings_premium.cpp index 694f5a9a42..6eb7d375a9 100644 --- a/Telegram/SourceFiles/settings/settings_premium.cpp +++ b/Telegram/SourceFiles/settings/settings_premium.cpp @@ -397,6 +397,8 @@ public: virtual void setPaused(bool paused) = 0; virtual void setTextPosition(int x, int y) = 0; + [[nodiscard]] virtual rpl::producer additionalHeight() const = 0; + protected: void paintEdges(QPainter &p, const QBrush &brush) const; void paintEdges(QPainter &p) const; @@ -601,6 +603,8 @@ public: void setPaused(bool paused) override; void setTextPosition(int x, int y) override; + rpl::producer additionalHeight() const override; + protected: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; @@ -912,6 +916,10 @@ void TopBarUser::setTextPosition(int x, int y) { _smallTop.position = { x, y }; } +rpl::producer TopBarUser::additionalHeight() const { + return rpl::never(); +} + void TopBarUser::paintEvent(QPaintEvent *e) { auto p = QPainter(this); @@ -939,6 +947,8 @@ public: void setPaused(bool paused) override; void setTextPosition(int x, int y) override; + rpl::producer additionalHeight() const override; + protected: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; @@ -1020,6 +1030,13 @@ void TopBar::setTextPosition(int x, int y) { _titlePosition = { x, y }; } +rpl::producer TopBar::additionalHeight() const { + return _about->heightValue( + ) | rpl::map([l = st::settingsPremiumAbout.style.lineHeight](int height) { + return std::max(height - l * 2, 0); + }); +} + void TopBar::resizeEvent(QResizeEvent *e) { const auto progress = (e->size().height() - minimumHeight()) / float64(maximumHeight() - minimumHeight()); @@ -1530,12 +1547,25 @@ QPointer Premium::createPinnedToTop( content->setRoundEdges(wrap == Info::Wrap::Layer); }, content->lifetime()); - content->setMaximumHeight(isEmojiStatus - ? st::settingsPremiumUserHeight + TopTransitionSkip() - : st::settingsPremiumTopHeight); + const auto calculateMaximumHeight = [=] { + return isEmojiStatus + ? st::settingsPremiumUserHeight + TopTransitionSkip() + : st::settingsPremiumTopHeight; + }; + + content->setMaximumHeight(calculateMaximumHeight()); content->setMinimumHeight(st::infoLayerTopBarHeight); content->resize(content->width(), content->maximumHeight()); + content->additionalHeight( + ) | rpl::start_with_next([=](int additionalHeight) { + const auto wasMax = (content->height() == content->maximumHeight()); + content->setMaximumHeight(calculateMaximumHeight() + + additionalHeight); + if (wasMax) { + content->resize(content->width(), content->maximumHeight()); + } + }, content->lifetime()); _wrap.value( ) | rpl::start_with_next([=](Info::Wrap wrap) {