add sizeThatFits in scroller node

This commit is contained in:
王劲鹏
2021-04-19 21:17:40 +08:00
committed by osborn
parent 77e32d1f08
commit 5ba5f5ce6c
3 changed files with 30 additions and 7 deletions

View File

@@ -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<DoricScrollerNode *>(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);
}