add vh layout

This commit is contained in:
pengfei.zhou
2019-07-24 10:14:17 +08:00
parent 341692f319
commit 9592e9ed3d
13 changed files with 300 additions and 39 deletions

View File

@@ -0,0 +1,64 @@
import { Modeling } from "./types";
const SPECIFIED = 1
const START = 1 << 1
const END = 1 << 2
const SHIFT_X = 0
const SHIFT_Y = 4
export const LEFT = (START | SPECIFIED) << SHIFT_X
export const RIGHT = (END | SPECIFIED) << SHIFT_X
export const TOP = (START | SPECIFIED) << SHIFT_Y
export const BOTTOM = (END | SPECIFIED) << SHIFT_Y
export const CENTER_X = SPECIFIED << SHIFT_X
export const CENTER_Y = SPECIFIED << SHIFT_Y
export const CENTER = CENTER_X | CENTER_Y
export class Gravity implements Modeling {
val = 0
left() {
this.val |= LEFT
return this
}
right() {
this.val |= RIGHT
return this
}
top() {
this.val |= TOP
return this
}
bottom() {
this.val |= BOTTOM
return this
}
center() {
this.val |= CENTER
return this
}
centerX() {
this.val |= CENTER_X
return this
}
centerY() {
this.val |= CENTER_Y
return this
}
toModel() {
return this.val
}
}

View File

@@ -15,4 +15,36 @@ export function obj2Model(obj: Model): Model {
}
type _M = string | number | boolean | Modeling | { [index: string]: Model | undefined }
export type Model = _M | Array<_M>
export type Model = _M | Array<_M>
export type Binder<T> = (v: T) => void
export class Mutable<T>{
private val: T
private binders: Set<Binder<T>> = new Set
get = () => {
return this.val
}
set = (v: T) => {
this.val = v
this.binders.forEach(e => {
Reflect.apply(e, undefined, [this.val])
})
}
private constructor(v: T) {
this.val = v
}
bind(binder: Binder<T>) {
this.binders.add(binder)
Reflect.apply(binder, undefined, [this.val])
}
static of<E>(v: E) {
return new Mutable(v)
}
}

View File

@@ -1,5 +1,4 @@
let __uniqueId__: number = 0
let __uniqueId__ = 0
export function uniqueId(prefix: string) {
return `__${prefix}_${__uniqueId__++}__`;
}