Allow pinned-to-bottom content in GenericBox.
This commit is contained in:
parent
127565a75b
commit
c36559a679
2 changed files with 39 additions and 8 deletions
|
|
@ -17,22 +17,28 @@ void GenericBox::prepare() {
|
||||||
_init(this);
|
_init(this);
|
||||||
|
|
||||||
const auto currentWidth = width();
|
const auto currentWidth = width();
|
||||||
const auto pinned = _pinnedToTopContent.data();
|
const auto pinnedToTop = _pinnedToTopContent.data();
|
||||||
if (pinned) {
|
const auto pinnedToBottom = _pinnedToBottomContent.data();
|
||||||
pinned->resizeToWidth(currentWidth);
|
if (pinnedToTop) {
|
||||||
|
pinnedToTop->resizeToWidth(currentWidth);
|
||||||
|
}
|
||||||
|
if (pinnedToBottom) {
|
||||||
|
pinnedToBottom->resizeToWidth(currentWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto wrap = object_ptr<Ui::OverrideMargins>(this, std::move(_owned));
|
auto wrap = object_ptr<Ui::OverrideMargins>(this, std::move(_owned));
|
||||||
wrap->resizeToWidth(currentWidth);
|
wrap->resizeToWidth(currentWidth);
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
pinned ? pinned->heightValue() : rpl::single(0),
|
pinnedToTop ? pinnedToTop->heightValue() : rpl::single(0),
|
||||||
wrap->heightValue()
|
wrap->heightValue(),
|
||||||
) | rpl::start_with_next([=](int top, int height) {
|
pinnedToBottom ? pinnedToBottom->heightValue() : rpl::single(0)
|
||||||
|
) | rpl::start_with_next([=](int top, int height, int bottom) {
|
||||||
Expects(_minHeight >= 0);
|
Expects(_minHeight >= 0);
|
||||||
Expects(!_maxHeight || _minHeight <= _maxHeight);
|
Expects(!_maxHeight || _minHeight <= _maxHeight);
|
||||||
|
|
||||||
setInnerTopSkip(top);
|
setInnerTopSkip(top);
|
||||||
const auto desired = top + height;
|
setInnerBottomSkip(bottom);
|
||||||
|
const auto desired = top + height + bottom;
|
||||||
setDimensions(
|
setDimensions(
|
||||||
currentWidth,
|
currentWidth,
|
||||||
std::clamp(
|
std::clamp(
|
||||||
|
|
@ -45,7 +51,17 @@ void GenericBox::prepare() {
|
||||||
setInnerWidget(
|
setInnerWidget(
|
||||||
std::move(wrap),
|
std::move(wrap),
|
||||||
_scrollSt ? *_scrollSt : st::boxScroll,
|
_scrollSt ? *_scrollSt : st::boxScroll,
|
||||||
pinned ? pinned->height() : 0);
|
pinnedToTop ? pinnedToTop->height() : 0,
|
||||||
|
pinnedToBottom ? pinnedToBottom->height() : 0);
|
||||||
|
|
||||||
|
if (pinnedToBottom) {
|
||||||
|
rpl::combine(
|
||||||
|
heightValue(),
|
||||||
|
pinnedToBottom->heightValue()
|
||||||
|
) | rpl::start_with_next([=](int outer, int height) {
|
||||||
|
pinnedToBottom->move(0, outer - height);
|
||||||
|
}, pinnedToBottom->lifetime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericBox::addSkip(int height) {
|
void GenericBox::addSkip(int height) {
|
||||||
|
|
@ -58,6 +74,12 @@ not_null<Ui::RpWidget*> GenericBox::doSetPinnedToTopContent(
|
||||||
return _pinnedToTopContent.data();
|
return _pinnedToTopContent.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
not_null<Ui::RpWidget*> GenericBox::doSetPinnedToBottomContent(
|
||||||
|
object_ptr<Ui::RpWidget> content) {
|
||||||
|
_pinnedToBottomContent = std::move(content);
|
||||||
|
return _pinnedToBottomContent.data();
|
||||||
|
}
|
||||||
|
|
||||||
int GenericBox::rowsCount() const {
|
int GenericBox::rowsCount() const {
|
||||||
return _content->count();
|
return _content->count();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,12 @@ public:
|
||||||
doSetPinnedToTopContent(std::move(content)).get());
|
doSetPinnedToTopContent(std::move(content)).get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Widget>
|
||||||
|
not_null<Widget*> setPinnedToBottomContent(object_ptr<Widget> content) {
|
||||||
|
return static_cast<Widget*>(
|
||||||
|
doSetPinnedToBottomContent(std::move(content)).get());
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] not_null<Ui::VerticalLayout*> verticalLayout();
|
[[nodiscard]] not_null<Ui::VerticalLayout*> verticalLayout();
|
||||||
|
|
||||||
using BoxContent::setNoContentMargin;
|
using BoxContent::setNoContentMargin;
|
||||||
|
|
@ -132,6 +138,8 @@ private:
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
not_null<Ui::RpWidget*> doSetPinnedToTopContent(
|
not_null<Ui::RpWidget*> doSetPinnedToTopContent(
|
||||||
object_ptr<Ui::RpWidget> content);
|
object_ptr<Ui::RpWidget> content);
|
||||||
|
not_null<Ui::RpWidget*> doSetPinnedToBottomContent(
|
||||||
|
object_ptr<Ui::RpWidget> content);
|
||||||
|
|
||||||
FnMut<void(not_null<GenericBox*>)> _init;
|
FnMut<void(not_null<GenericBox*>)> _init;
|
||||||
Fn<void()> _focus;
|
Fn<void()> _focus;
|
||||||
|
|
@ -144,6 +152,7 @@ private:
|
||||||
int _maxHeight = 0;
|
int _maxHeight = 0;
|
||||||
|
|
||||||
object_ptr<Ui::RpWidget> _pinnedToTopContent = { nullptr };
|
object_ptr<Ui::RpWidget> _pinnedToTopContent = { nullptr };
|
||||||
|
object_ptr<Ui::RpWidget> _pinnedToBottomContent = { nullptr };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue