From de08866eb45cb915097530647bfa87cd9f4766ec Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 16 Jul 2019 19:50:12 +0800 Subject: [PATCH] add layout config --- js-framework/index.ts | 9 +++++- js-framework/view/view.ts | 62 ++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/js-framework/index.ts b/js-framework/index.ts index 029293cb..88e71e07 100644 --- a/js-framework/index.ts +++ b/js-framework/index.ts @@ -1,4 +1,4 @@ -import { Text } from "./view/view"; +import { Text, Alignment, VLayout, Gravity } from "./view/view"; import { Color } from "./util/color"; const v = new Text @@ -7,4 +7,11 @@ v.height = 30 v.left = 5 v.top = 5 v.bgColor = Color.parse('#00ff00') +v.config = { + alignment: Alignment.start +} console.log(v.toModel()) + +const layout = new Text + +console.log(layout.toModel()) diff --git a/js-framework/view/view.ts b/js-framework/view/view.ts index c390f6fd..78d2bb0a 100644 --- a/js-framework/view/view.ts +++ b/js-framework/view/view.ts @@ -80,27 +80,73 @@ export abstract class View implements IWatcher, Modeling { toModel() { 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 children: View[] = [] - - add(v: View) { - this.children.push(v) - } } 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 {