add layout config

This commit is contained in:
pengfei.zhou 2019-07-16 19:50:12 +08:00
parent ea2145da69
commit de08866eb4
2 changed files with 62 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import { Text } from "./view/view"; import { Text, Alignment, VLayout, Gravity } from "./view/view";
import { Color } from "./util/color"; import { Color } from "./util/color";
const v = new Text const v = new Text
@ -7,4 +7,11 @@ v.height = 30
v.left = 5 v.left = 5
v.top = 5 v.top = 5
v.bgColor = Color.parse('#00ff00') v.bgColor = Color.parse('#00ff00')
v.config = {
alignment: Alignment.start
}
console.log(v.toModel()) console.log(v.toModel())
const layout = new Text
console.log(layout.toModel())

View File

@ -80,27 +80,73 @@ export abstract class View implements IWatcher, Modeling {
toModel() { toModel() {
return this.__dirty_props__ || {} return this.__dirty_props__ || {}
} }
@Property
padding?: {
left?: number,
right?: number,
top?: number,
bottom?: number,
}
@Property
config?: Config
} }
export class Group extends View { export enum Alignment {
center = 0,
start,
end,
}
export enum Gravity {
center = 0,
left,
right,
top,
bottom,
}
export interface Config {
margin?: {
left?: number,
right?: number,
top?: number,
bottom?: number,
}
alignment?: Alignment
}
export interface StackConfig extends Config {
}
export interface LayoutConfig extends Config {
weight?: number
}
export abstract class Group extends View {
@Property @Property
children: View[] = [] children: View[] = []
add(v: View) {
this.children.push(v)
}
} }
export class Stack extends Group { export class Stack extends Group {
@Property
gravity?: number
} }
export class VLayout extends Group { class LinearLayout extends Group {
@Property
space?: number
@Property
gravity?: number
} }
export class HLayout extends Group { export class VLayout extends LinearLayout {
}
export class HLayout extends LinearLayout {
} }
export class Text extends View { export class Text extends View {