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;
}
void BoxContent::setInner(object_ptr<TWidget> inner) {
setInner(std::move(inner), st::boxScroll);
}
void BoxContent::setInner(
object_ptr<TWidget> inner,
const style::ScrollArea &st) {

View file

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

View file

@ -29,10 +29,16 @@ void GenericBox::prepare() {
wrap->heightValue()
) | rpl::start_with_next([=](int top, int height) {
setInnerTopSkip(top);
setDimensions(currentWidth, top + height);
const auto desired = top + height;
setDimensions(
currentWidth,
_maxHeight ? std::min(desired, _maxHeight) : desired);
}, 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) {

View file

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