fix layout bug

This commit is contained in:
王劲鹏 2021-05-07 19:14:19 +08:00 committed by osborn
parent 0f2a6ef55c
commit 3721c856fb

View File

@ -140,7 +140,11 @@ void DoricLayouts::measureSelf(QSizeF targetSize) {
DoricLayouts *parentDoricLayout = DoricLayouts *parentDoricLayout =
(DoricLayouts *)(parent->property("doricLayout").toULongLong()); (DoricLayouts *)(parent->property("doricLayout").toULongLong());
if (parentDoricLayout != nullptr && if (parentDoricLayout != nullptr &&
parentDoricLayout->layoutType == DoricLayoutType::DoricHLayout && parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
width = targetSize.width();
} else if (parentDoricLayout != nullptr &&
parentDoricLayout->layoutType ==
DoricLayoutType::DoricHLayout &&
this->weight > 0) { this->weight > 0) {
width = 0; width = 0;
setMeasuredWidth(0); setMeasuredWidth(0);
@ -223,15 +227,17 @@ void DoricLayouts::measureContent(QSizeF targetSize) {
DoricLayouts *parentDoricLayout = DoricLayouts *parentDoricLayout =
(DoricLayouts *)(parent->property("doricLayout").toULongLong()); (DoricLayouts *)(parent->property("doricLayout").toULongLong());
if (parentDoricLayout != nullptr) { if (parentDoricLayout != nullptr) {
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit && if (parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
this->widthSpec == DoricLayoutSpec::DoricLayoutMost) { 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) { 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 && if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) { layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
layout->measuredWidth = layout->measuredWidth =
this->measuredWidth - layout->marginLeft - layout->marginRight; this->contentWidth - layout->marginLeft - layout->marginRight;
} }
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit && if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) { layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
layout->measuredHeight = layout->measuredHeight =
this->measuredHeight - layout->marginTop - layout->marginBottom; this->contentHeight - layout->marginTop - layout->marginBottom;
} }
layout->layout(); layout->layout();
@ -536,11 +542,7 @@ void DoricLayouts::layoutStack() {
DoricGravity::DoricGravityCenterX) { DoricGravity::DoricGravityCenterX) {
layout->setMeasuredX(this->measuredWidth / 2 - layout->measuredWidth / 2); layout->setMeasuredX(this->measuredWidth / 2 - layout->measuredWidth / 2);
} else { } else {
if (layout->marginLeft || layout->marginRight) {
layout->setMeasuredX(this->paddingLeft); layout->setMeasuredX(this->paddingLeft);
} else {
layout->setMeasuredX(0);
}
} }
if ((gravity & DoricGravity::DoricGravityTop) == if ((gravity & DoricGravity::DoricGravityTop) ==
@ -555,11 +557,7 @@ void DoricLayouts::layoutStack() {
layout->setMeasuredY(this->measuredHeight / 2 - layout->setMeasuredY(this->measuredHeight / 2 -
layout->measuredHeight / 2); layout->measuredHeight / 2);
} else { } else {
if (layout->marginTop || layout->marginBottom) {
layout->setMeasuredY(this->paddingTop); layout->setMeasuredY(this->paddingTop);
} else {
layout->setMeasuredY(0);
}
} }
if (!gravity) { if (!gravity) {
@ -613,12 +611,7 @@ void DoricLayouts::layoutVLayout() {
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit && if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) { layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
layout->measuredWidth = 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 - yStart -
layout->marginTop - layout->marginBottom;
} }
layout->layout(); layout->layout();
int gravity = layout->alignment | this->gravity; int gravity = layout->alignment | this->gravity;
@ -677,16 +670,10 @@ void DoricLayouts::layoutHLayout() {
continue; continue;
} }
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
layout->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
layout->measuredWidth = this->measuredWidth - xStart -
layout->marginLeft - layout->marginRight;
}
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit && if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) { layout->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
layout->measuredHeight = layout->measuredHeight =
this->measuredHeight - layout->marginTop - layout->marginBottom; this->contentHeight - layout->marginTop - layout->marginBottom;
} }
layout->layout(); layout->layout();