add sizeThatFits in scroller node
This commit is contained in:
parent
77e32d1f08
commit
5ba5f5ce6c
@ -13,8 +13,6 @@ QQuickItem *DoricScrollerNode::build() {
|
|||||||
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
||||||
this->createLayouts(item);
|
this->createLayouts(item);
|
||||||
|
|
||||||
getLayouts()->setLayoutType(DoricLayoutType::DoricStack);
|
|
||||||
|
|
||||||
item->setProperty("wrapper", QString::number((qint64)this));
|
item->setProperty("wrapper", QString::number((qint64)this));
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@ -109,3 +107,13 @@ void DoricScrollerNode::blendSubNode(QJsonValue subProperties) {
|
|||||||
mChildNode->blend(subProperties["props"]);
|
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()));
|
||||||
|
}
|
||||||
|
@ -23,6 +23,8 @@ public:
|
|||||||
virtual void afterBlended(QJsonValue jsValue) override;
|
virtual void afterBlended(QJsonValue jsValue) override;
|
||||||
|
|
||||||
virtual void requestLayout() override;
|
virtual void requestLayout() override;
|
||||||
|
|
||||||
|
QSizeF sizeThatFits(QSizeF size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DORICSCROLLERNODE_H
|
#endif // DORICSCROLLERNODE_H
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "DoricLayouts.h"
|
#include "DoricLayouts.h"
|
||||||
|
#include "shader/DoricScrollerNode.h"
|
||||||
|
|
||||||
DoricLayouts::DoricLayouts(QObject *parent) : QObject(parent) {
|
DoricLayouts::DoricLayouts(QObject *parent) : QObject(parent) {
|
||||||
this->widthSpec = DoricLayoutSpec::DoricLayoutJust;
|
this->widthSpec = DoricLayoutSpec::DoricLayoutJust;
|
||||||
@ -222,15 +223,27 @@ void DoricLayouts::measureContent(QSizeF targetSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DoricLayouts::measureUndefinedContent(QSizeF targetSize) {
|
void DoricLayouts::measureUndefinedContent(QSizeF targetSize) {
|
||||||
|
// begin size that fits
|
||||||
qreal width = this->view->width();
|
qreal width = this->view->width();
|
||||||
qreal height = this->view->height();
|
qreal height = this->view->height();
|
||||||
|
|
||||||
|
if (tag == "Scroller") {
|
||||||
|
QObject *object =
|
||||||
|
(QObject *)(this->view->property("wrapper").toULongLong());
|
||||||
|
DoricScrollerNode *viewNode = dynamic_cast<DoricScrollerNode *>(object);
|
||||||
|
QSizeF measuredSize = viewNode->sizeThatFits(targetSize);
|
||||||
|
width = measuredSize.width();
|
||||||
|
height = measuredSize.height();
|
||||||
|
} else {
|
||||||
if (width > targetSize.width()) {
|
if (width > targetSize.width()) {
|
||||||
width = targetSize.width();
|
width = targetSize.width();
|
||||||
}
|
}
|
||||||
if (height > targetSize.height()) {
|
if (height > targetSize.height()) {
|
||||||
height = targetSize.height();
|
height = targetSize.height();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// end size that fits
|
||||||
|
|
||||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||||
setMeasuredWidth(width + this->paddingLeft + this->paddingRight);
|
setMeasuredWidth(width + this->paddingLeft + this->paddingRight);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user