From 3721c856fb8f1a418050d0788a4a3cc7c7e6fb92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Fri, 7 May 2021 19:14:19 +0800 Subject: [PATCH] fix layout bug --- doric-Qt/example/doric/utils/DoricLayouts.cpp | 53 +++++++------------ 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/doric-Qt/example/doric/utils/DoricLayouts.cpp b/doric-Qt/example/doric/utils/DoricLayouts.cpp index b74897ad..b6501dd6 100644 --- a/doric-Qt/example/doric/utils/DoricLayouts.cpp +++ b/doric-Qt/example/doric/utils/DoricLayouts.cpp @@ -140,8 +140,12 @@ void DoricLayouts::measureSelf(QSizeF targetSize) { DoricLayouts *parentDoricLayout = (DoricLayouts *)(parent->property("doricLayout").toULongLong()); if (parentDoricLayout != nullptr && - parentDoricLayout->layoutType == DoricLayoutType::DoricHLayout && - this->weight > 0) { + parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit) { + width = targetSize.width(); + } else if (parentDoricLayout != nullptr && + parentDoricLayout->layoutType == + DoricLayoutType::DoricHLayout && + this->weight > 0) { width = 0; setMeasuredWidth(0); } else { @@ -223,15 +227,17 @@ void DoricLayouts::measureContent(QSizeF targetSize) { DoricLayouts *parentDoricLayout = (DoricLayouts *)(parent->property("doricLayout").toULongLong()); if (parentDoricLayout != nullptr) { - if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined && - parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit && + + if (parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit && this->widthSpec == DoricLayoutSpec::DoricLayoutMost) { - setMeasuredWidth(targetSize.width()); + setMeasuredWidth(this->contentWidth + this->paddingLeft + + this->paddingRight); } - if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined && - parentDoricLayout->heightSpec == DoricLayoutSpec::DoricLayoutFit && + + if (parentDoricLayout->heightSpec == DoricLayoutSpec::DoricLayoutFit && this->heightSpec == DoricLayoutSpec::DoricLayoutMost) { - setMeasuredHeight(targetSize.height()); + setMeasuredHeight(this->contentHeight + this->paddingTop + + this->paddingBottom); } } } @@ -515,12 +521,12 @@ void DoricLayouts::layoutStack() { if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit && layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) { layout->measuredWidth = - this->measuredWidth - layout->marginLeft - layout->marginRight; + this->contentWidth - layout->marginLeft - layout->marginRight; } if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit && layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) { layout->measuredHeight = - this->measuredHeight - layout->marginTop - layout->marginBottom; + this->contentHeight - layout->marginTop - layout->marginBottom; } layout->layout(); @@ -536,11 +542,7 @@ void DoricLayouts::layoutStack() { DoricGravity::DoricGravityCenterX) { layout->setMeasuredX(this->measuredWidth / 2 - layout->measuredWidth / 2); } else { - if (layout->marginLeft || layout->marginRight) { - layout->setMeasuredX(this->paddingLeft); - } else { - layout->setMeasuredX(0); - } + layout->setMeasuredX(this->paddingLeft); } if ((gravity & DoricGravity::DoricGravityTop) == @@ -555,11 +557,7 @@ void DoricLayouts::layoutStack() { layout->setMeasuredY(this->measuredHeight / 2 - layout->measuredHeight / 2); } else { - if (layout->marginTop || layout->marginBottom) { - layout->setMeasuredY(this->paddingTop); - } else { - layout->setMeasuredY(0); - } + layout->setMeasuredY(this->paddingTop); } if (!gravity) { @@ -613,12 +611,7 @@ void DoricLayouts::layoutVLayout() { if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit && layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) { layout->measuredWidth = - this->measuredWidth - layout->marginLeft - layout->marginRight; - } - if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit && - layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) { - layout->measuredHeight = this->measuredHeight - yStart - - layout->marginTop - layout->marginBottom; + this->contentWidth - layout->marginLeft - layout->marginRight; } layout->layout(); int gravity = layout->alignment | this->gravity; @@ -677,16 +670,10 @@ void DoricLayouts::layoutHLayout() { continue; } - if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit && - layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) { - layout->measuredWidth = this->measuredWidth - xStart - - layout->marginLeft - layout->marginRight; - } - if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit && layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) { layout->measuredHeight = - this->measuredHeight - layout->marginTop - layout->marginBottom; + this->contentHeight - layout->marginTop - layout->marginBottom; } layout->layout();