From 9d07d6a476f057c55af9392804c3e8b6246c637c Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 1 May 2022 02:35:42 +0300 Subject: [PATCH] Added ability to append pinned to top content to generic box. --- ui/layers/generic_box.cpp | 25 +++++++++++++++++++++++-- ui/layers/generic_box.h | 10 +++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ui/layers/generic_box.cpp b/ui/layers/generic_box.cpp index 447bf8c..fe90bce 100644 --- a/ui/layers/generic_box.cpp +++ b/ui/layers/generic_box.cpp @@ -16,15 +16,36 @@ namespace Ui { void GenericBox::prepare() { _init(this); + const auto currentWidth = width(); + if (_pinnedToTopContent) { + _pinnedToTopContent->resizeToWidth(currentWidth); + } + auto wrap = object_ptr(this, std::move(_owned)); - setDimensionsToContent(_width ? _width : st::boxWidth, wrap.data()); - setInnerWidget(std::move(wrap)); + setDimensionsToContent(currentWidth, wrap.data()); + setInnerWidget( + std::move(wrap), + _pinnedToTopContent ? _pinnedToTopContent->height() : 0); } void GenericBox::addSkip(int height) { addRow(object_ptr(this, height)); } +not_null GenericBox::setPinnedToTopContent( + object_ptr layout) { + _pinnedToTopContent = std::move(layout); + return _pinnedToTopContent.data(); +} + +int GenericBox::rowsCount() const { + return _content->count(); +} + +int GenericBox::width() const { + return _width ? _width : st::boxWidth; +} + not_null GenericBox::verticalLayout() { return _content; } diff --git a/ui/layers/generic_box.h b/ui/layers/generic_box.h index b6832f8..4214375 100644 --- a/ui/layers/generic_box.h +++ b/ui/layers/generic_box.h @@ -42,9 +42,8 @@ public: _showFinished = callback; } - int rowsCount() const { - return _content->count(); - } + [[nodiscard]] int rowsCount() const; + [[nodiscard]] int width() const; template < typename Widget, @@ -85,6 +84,9 @@ public: } } + not_null setPinnedToTopContent( + object_ptr layout); + [[nodiscard]] not_null verticalLayout(); using BoxContent::setNoContentMargin; @@ -124,6 +126,8 @@ private: not_null _content; int _width = 0; + object_ptr _pinnedToTopContent = { nullptr }; + }; template