From 5ba5f5ce6c332840ac3415194dd4c98535b0e45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Mon, 19 Apr 2021 21:17:40 +0800 Subject: [PATCH] add sizeThatFits in scroller node --- doric-Qt/doric/shader/DoricScrollerNode.cpp | 12 +++++++++-- doric-Qt/doric/shader/DoricScrollerNode.h | 2 ++ doric-Qt/doric/utils/DoricLayouts.cpp | 23 ++++++++++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/doric-Qt/doric/shader/DoricScrollerNode.cpp b/doric-Qt/doric/shader/DoricScrollerNode.cpp index 9d797141..988e39af 100644 --- a/doric-Qt/doric/shader/DoricScrollerNode.cpp +++ b/doric-Qt/doric/shader/DoricScrollerNode.cpp @@ -13,8 +13,6 @@ QQuickItem *DoricScrollerNode::build() { QQuickItem *item = qobject_cast(component.create()); this->createLayouts(item); - getLayouts()->setLayoutType(DoricLayoutType::DoricStack); - item->setProperty("wrapper", QString::number((qint64)this)); return item; } @@ -109,3 +107,13 @@ void DoricScrollerNode::blendSubNode(QJsonValue subProperties) { mChildNode->blend(subProperties["props"]); } } + +QSizeF DoricScrollerNode::sizeThatFits(QSizeF size) { + DoricLayouts *layout = (DoricLayouts *)mChildNode->getNodeView() + ->property("doricLayout") + .toULongLong(); + layout->apply(size); + + return QSizeF(qMin(size.width(), layout->getMeasuredWidth()), + qMin(size.height(), layout->getMeasuredHeight())); +} diff --git a/doric-Qt/doric/shader/DoricScrollerNode.h b/doric-Qt/doric/shader/DoricScrollerNode.h index 9473c1dc..98048551 100644 --- a/doric-Qt/doric/shader/DoricScrollerNode.h +++ b/doric-Qt/doric/shader/DoricScrollerNode.h @@ -23,6 +23,8 @@ public: virtual void afterBlended(QJsonValue jsValue) override; virtual void requestLayout() override; + + QSizeF sizeThatFits(QSizeF size); }; #endif // DORICSCROLLERNODE_H diff --git a/doric-Qt/doric/utils/DoricLayouts.cpp b/doric-Qt/doric/utils/DoricLayouts.cpp index 1ebc1dab..e3f13a00 100644 --- a/doric-Qt/doric/utils/DoricLayouts.cpp +++ b/doric-Qt/doric/utils/DoricLayouts.cpp @@ -1,4 +1,5 @@ #include "DoricLayouts.h" +#include "shader/DoricScrollerNode.h" DoricLayouts::DoricLayouts(QObject *parent) : QObject(parent) { this->widthSpec = DoricLayoutSpec::DoricLayoutJust; @@ -222,15 +223,27 @@ void DoricLayouts::measureContent(QSizeF targetSize) { } void DoricLayouts::measureUndefinedContent(QSizeF targetSize) { + // begin size that fits qreal width = this->view->width(); qreal height = this->view->height(); - if (width > targetSize.width()) { - width = targetSize.width(); - } - if (height > targetSize.height()) { - height = targetSize.height(); + if (tag == "Scroller") { + QObject *object = + (QObject *)(this->view->property("wrapper").toULongLong()); + DoricScrollerNode *viewNode = dynamic_cast(object); + QSizeF measuredSize = viewNode->sizeThatFits(targetSize); + width = measuredSize.width(); + height = measuredSize.height(); + } else { + if (width > targetSize.width()) { + width = targetSize.width(); + } + if (height > targetSize.height()) { + height = targetSize.height(); + } } + // end size that fits + if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) { setMeasuredWidth(width + this->paddingLeft + this->paddingRight); }