2019-12-21 11:09:27 +08:00
|
|
|
import { DoricGroupViewNode, LayoutSpec, FrameSize, LEFT, RIGHT, CENTER_X, CENTER_Y, TOP, BOTTOM, toPixelString } from "./DoricViewNode";
|
2019-12-20 17:28:24 +08:00
|
|
|
|
|
|
|
export class DoricVLayoutNode extends DoricGroupViewNode {
|
|
|
|
space = 0
|
|
|
|
gravity = 0
|
2019-12-21 11:09:27 +08:00
|
|
|
|
2019-12-20 17:28:24 +08:00
|
|
|
build() {
|
2019-12-20 21:26:10 +08:00
|
|
|
const ret = document.createElement('div')
|
|
|
|
ret.style.display = "flex"
|
|
|
|
ret.style.flexDirection = "column"
|
|
|
|
ret.style.flexWrap = "nowrap"
|
|
|
|
return ret
|
2019-12-20 17:28:24 +08:00
|
|
|
}
|
|
|
|
blendProps(v: HTMLElement, propName: string, prop: any) {
|
|
|
|
if (propName === 'space') {
|
|
|
|
this.space = prop
|
|
|
|
} else if (propName === 'gravity') {
|
|
|
|
this.gravity = prop
|
2019-12-20 21:26:10 +08:00
|
|
|
if ((this.gravity & LEFT) === LEFT) {
|
2019-12-21 11:09:27 +08:00
|
|
|
this.view.style.alignItems = "flex-start"
|
2019-12-20 21:26:10 +08:00
|
|
|
} else if ((this.gravity & RIGHT) === RIGHT) {
|
2019-12-21 11:09:27 +08:00
|
|
|
this.view.style.alignItems = "flex-end"
|
2019-12-20 21:26:10 +08:00
|
|
|
} else if ((this.gravity & CENTER_X) === CENTER_X) {
|
2019-12-21 11:09:27 +08:00
|
|
|
this.view.style.alignItems = "center"
|
2019-12-20 21:26:10 +08:00
|
|
|
}
|
|
|
|
if ((this.gravity & TOP) === TOP) {
|
2019-12-21 11:09:27 +08:00
|
|
|
this.view.style.justifyContent = "flex-start"
|
2019-12-20 21:26:10 +08:00
|
|
|
} else if ((this.gravity & BOTTOM) === BOTTOM) {
|
2019-12-21 11:09:27 +08:00
|
|
|
this.view.style.justifyContent = "flex-end"
|
2019-12-20 21:26:10 +08:00
|
|
|
} else if ((this.gravity & CENTER_Y) === CENTER_Y) {
|
2019-12-21 11:09:27 +08:00
|
|
|
this.view.style.justifyContent = "center"
|
2019-12-20 21:26:10 +08:00
|
|
|
}
|
2019-12-20 17:28:24 +08:00
|
|
|
} else {
|
|
|
|
super.blendProps(v, propName, prop)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-21 11:09:27 +08:00
|
|
|
layout() {
|
|
|
|
super.layout()
|
|
|
|
this.childNodes.forEach((e, idx) => {
|
|
|
|
e.view.style.flexShrink = "0"
|
|
|
|
if (e.layoutConfig?.weight) {
|
|
|
|
e.view.style.flex = `${e.layoutConfig?.weight}`
|
2019-12-20 17:28:24 +08:00
|
|
|
}
|
2019-12-21 11:09:27 +08:00
|
|
|
e.view.style.marginTop = toPixelString(e.layoutConfig?.margin?.top || 0)
|
|
|
|
e.view.style.marginBottom = toPixelString(
|
|
|
|
(idx === this.childNodes.length - 1) ? 0 : this.space
|
|
|
|
+ (e.layoutConfig?.margin?.bottom || 0))
|
|
|
|
e.view.style.marginLeft = toPixelString(e.layoutConfig?.margin?.left || 0)
|
|
|
|
e.view.style.marginRight = toPixelString(e.layoutConfig?.margin?.right || 0)
|
|
|
|
})
|
2019-12-20 17:28:24 +08:00
|
|
|
}
|
|
|
|
}
|