Added ability to append pinned to bottom content to settings sections.

This commit is contained in:
23rd 2022-05-03 18:43:04 +03:00
parent 972666440e
commit 5fb71cb165
5 changed files with 45 additions and 8 deletions

View File

@ -61,7 +61,9 @@ ContentWidget::ContentWidget(
refreshSearchField(shown);
}, lifetime());
}
_scrollTopSkip.changes(
rpl::merge(
_scrollTopSkip.changes(),
_scrollBottomSkip.changes()
) | rpl::start_with_next([this] {
updateControlsGeometry();
}, lifetime());
@ -79,7 +81,7 @@ void ContentWidget::updateControlsGeometry() {
auto newScrollTop = _scroll->scrollTop() + _topDelta;
auto scrollGeometry = rect().marginsRemoved(
QMargins(0, _scrollTopSkip.current(), 0, 0));
{ 0, _scrollTopSkip.current(), 0, _scrollBottomSkip.current() });
if (_scroll->geometry() != scrollGeometry) {
_scroll->setGeometry(scrollGeometry);
}
@ -159,9 +161,11 @@ Ui::RpWidget *ContentWidget::doSetInnerWidget(
}
int ContentWidget::scrollTillBottom(int forHeight) const {
auto scrollHeight = forHeight - _scrollTopSkip.current();
auto scrollBottom = _scroll->scrollTop() + scrollHeight;
auto desired = _innerDesiredHeight;
const auto scrollHeight = forHeight
- _scrollTopSkip.current()
- _scrollBottomSkip.current();
const auto scrollBottom = _scroll->scrollTop() + scrollHeight;
const auto desired = _innerDesiredHeight;
return std::max(desired - scrollBottom, 0);
}
@ -173,6 +177,10 @@ void ContentWidget::setScrollTopSkip(int scrollTopSkip) {
_scrollTopSkip = scrollTopSkip;
}
void ContentWidget::setScrollBottomSkip(int scrollBottomSkip) {
_scrollBottomSkip = scrollBottomSkip;
}
rpl::producer<int> ContentWidget::scrollHeightValue() const {
return _scroll->heightValue();
}
@ -187,8 +195,9 @@ rpl::producer<int> ContentWidget::desiredHeightValue() const {
using namespace rpl::mappers;
return rpl::combine(
_innerWrap->entity()->desiredHeightValue(),
_scrollTopSkip.value()
) | rpl::map(_1 + _2);
_scrollTopSkip.value(),
_scrollBottomSkip.value()
) | rpl::map(_1 + _2 + _3);
}
rpl::producer<bool> ContentWidget::desiredShadowVisibility() const {

View File

@ -94,6 +94,7 @@ protected:
void paintEvent(QPaintEvent *e) override;
void setScrollTopSkip(int scrollTopSkip);
void setScrollBottomSkip(int scrollBottomSkip);
int scrollTopSave() const;
void scrollTopRestore(int scrollTop);
void scrollTo(const Ui::ScrollToRequest &request);
@ -109,6 +110,7 @@ private:
style::color _bg;
rpl::variable<int> _scrollTopSkip = -1;
rpl::variable<int> _scrollBottomSkip = -1;
rpl::event_stream<int> _scrollTillBottomChanges;
object_ptr<Ui::ScrollArea> _scroll;
Ui::PaddingWrap<Ui::RpWidget> *_innerWrap = nullptr;

View File

@ -48,7 +48,8 @@ Widget::Widget(
, _inner(
setInnerWidget(
_type()->create(this, controller->parentController())))
, _pinnedToTop(_inner->createPinnedToTop(this)) {
, _pinnedToTop(_inner->createPinnedToTop(this))
, _pinnedToBottom(_inner->createPinnedToBottom(this)) {
_inner->sectionShowOther(
) | rpl::start_with_next([=](Type type) {
controller->showSettings(type);
@ -81,6 +82,26 @@ Widget::Widget(
setScrollTopSkip(h);
}, _pinnedToTop->lifetime());
}
if (_pinnedToBottom) {
const auto processHeight = [=](int bottomHeight, int height) {
setScrollBottomSkip(bottomHeight);
_pinnedToBottom->moveToLeft(
_pinnedToBottom->x(),
height - bottomHeight);
};
_inner->sizeValue(
) | rpl::start_with_next([=](const QSize &s) {
_pinnedToBottom->resizeToWidth(s.width());
processHeight(_pinnedToBottom->height(), height());
}, _pinnedToBottom->lifetime());
rpl::combine(
_pinnedToBottom->heightValue(),
heightValue()
) | rpl::start_with_next(processHeight, _pinnedToBottom->lifetime());
}
}
Widget::~Widget() = default;

View File

@ -83,6 +83,7 @@ private:
not_null<::Settings::AbstractSection*> _inner;
QPointer<Ui::RpWidget> _pinnedToTop;
QPointer<Ui::RpWidget> _pinnedToBottom;
rpl::event_stream<std::vector<Type>> _removesFromStack;

View File

@ -96,6 +96,10 @@ public:
not_null<QWidget*> parent) {
return nullptr;
}
[[nodiscard]] virtual QPointer<Ui::RpWidget> createPinnedToBottom(
not_null<Ui::RpWidget*> parent) {
return nullptr;
}
};
template <typename SectionType>