mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +02:00
Added support of flexible scrollbar to Info::ContentWidget.
This commit is contained in:
parent
001aba4791
commit
9236dd3acb
6 changed files with 79 additions and 3 deletions
|
@ -225,6 +225,10 @@ int ContentWidget::scrollTopSave() const {
|
||||||
return _scroll->scrollTop();
|
return _scroll->scrollTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<int> ContentWidget::scrollTopValue() const {
|
||||||
|
return _scroll->scrollTopValue();
|
||||||
|
}
|
||||||
|
|
||||||
void ContentWidget::scrollTopRestore(int scrollTop) {
|
void ContentWidget::scrollTopRestore(int scrollTop) {
|
||||||
_scroll->scrollToY(scrollTop);
|
_scroll->scrollToY(scrollTop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,7 @@ protected:
|
||||||
int scrollTopSave() const;
|
int scrollTopSave() const;
|
||||||
void scrollTopRestore(int scrollTop);
|
void scrollTopRestore(int scrollTop);
|
||||||
void scrollTo(const Ui::ScrollToRequest &request);
|
void scrollTo(const Ui::ScrollToRequest &request);
|
||||||
|
[[nodiscard]] rpl::producer<int> scrollTopValue() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RpWidget *doSetInnerWidget(object_ptr<RpWidget> inner);
|
RpWidget *doSetInnerWidget(object_ptr<RpWidget> inner);
|
||||||
|
|
|
@ -44,9 +44,34 @@ Widget::Widget(
|
||||||
: ContentWidget(parent, controller)
|
: ContentWidget(parent, controller)
|
||||||
, _self(controller->key().settingsSelf())
|
, _self(controller->key().settingsSelf())
|
||||||
, _type(controller->section().settingsType())
|
, _type(controller->section().settingsType())
|
||||||
, _inner(
|
, _inner([&] {
|
||||||
setInnerWidget(
|
auto inner = _type()->create(this, controller->parentController());
|
||||||
_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))
|
, _pinnedToTop(_inner->createPinnedToTop(this))
|
||||||
, _pinnedToBottom(_inner->createPinnedToBottom(this)) {
|
, _pinnedToBottom(_inner->createPinnedToBottom(this)) {
|
||||||
_inner->sectionShowOther(
|
_inner->sectionShowOther(
|
||||||
|
@ -103,6 +128,39 @@ Widget::Widget(
|
||||||
heightValue()
|
heightValue()
|
||||||
) | rpl::start_with_next(processHeight, _pinnedToBottom->lifetime());
|
) | 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;
|
Widget::~Widget() = default;
|
||||||
|
|
|
@ -81,6 +81,10 @@ private:
|
||||||
not_null<UserData*> _self;
|
not_null<UserData*> _self;
|
||||||
Type _type = Type();
|
Type _type = Type();
|
||||||
|
|
||||||
|
struct {
|
||||||
|
rpl::event_stream<int> contentHeightValue;
|
||||||
|
rpl::event_stream<int> fillerWidthValue;
|
||||||
|
} _flexibleScroll;
|
||||||
not_null<::Settings::AbstractSection*> _inner;
|
not_null<::Settings::AbstractSection*> _inner;
|
||||||
QPointer<Ui::RpWidget> _pinnedToTop;
|
QPointer<Ui::RpWidget> _pinnedToTop;
|
||||||
QPointer<Ui::RpWidget> _pinnedToBottom;
|
QPointer<Ui::RpWidget> _pinnedToBottom;
|
||||||
|
|
|
@ -101,6 +101,9 @@ public:
|
||||||
not_null<Ui::RpWidget*> parent) {
|
not_null<Ui::RpWidget*> parent) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] virtual bool hasFlexibleTopBar() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
virtual void setStepDataReference(std::any &data) {
|
virtual void setStepDataReference(std::any &data) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,6 +44,8 @@ public:
|
||||||
[[nodiscard]] QPointer<Ui::RpWidget> createPinnedToBottom(
|
[[nodiscard]] QPointer<Ui::RpWidget> createPinnedToBottom(
|
||||||
not_null<Ui::RpWidget*> parent) override;
|
not_null<Ui::RpWidget*> parent) override;
|
||||||
|
|
||||||
|
[[nodiscard]] bool hasFlexibleTopBar() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupContent();
|
void setupContent();
|
||||||
|
|
||||||
|
@ -63,6 +65,10 @@ rpl::producer<QString> Premium::title() {
|
||||||
return tr::lng_premium_summary_title();
|
return tr::lng_premium_summary_title();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Premium::hasFlexibleTopBar() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Premium::setupContent() {
|
void Premium::setupContent() {
|
||||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue