Added support of flexible scrollbar to Info::ContentWidget.

This commit is contained in:
23rd 2022-05-21 06:25:01 +03:00
parent 001aba4791
commit 9236dd3acb
6 changed files with 79 additions and 3 deletions

View file

@ -225,6 +225,10 @@ int ContentWidget::scrollTopSave() const {
return _scroll->scrollTop();
}
rpl::producer<int> ContentWidget::scrollTopValue() const {
return _scroll->scrollTopValue();
}
void ContentWidget::scrollTopRestore(int scrollTop) {
_scroll->scrollToY(scrollTop);
}

View file

@ -101,6 +101,7 @@ protected:
int scrollTopSave() const;
void scrollTopRestore(int scrollTop);
void scrollTo(const Ui::ScrollToRequest &request);
[[nodiscard]] rpl::producer<int> scrollTopValue() const;
private:
RpWidget *doSetInnerWidget(object_ptr<RpWidget> inner);

View file

@ -44,9 +44,34 @@ Widget::Widget(
: ContentWidget(parent, controller)
, _self(controller->key().settingsSelf())
, _type(controller->section().settingsType())
, _inner(
setInnerWidget(
_type()->create(this, controller->parentController())))
, _inner([&] {
auto inner = _type()->create(this, controller->parentController());
if (inner->hasFlexibleTopBar()) {
auto filler = setInnerWidget(object_ptr<Ui::RpWidget>(this));
filler->resize(1, 1);
_flexibleScroll.contentHeightValue.events(
) | rpl::start_with_next([=](int h) {
filler->resize(filler->width(), h);
}, filler->lifetime());
filler->widthValue(
) | rpl::start_to_stream(
_flexibleScroll.fillerWidthValue,
lifetime());
// ScrollArea -> PaddingWrap -> RpWidget.
inner->setParent(filler->parentWidget()->parentWidget());
inner->raise();
using InnerPtr = base::unique_qptr<::Settings::AbstractSection>;
auto owner = filler->lifetime().make_state<InnerPtr>(
std::move(inner.release()));
return owner->get();
} else {
return setInnerWidget(std::move(inner));
}
}())
, _pinnedToTop(_inner->createPinnedToTop(this))
, _pinnedToBottom(_inner->createPinnedToBottom(this)) {
_inner->sectionShowOther(
@ -103,6 +128,39 @@ Widget::Widget(
heightValue()
) | rpl::start_with_next(processHeight, _pinnedToBottom->lifetime());
}
if (_pinnedToTop
&& _pinnedToTop->minimumHeight()
&& _inner->hasFlexibleTopBar()) {
const auto heightDiff = [=] {
return _pinnedToTop->maximumHeight()
- _pinnedToTop->minimumHeight();
};
_inner->heightValue(
) | rpl::start_with_next([=](int h) {
_flexibleScroll.contentHeightValue.fire(h + heightDiff());
}, _pinnedToTop->lifetime());
scrollTopValue(
) | rpl::start_with_next([=](int top) {
if (!_pinnedToTop) {
return;
}
const auto current = heightDiff() - top;
_inner->moveToLeft(0, std::min(0, current));
_pinnedToTop->resize(
_pinnedToTop->width(),
std::max(current + _pinnedToTop->minimumHeight(), 0));
}, _inner->lifetime());
_flexibleScroll.fillerWidthValue.events(
) | rpl::start_with_next([=](int w) {
_inner->resizeToWidth(w);
}, _inner->lifetime());
setPaintPadding({ 0, _pinnedToTop->minimumHeight(), 0, 0 });
}
}
Widget::~Widget() = default;

View file

@ -81,6 +81,10 @@ private:
not_null<UserData*> _self;
Type _type = Type();
struct {
rpl::event_stream<int> contentHeightValue;
rpl::event_stream<int> fillerWidthValue;
} _flexibleScroll;
not_null<::Settings::AbstractSection*> _inner;
QPointer<Ui::RpWidget> _pinnedToTop;
QPointer<Ui::RpWidget> _pinnedToBottom;

View file

@ -101,6 +101,9 @@ public:
not_null<Ui::RpWidget*> parent) {
return nullptr;
}
[[nodiscard]] virtual bool hasFlexibleTopBar() const {
return false;
}
virtual void setStepDataReference(std::any &data) {
}
};

View file

@ -44,6 +44,8 @@ public:
[[nodiscard]] QPointer<Ui::RpWidget> createPinnedToBottom(
not_null<Ui::RpWidget*> parent) override;
[[nodiscard]] bool hasFlexibleTopBar() const override;
private:
void setupContent();
@ -63,6 +65,10 @@ rpl::producer<QString> Premium::title() {
return tr::lng_premium_summary_title();
}
bool Premium::hasFlexibleTopBar() const {
return true;
}
void Premium::setupContent() {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);