Added ability to append pinned to top content to generic box.

This commit is contained in:
23rd 2022-05-01 02:35:42 +03:00 committed by John Preston
parent 35c84d7d54
commit 9d07d6a476
2 changed files with 30 additions and 5 deletions

View file

@ -16,15 +16,36 @@ namespace Ui {
void GenericBox::prepare() { void GenericBox::prepare() {
_init(this); _init(this);
const auto currentWidth = width();
if (_pinnedToTopContent) {
_pinnedToTopContent->resizeToWidth(currentWidth);
}
auto wrap = object_ptr<Ui::OverrideMargins>(this, std::move(_owned)); auto wrap = object_ptr<Ui::OverrideMargins>(this, std::move(_owned));
setDimensionsToContent(_width ? _width : st::boxWidth, wrap.data()); setDimensionsToContent(currentWidth, wrap.data());
setInnerWidget(std::move(wrap)); setInnerWidget(
std::move(wrap),
_pinnedToTopContent ? _pinnedToTopContent->height() : 0);
} }
void GenericBox::addSkip(int height) { void GenericBox::addSkip(int height) {
addRow(object_ptr<Ui::FixedHeightWidget>(this, height)); addRow(object_ptr<Ui::FixedHeightWidget>(this, height));
} }
not_null<Ui::VerticalLayout*> GenericBox::setPinnedToTopContent(
object_ptr<Ui::VerticalLayout> 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<Ui::VerticalLayout*> GenericBox::verticalLayout() { not_null<Ui::VerticalLayout*> GenericBox::verticalLayout() {
return _content; return _content;
} }

View file

@ -42,9 +42,8 @@ public:
_showFinished = callback; _showFinished = callback;
} }
int rowsCount() const { [[nodiscard]] int rowsCount() const;
return _content->count(); [[nodiscard]] int width() const;
}
template < template <
typename Widget, typename Widget,
@ -85,6 +84,9 @@ public:
} }
} }
not_null<Ui::VerticalLayout*> setPinnedToTopContent(
object_ptr<Ui::VerticalLayout> layout);
[[nodiscard]] not_null<Ui::VerticalLayout*> verticalLayout(); [[nodiscard]] not_null<Ui::VerticalLayout*> verticalLayout();
using BoxContent::setNoContentMargin; using BoxContent::setNoContentMargin;
@ -124,6 +126,8 @@ private:
not_null<Ui::VerticalLayout*> _content; not_null<Ui::VerticalLayout*> _content;
int _width = 0; int _width = 0;
object_ptr<Ui::VerticalLayout> _pinnedToTopContent = { nullptr };
}; };
template <typename InitMethod, typename ...InitArgs> template <typename InitMethod, typename ...InitArgs>