From f450dcf2c5fa1dfa0ad1fda483421c6548ff4fbb Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 6 Oct 2022 17:03:32 +0400 Subject: [PATCH] Support GenericBox max height / scroll style. --- ui/layers/box_content.cpp | 4 ---- ui/layers/box_content.h | 15 +++++++++------ ui/layers/generic_box.cpp | 10 ++++++++-- ui/layers/generic_box.h | 9 +++++++++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ui/layers/box_content.cpp b/ui/layers/box_content.cpp index e1a0423..bd06178 100644 --- a/ui/layers/box_content.cpp +++ b/ui/layers/box_content.cpp @@ -103,10 +103,6 @@ QPointer BoxContent::addTopButton( return result; } -void BoxContent::setInner(object_ptr inner) { - setInner(std::move(inner), st::boxScroll); -} - void BoxContent::setInner( object_ptr inner, const style::ScrollArea &st) { diff --git a/ui/layers/box_content.h b/ui/layers/box_content.h index fa275f5..deeb8af 100644 --- a/ui/layers/box_content.h +++ b/ui/layers/box_content.h @@ -31,6 +31,10 @@ struct ScrollArea; struct Box; } // namespace style +namespace st { +extern const style::ScrollArea &boxScroll; +} // namespace st + namespace Ui { class GenericBox; } // namespace Ui @@ -242,11 +246,11 @@ protected: object_ptr inner, int topSkip = 0, int bottomSkip = 0) { - auto result = QPointer(inner.data()); - setInnerTopSkip(topSkip); - setInnerBottomSkip(bottomSkip); - setInner(std::move(inner)); - return result; + return setInnerWidget( + std::move(inner), + st::boxScroll, + topSkip, + bottomSkip); } template @@ -265,7 +269,6 @@ protected: private: void finishPrepare(); void finishScrollCreate(); - void setInner(object_ptr inner); void setInner(object_ptr inner, const style::ScrollArea &st); void updateScrollAreaGeometry(); void updateInnerVisibleTopBottom(); diff --git a/ui/layers/generic_box.cpp b/ui/layers/generic_box.cpp index 9e85910..e61ea3f 100644 --- a/ui/layers/generic_box.cpp +++ b/ui/layers/generic_box.cpp @@ -29,10 +29,16 @@ void GenericBox::prepare() { wrap->heightValue() ) | rpl::start_with_next([=](int top, int height) { setInnerTopSkip(top); - setDimensions(currentWidth, top + height); + const auto desired = top + height; + setDimensions( + currentWidth, + _maxHeight ? std::min(desired, _maxHeight) : desired); }, wrap->lifetime()); - setInnerWidget(std::move(wrap), pinned ? pinned->height() : 0); + setInnerWidget( + std::move(wrap), + _scrollSt ? *_scrollSt : st::boxScroll, + pinned ? pinned->height() : 0); } void GenericBox::addSkip(int height) { diff --git a/ui/layers/generic_box.h b/ui/layers/generic_box.h index 60bf1ef..f1a441c 100644 --- a/ui/layers/generic_box.h +++ b/ui/layers/generic_box.h @@ -71,6 +71,13 @@ public: void addSkip(int height); + void setMaxHeight(int maxHeight) { + _maxHeight = maxHeight; + } + void setScrollStyle(const style::ScrollArea &st) { + _scrollSt = &st; + } + void setInnerFocus() override { if (_focus) { _focus(); @@ -128,7 +135,9 @@ private: Fn _showFinished; object_ptr _owned; not_null _content; + const style::ScrollArea *_scrollSt = nullptr; int _width = 0; + int _maxHeight = 0; object_ptr _pinnedToTopContent = { nullptr };