This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-web/src/shader/DoricVLayoutNode.ts

60 lines
2.5 KiB
TypeScript
Raw Normal View History

2019-12-21 13:28:51 +08:00
import { DoricGroupViewNode, 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-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) {
this.view.style.alignItems = "flex-start"
2019-12-20 21:26:10 +08:00
} else if ((this.gravity & RIGHT) === RIGHT) {
this.view.style.alignItems = "flex-end"
2019-12-20 21:26:10 +08:00
} else if ((this.gravity & CENTER_X) === CENTER_X) {
this.view.style.alignItems = "center"
2019-12-20 21:26:10 +08:00
}
if ((this.gravity & TOP) === TOP) {
this.view.style.justifyContent = "flex-start"
2019-12-20 21:26:10 +08:00
} else if ((this.gravity & BOTTOM) === BOTTOM) {
this.view.style.justifyContent = "flex-end"
2019-12-20 21:26:10 +08:00
} else if ((this.gravity & CENTER_Y) === CENTER_Y) {
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)
}
}
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
}
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)
if ((e.layoutConfig.alignment & LEFT) === LEFT) {
e.view.style.alignSelf = "flex-start"
} else if ((e.layoutConfig.alignment & RIGHT) === RIGHT) {
e.view.style.alignSelf = "flex-end"
} else if ((e.layoutConfig.alignment & CENTER_X) === CENTER_X) {
e.view.style.alignSelf = "center"
}
})
2019-12-20 17:28:24 +08:00
}
}