Support GenericBox max height / scroll style.

This commit is contained in:
John Preston 2022-10-06 17:03:32 +04:00
parent a755fa391e
commit f450dcf2c5
4 changed files with 26 additions and 12 deletions

View file

@ -103,10 +103,6 @@ QPointer<IconButton> BoxContent::addTopButton(
return result; return result;
} }
void BoxContent::setInner(object_ptr<TWidget> inner) {
setInner(std::move(inner), st::boxScroll);
}
void BoxContent::setInner( void BoxContent::setInner(
object_ptr<TWidget> inner, object_ptr<TWidget> inner,
const style::ScrollArea &st) { const style::ScrollArea &st) {

View file

@ -31,6 +31,10 @@ struct ScrollArea;
struct Box; struct Box;
} // namespace style } // namespace style
namespace st {
extern const style::ScrollArea &boxScroll;
} // namespace st
namespace Ui { namespace Ui {
class GenericBox; class GenericBox;
} // namespace Ui } // namespace Ui
@ -242,11 +246,11 @@ protected:
object_ptr<Widget> inner, object_ptr<Widget> inner,
int topSkip = 0, int topSkip = 0,
int bottomSkip = 0) { int bottomSkip = 0) {
auto result = QPointer<Widget>(inner.data()); return setInnerWidget(
setInnerTopSkip(topSkip); std::move(inner),
setInnerBottomSkip(bottomSkip); st::boxScroll,
setInner(std::move(inner)); topSkip,
return result; bottomSkip);
} }
template <typename Widget> template <typename Widget>
@ -265,7 +269,6 @@ protected:
private: private:
void finishPrepare(); void finishPrepare();
void finishScrollCreate(); void finishScrollCreate();
void setInner(object_ptr<TWidget> inner);
void setInner(object_ptr<TWidget> inner, const style::ScrollArea &st); void setInner(object_ptr<TWidget> inner, const style::ScrollArea &st);
void updateScrollAreaGeometry(); void updateScrollAreaGeometry();
void updateInnerVisibleTopBottom(); void updateInnerVisibleTopBottom();

View file

@ -29,10 +29,16 @@ void GenericBox::prepare() {
wrap->heightValue() wrap->heightValue()
) | rpl::start_with_next([=](int top, int height) { ) | rpl::start_with_next([=](int top, int height) {
setInnerTopSkip(top); setInnerTopSkip(top);
setDimensions(currentWidth, top + height); const auto desired = top + height;
setDimensions(
currentWidth,
_maxHeight ? std::min(desired, _maxHeight) : desired);
}, wrap->lifetime()); }, wrap->lifetime());
setInnerWidget(std::move(wrap), pinned ? pinned->height() : 0); setInnerWidget(
std::move(wrap),
_scrollSt ? *_scrollSt : st::boxScroll,
pinned ? pinned->height() : 0);
} }
void GenericBox::addSkip(int height) { void GenericBox::addSkip(int height) {

View file

@ -71,6 +71,13 @@ public:
void addSkip(int height); void addSkip(int height);
void setMaxHeight(int maxHeight) {
_maxHeight = maxHeight;
}
void setScrollStyle(const style::ScrollArea &st) {
_scrollSt = &st;
}
void setInnerFocus() override { void setInnerFocus() override {
if (_focus) { if (_focus) {
_focus(); _focus();
@ -128,7 +135,9 @@ private:
Fn<void()> _showFinished; Fn<void()> _showFinished;
object_ptr<Ui::VerticalLayout> _owned; object_ptr<Ui::VerticalLayout> _owned;
not_null<Ui::VerticalLayout*> _content; not_null<Ui::VerticalLayout*> _content;
const style::ScrollArea *_scrollSt = nullptr;
int _width = 0; int _width = 0;
int _maxHeight = 0;
object_ptr<Ui::RpWidget> _pinnedToTopContent = { nullptr }; object_ptr<Ui::RpWidget> _pinnedToTopContent = { nullptr };