add gravity handle & nested layout with rectangle with height handle

This commit is contained in:
王劲鹏
2021-03-17 18:20:43 +08:00
committed by osborn
parent fc104c4ec1
commit 0c151c435f
8 changed files with 87 additions and 21 deletions

View File

@@ -0,0 +1,32 @@
// gravity.mjs
export function enumerate() {
const SPECIFIED = 1;
const START = 1 << 1;
const END = 1 << 2;
const SHIFT_X = 0;
const SHIFT_Y = 4;
const LEFT = (START | SPECIFIED) << SHIFT_X;
const RIGHT = (END | SPECIFIED) << SHIFT_X;
const TOP = (START | SPECIFIED) << SHIFT_Y;
const BOTTOM = (END | SPECIFIED) << SHIFT_Y;
const CENTER_X = SPECIFIED << SHIFT_X;
const CENTER_Y = SPECIFIED << SHIFT_Y;
const CENTER = CENTER_X | CENTER_Y;
var gravity = {
SPECIFIED,
START,
END,
SHIFT_X,
SHIFT_Y,
LEFT,
RIGHT,
TOP,
BOTTOM,
CENTER_X,
CENTER_Y,
CENTER
}
return gravity
}

View File

@@ -3,16 +3,18 @@ import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15
import "util.mjs" as Util
import "gravity.mjs" as Gravity
Rectangle {
property var tag: "HLayout"
property var uuid: Util.uuidv4()
property int widthSpec: 0
property int heightSpec: 0
property int childrenRectWidth: childrenRect.width
property int childrenRectHeight: childrenRect.height
property var tag: "HLayout"
onWidthChanged: () => {
console.log(tag, uuid + " onWidthChanged: " + this.width)
}
@@ -24,8 +26,10 @@ Rectangle {
onWidthSpecChanged: () => {
console.log(tag, uuid + " onWidthSpecChanged: " + this.widthSpec)
console.log(tag, uuid + " parent width: " + parent.width)
if (this.widthSpec === 2) {
this.width = parent.width
// children[0].width = parent.width
}
}
@@ -35,6 +39,7 @@ Rectangle {
if (this.heightSpec === 2) {
this.height = parent.height
children[0].height = parent.height
}
}
@@ -56,6 +61,19 @@ Rectangle {
color: 'transparent'
RowLayout {
property int gravity: 0
spacing: 0
onChildrenChanged: () => {
console.log(tag, uuid + " gravity: " + gravity)
for (var i = 0;i !== children.length;i++) {
switch(this.gravity) {
case Gravity.enumerate().CENTER_X:
children[i].Layout.alignment = Qt.AlignHCenter
break
}
}
}
}
}

View File

@@ -3,16 +3,18 @@ import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15
import "util.mjs" as Util
import "gravity.mjs" as Gravity
Rectangle {
property var tag: "VLayout"
property var uuid: Util.uuidv4()
property int widthSpec: 0
property int heightSpec: 0
property int childrenRectWidth: childrenRect.width
property int childrenRectHeight: childrenRect.height
property var tag: "VLayout"
onWidthChanged: () => {
console.log(tag, uuid + " onWidthChanged: " + this.width)
}
@@ -24,8 +26,10 @@ Rectangle {
onWidthSpecChanged: () => {
console.log(tag, uuid + " onWidthSpecChanged: " + this.widthSpec)
console.log(tag, uuid + " parent width: " + parent.width)
if (this.widthSpec === 2) {
this.width = parent.width
children[0].width = parent.width
}
}
@@ -35,6 +39,7 @@ Rectangle {
if (this.heightSpec === 2) {
this.height = parent.height
// children[0].height = parent.height
}
}
@@ -56,6 +61,20 @@ Rectangle {
color: 'transparent'
ColumnLayout {
property int gravity: 0
spacing: 0
onChildrenChanged: () => {
console.log(tag, uuid + " gravity: " + gravity)
for (var i = 0;i !== children.length;i++) {
switch(this.gravity) {
case Gravity.enumerate().CENTER_X:
children[i].Layout.alignment = Qt.AlignHCenter
break
}
}
}
}
}