fix doric layout bug
This commit is contained in:
parent
46bcaeb772
commit
d231ae099f
@ -39,12 +39,12 @@ TextArea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onWidthChanged: {
|
onWidthChanged: {
|
||||||
// bg.implicitWidth = width
|
bg.implicitWidth = width
|
||||||
console.log(tag, uuid + " onWidthChanged: " + this.width)
|
console.log(tag, uuid + " onWidthChanged: " + this.width)
|
||||||
}
|
}
|
||||||
|
|
||||||
onHeightChanged: {
|
onHeightChanged: {
|
||||||
// bg.implicitHeight = height
|
bg.implicitHeight = height
|
||||||
console.log(tag, uuid + " onHeightChanged: " + this.height)
|
console.log(tag, uuid + " onHeightChanged: " + this.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ void DoricViewNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
|||||||
} else if (name == "x") {
|
} else if (name == "x") {
|
||||||
getLayouts()->setMarginLeft(prop.toInt());
|
getLayouts()->setMarginLeft(prop.toInt());
|
||||||
} else if (name == "y") {
|
} else if (name == "y") {
|
||||||
getLayouts()->setMarginRight(prop.toInt());
|
getLayouts()->setMarginTop(prop.toInt());
|
||||||
} else if (name == "corners") {
|
} else if (name == "corners") {
|
||||||
view->setProperty("radius", prop.toInt());
|
view->setProperty("radius", prop.toInt());
|
||||||
} else if (name == "onClick") {
|
} else if (name == "onClick") {
|
||||||
|
@ -1,12 +1,48 @@
|
|||||||
#include "DoricLayouts.h"
|
#include "DoricLayouts.h"
|
||||||
|
|
||||||
DoricLayouts::DoricLayouts() {
|
DoricLayouts::DoricLayouts(QObject *parent) : QObject(parent) {
|
||||||
this->widthSpec = DoricLayoutSpec::DoricLayoutJust;
|
this->widthSpec = DoricLayoutSpec::DoricLayoutJust;
|
||||||
this->heightSpec = DoricLayoutSpec::DoricLayoutJust;
|
this->heightSpec = DoricLayoutSpec::DoricLayoutJust;
|
||||||
this->maxWidth = 32767;
|
|
||||||
this->maxHeight = 32767;
|
this->alignment = 0;
|
||||||
|
this->gravity = 0;
|
||||||
|
|
||||||
|
this->width = 0;
|
||||||
|
this->height = 0;
|
||||||
|
|
||||||
|
this->spacing = 0;
|
||||||
|
|
||||||
|
this->marginBottom = 0;
|
||||||
|
this->marginTop = 0;
|
||||||
|
this->marginLeft = 0;
|
||||||
|
this->marginRight = 0;
|
||||||
|
|
||||||
|
this->paddingLeft = 0;
|
||||||
|
this->paddingRight = 0;
|
||||||
|
this->paddingBottom = 0;
|
||||||
|
this->paddingTop = 0;
|
||||||
|
|
||||||
|
this->weight = 0;
|
||||||
|
|
||||||
|
this->layoutType = DoricLayoutType::DoricUndefined;
|
||||||
|
|
||||||
|
this->disabled = false;
|
||||||
|
|
||||||
|
this->maxWidth = INT_MAX;
|
||||||
|
this->maxHeight = INT_MAX;
|
||||||
this->minWidth = 0;
|
this->minWidth = 0;
|
||||||
this->minHeight = 0;
|
this->minHeight = 0;
|
||||||
|
|
||||||
|
this->measuredWidth = 0;
|
||||||
|
this->measuredHeight = 0;
|
||||||
|
|
||||||
|
this->measuredX = 0;
|
||||||
|
this->measuredY = 0;
|
||||||
|
|
||||||
|
this->undefined = false;
|
||||||
|
|
||||||
|
this->contentWidth = 0;
|
||||||
|
this->contentHeight = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricLayouts::setWidthSpec(int widthSpec) { this->widthSpec = widthSpec; }
|
void DoricLayouts::setWidthSpec(int widthSpec) { this->widthSpec = widthSpec; }
|
||||||
@ -51,6 +87,7 @@ void DoricLayouts::setWeight(int weight) { this->weight = weight; }
|
|||||||
|
|
||||||
void DoricLayouts::setView(QQuickItem *view) {
|
void DoricLayouts::setView(QQuickItem *view) {
|
||||||
this->view = view;
|
this->view = view;
|
||||||
|
this->setParent(view);
|
||||||
this->tag = view->property("tag").toString();
|
this->tag = view->property("tag").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,15 +129,15 @@ void DoricLayouts::measureSelf(int targetWidth, int targetHeight) {
|
|||||||
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
|
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
|
||||||
if (parentDoricLayout->layoutType == DoricLayoutType::DoricHLayout &&
|
if (parentDoricLayout->layoutType == DoricLayoutType::DoricHLayout &&
|
||||||
this->weight > 0) {
|
this->weight > 0) {
|
||||||
width = this->measuredWidth = 0;
|
width = 0;
|
||||||
setMeasuredWidth();
|
setMeasuredWidth(0);
|
||||||
} else {
|
} else {
|
||||||
width = this->measuredWidth = targetWidth;
|
width = targetWidth;
|
||||||
setMeasuredWidth();
|
setMeasuredWidth(targetWidth);
|
||||||
}
|
}
|
||||||
} else if (this->widthSpec == DoricLayoutSpec::DoricLayoutJust) {
|
} else if (this->widthSpec == DoricLayoutSpec::DoricLayoutJust) {
|
||||||
width = this->measuredWidth = this->width;
|
width = this->width;
|
||||||
setMeasuredWidth();
|
setMeasuredWidth(this->width);
|
||||||
} else {
|
} else {
|
||||||
width = targetWidth;
|
width = targetWidth;
|
||||||
}
|
}
|
||||||
@ -113,12 +150,15 @@ void DoricLayouts::measureSelf(int targetWidth, int targetHeight) {
|
|||||||
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
|
(DoricLayouts *)(parent->property("doricLayout").toULongLong());
|
||||||
if (parentDoricLayout->layoutType == DoricLayoutType::DoricVLayout &&
|
if (parentDoricLayout->layoutType == DoricLayoutType::DoricVLayout &&
|
||||||
this->weight > 0) {
|
this->weight > 0) {
|
||||||
height = this->measuredHeight = 0;
|
height = 0;
|
||||||
|
setMeasuredHeight(0);
|
||||||
} else {
|
} else {
|
||||||
height = this->measuredHeight = targetHeight;
|
height = targetHeight;
|
||||||
|
setMeasuredHeight(targetHeight);
|
||||||
}
|
}
|
||||||
} else if (this->heightSpec == DoricLayoutSpec::DoricLayoutJust) {
|
} else if (this->heightSpec == DoricLayoutSpec::DoricLayoutJust) {
|
||||||
height = this->measuredHeight = this->height;
|
height = this->height;
|
||||||
|
setMeasuredHeight(this->height);
|
||||||
} else {
|
} else {
|
||||||
height = targetHeight;
|
height = targetHeight;
|
||||||
}
|
}
|
||||||
@ -137,6 +177,7 @@ void DoricLayouts::measureSelf(int targetWidth, int targetHeight) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DoricLayouts::measureContent(int targetWidth, int targetHeight) {
|
void DoricLayouts::measureContent(int targetWidth, int targetHeight) {
|
||||||
|
qCritical() << "measureContent: " << tag << this->view->property("uuid");
|
||||||
switch (this->layoutType) {
|
switch (this->layoutType) {
|
||||||
case DoricLayoutType::DoricStack: {
|
case DoricLayoutType::DoricStack: {
|
||||||
this->measureStackContent(targetWidth, targetHeight);
|
this->measureStackContent(targetWidth, targetHeight);
|
||||||
@ -163,13 +204,12 @@ void DoricLayouts::measureContent(int targetWidth, int targetHeight) {
|
|||||||
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
|
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
|
||||||
parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
|
parentDoricLayout->widthSpec == DoricLayoutSpec::DoricLayoutFit &&
|
||||||
this->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
this->widthSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||||
this->measuredWidth = 0;
|
setMeasuredWidth(0);
|
||||||
setMeasuredWidth();
|
|
||||||
}
|
}
|
||||||
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
|
if (parentDoricLayout->layoutType != DoricLayoutType::DoricUndefined &&
|
||||||
parentDoricLayout->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
|
parentDoricLayout->heightSpec == DoricLayoutSpec::DoricLayoutFit &&
|
||||||
this->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
this->heightSpec == DoricLayoutSpec::DoricLayoutMost) {
|
||||||
this->measuredHeight = 0;
|
setMeasuredHeight(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,11 +225,10 @@ void DoricLayouts::measureUndefinedContent(int targetWidth, int targetHeight) {
|
|||||||
height = targetHeight;
|
height = targetHeight;
|
||||||
}
|
}
|
||||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||||
this->measuredWidth = width + this->paddingLeft + this->paddingRight;
|
setMeasuredWidth(width + this->paddingLeft + this->paddingRight);
|
||||||
setMeasuredWidth();
|
|
||||||
}
|
}
|
||||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||||
this->measuredHeight = height + this->paddingTop + this->paddingBottom;
|
setMeasuredHeight(height + this->paddingTop + this->paddingBottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void DoricLayouts::measureStackContent(int targetWidth, int targetHeight) {
|
void DoricLayouts::measureStackContent(int targetWidth, int targetHeight) {
|
||||||
@ -211,13 +250,11 @@ void DoricLayouts::measureStackContent(int targetWidth, int targetHeight) {
|
|||||||
contentHeight = qMax(contentHeight, layout->takenHeight());
|
contentHeight = qMax(contentHeight, layout->takenHeight());
|
||||||
}
|
}
|
||||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||||
this->measuredWidth = contentWidth + this->paddingLeft + this->paddingRight;
|
setMeasuredWidth(contentWidth + this->paddingLeft + this->paddingRight);
|
||||||
setMeasuredWidth();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||||
this->measuredHeight =
|
setMeasuredHeight(contentHeight + this->paddingTop + this->paddingBottom);
|
||||||
contentHeight + this->paddingTop + this->paddingBottom;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->contentWidth = contentWidth;
|
this->contentWidth = contentWidth;
|
||||||
@ -277,13 +314,11 @@ void DoricLayouts::measureVLayoutContent(int targetWidth, int targetHeight) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||||
this->measuredWidth = contentWidth + this->paddingLeft + this->paddingRight;
|
setMeasuredWidth(contentWidth + this->paddingLeft + this->paddingRight);
|
||||||
setMeasuredWidth();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||||
this->measuredHeight =
|
setMeasuredHeight(contentHeight + this->paddingTop + this->paddingBottom);
|
||||||
contentHeight + this->paddingTop + this->paddingBottom;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->contentWidth = contentWidth;
|
this->contentWidth = contentWidth;
|
||||||
@ -342,13 +377,11 @@ void DoricLayouts::measureHLayoutContent(int targetWidth, int targetHeight) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
if (this->widthSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||||
this->measuredWidth = contentWidth + this->paddingLeft + this->paddingRight;
|
setMeasuredWidth(contentWidth + this->paddingLeft + this->paddingRight);
|
||||||
setMeasuredWidth();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
if (this->heightSpec == DoricLayoutSpec::DoricLayoutFit) {
|
||||||
this->measuredHeight =
|
setMeasuredHeight(contentHeight + this->paddingTop + this->paddingBottom);
|
||||||
contentHeight + this->paddingTop + this->paddingBottom;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->contentWidth = contentWidth;
|
this->contentWidth = contentWidth;
|
||||||
@ -370,21 +403,19 @@ QPair<int, int> DoricLayouts::removeMargin(int targetWidth, int targetHeight) {
|
|||||||
bool DoricLayouts::restrainSize() {
|
bool DoricLayouts::restrainSize() {
|
||||||
bool needRemeasure = false;
|
bool needRemeasure = false;
|
||||||
if (this->measuredWidth > this->maxWidth) {
|
if (this->measuredWidth > this->maxWidth) {
|
||||||
this->measuredWidth = this->maxWidth;
|
setMeasuredWidth(this->maxWidth);
|
||||||
setMeasuredWidth();
|
|
||||||
needRemeasure = true;
|
needRemeasure = true;
|
||||||
}
|
}
|
||||||
if (this->measuredHeight > this->maxHeight) {
|
if (this->measuredHeight > this->maxHeight) {
|
||||||
this->measuredHeight = this->maxHeight;
|
setMeasuredHeight(this->maxHeight);
|
||||||
needRemeasure = true;
|
needRemeasure = true;
|
||||||
}
|
}
|
||||||
if (this->measuredWidth < this->minWidth) {
|
if (this->measuredWidth < this->minWidth) {
|
||||||
this->measuredWidth = this->minWidth;
|
setMeasuredWidth(this->minWidth);
|
||||||
setMeasuredWidth();
|
|
||||||
needRemeasure = true;
|
needRemeasure = true;
|
||||||
}
|
}
|
||||||
if (this->measuredHeight < this->minHeight) {
|
if (this->measuredHeight < this->minHeight) {
|
||||||
this->measuredHeight = this->minHeight;
|
setMeasuredHeight(this->minHeight);
|
||||||
needRemeasure = true;
|
needRemeasure = true;
|
||||||
}
|
}
|
||||||
return needRemeasure;
|
return needRemeasure;
|
||||||
@ -423,6 +454,12 @@ void DoricLayouts::setFrame() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
||||||
|
<< " measuredHeight: " << this->measuredHeight
|
||||||
|
<< " measuredHeight: " << this->measuredHeight
|
||||||
|
<< " measuredX: " << this->measuredX
|
||||||
|
<< " measuredY: " << this->measuredY;
|
||||||
|
|
||||||
this->view->setProperty("width", this->measuredWidth);
|
this->view->setProperty("width", this->measuredWidth);
|
||||||
this->view->setProperty("height", this->measuredHeight);
|
this->view->setProperty("height", this->measuredHeight);
|
||||||
this->view->setProperty("x", this->measuredX);
|
this->view->setProperty("x", this->measuredX);
|
||||||
@ -649,12 +686,20 @@ void DoricLayouts::layoutHLayout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Private Section
|
// Private Section
|
||||||
void DoricLayouts::setMeasuredWidth() {
|
void DoricLayouts::setMeasuredWidth(int measuredWidth) {
|
||||||
|
this->measuredWidth = measuredWidth;
|
||||||
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
||||||
<< " measuredWidth: " << this->measuredWidth;
|
<< " measuredWidth: " << this->measuredWidth;
|
||||||
|
if (this->measuredWidth > 1000 || this->measuredWidth < 0) {
|
||||||
|
qDebug() << "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoricLayouts::setMeasuredHeight() {
|
void DoricLayouts::setMeasuredHeight(int measuredHeight) {
|
||||||
qCritical() << "DoricLayouts: " << tag
|
this->measuredHeight = measuredHeight;
|
||||||
|
qCritical() << "DoricLayouts: " << tag << this->view->property("uuid")
|
||||||
<< " measuredHeight: " << this->measuredHeight;
|
<< " measuredHeight: " << this->measuredHeight;
|
||||||
|
if (this->measuredHeight > 2000 || this->measuredHeight < 0) {
|
||||||
|
qDebug() << "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,9 @@ public:
|
|||||||
DoricGravityCenterX | DoricGravityCenterY;
|
DoricGravityCenterX | DoricGravityCenterY;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DoricLayouts {
|
class DoricLayouts : public QObject {
|
||||||
public:
|
public:
|
||||||
DoricLayouts();
|
explicit DoricLayouts(QObject *parent = nullptr);
|
||||||
|
|
||||||
void setWidthSpec(int widthSpec);
|
void setWidthSpec(int widthSpec);
|
||||||
void setHeightSpec(int heightSpec);
|
void setHeightSpec(int heightSpec);
|
||||||
@ -150,9 +150,9 @@ private:
|
|||||||
bool resolved;
|
bool resolved;
|
||||||
|
|
||||||
int measuredWidth;
|
int measuredWidth;
|
||||||
void setMeasuredWidth();
|
void setMeasuredWidth(int measuredWidth);
|
||||||
int measuredHeight;
|
int measuredHeight;
|
||||||
void setMeasuredHeight();
|
void setMeasuredHeight(int measuredHeight);
|
||||||
int measuredX;
|
int measuredX;
|
||||||
int measuredY;
|
int measuredY;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user