feat:Gravity static memebers
This commit is contained in:
parent
d495043dc9
commit
748bac8bc1
@ -13,7 +13,7 @@ class CounterView extends ViewHolder<CountModel> {
|
||||
text({
|
||||
textSize: 40,
|
||||
layoutConfig: {
|
||||
alignment: new Gravity().center(),
|
||||
alignment: Gravity.Center,
|
||||
widthSpec: LayoutSpec.WRAP_CONTENT,
|
||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||
},
|
||||
@ -27,7 +27,7 @@ class CounterView extends ViewHolder<CountModel> {
|
||||
},
|
||||
corners: 5,
|
||||
layoutConfig: {
|
||||
alignment: new Gravity().center(),
|
||||
alignment: Gravity.Center,
|
||||
widthSpec: LayoutSpec.WRAP_CONTENT,
|
||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||
},
|
||||
@ -43,9 +43,9 @@ class CounterView extends ViewHolder<CountModel> {
|
||||
it.width = 200
|
||||
it.height = 200
|
||||
it.space = 20
|
||||
it.gravity = new Gravity().center()
|
||||
it.gravity = Gravity.Center
|
||||
it.layoutConfig = {
|
||||
alignment: new Gravity().center()
|
||||
alignment: Gravity.Center
|
||||
}
|
||||
it.border = {
|
||||
width: 1,
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
import { Group, Panel, Text, text, gravity, Color, Stack, LayoutSpec, vlayout, hlayout, scroller, IVLayout, IHLayout, layoutConfig } from "doric";
|
||||
import { Group, Panel, Text, text, gravity, Color, Stack, LayoutSpec, vlayout, hlayout, scroller, IVLayout, IHLayout, layoutConfig, Gravity } from "doric";
|
||||
import { colors } from "./utils";
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ function boxStr(str: string, idx = 0) {
|
||||
return (new Text).also(it => {
|
||||
it.width = it.height = 20
|
||||
it.text = str
|
||||
it.textColor = Color.parse('#ffffff')
|
||||
it.textColor = Color.WHITE
|
||||
it.bgColor = colors[idx || 0]
|
||||
})
|
||||
}
|
||||
@ -38,7 +38,7 @@ class EffectsDemo extends Panel {
|
||||
width: 100,
|
||||
height: 100
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -56,7 +56,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 5,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -69,7 +69,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 10
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -88,7 +88,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 10
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
]).apply({ space: 20 } as IHLayout),
|
||||
@ -109,7 +109,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 5,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -132,7 +132,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 10
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -152,7 +152,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 10
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -178,7 +178,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 5,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
]).apply({ space: 20 } as IHLayout),
|
||||
@ -202,7 +202,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 10,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -224,7 +224,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 10,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -246,7 +246,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 10,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -268,7 +268,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 10,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
]).apply({ space: 20 } as IHLayout),
|
||||
@ -285,7 +285,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 5,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -302,7 +302,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 5,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -319,7 +319,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 5,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -336,7 +336,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 5,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
vlayout([
|
||||
@ -353,7 +353,7 @@ class EffectsDemo extends Panel {
|
||||
bottom: 5,
|
||||
})
|
||||
}),]).apply({
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout),
|
||||
]).apply({ space: 20 } as IHLayout),
|
||||
|
@ -11,7 +11,7 @@ class ModalDemo extends Panel {
|
||||
textSize: 30,
|
||||
textColor: Color.WHITE,
|
||||
bgColor: colors[1],
|
||||
textAlignment: gravity().center(),
|
||||
textAlignment: Gravity.Center,
|
||||
height: 50,
|
||||
}),
|
||||
label('toast'),
|
||||
@ -28,7 +28,7 @@ class ModalDemo extends Panel {
|
||||
} as IText),
|
||||
]).apply({
|
||||
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
|
||||
gravity: gravity().center(),
|
||||
gravity: Gravity.Center,
|
||||
space: 10,
|
||||
} as IVLayout)).apply({
|
||||
layoutConfig: layoutConfig().atmost(),
|
||||
|
@ -37,45 +37,65 @@ export class Gravity implements Modeling {
|
||||
val = 0
|
||||
|
||||
left() {
|
||||
this.val |= LEFT
|
||||
return this
|
||||
const val = this.val | LEFT
|
||||
const ret = new Gravity
|
||||
ret.val = val
|
||||
return ret
|
||||
}
|
||||
|
||||
right() {
|
||||
this.val |= RIGHT
|
||||
return this
|
||||
const val = this.val | RIGHT
|
||||
const ret = new Gravity
|
||||
ret.val = val
|
||||
return ret
|
||||
}
|
||||
|
||||
top() {
|
||||
this.val |= TOP
|
||||
return this
|
||||
const val = this.val | TOP
|
||||
const ret = new Gravity
|
||||
ret.val = val
|
||||
return ret
|
||||
}
|
||||
|
||||
bottom() {
|
||||
this.val |= BOTTOM
|
||||
return this
|
||||
const val = this.val | BOTTOM
|
||||
const ret = new Gravity
|
||||
ret.val = val
|
||||
return ret
|
||||
}
|
||||
|
||||
center() {
|
||||
this.val |= CENTER
|
||||
return this
|
||||
const val = this.val | CENTER
|
||||
const ret = new Gravity
|
||||
ret.val = val
|
||||
return ret
|
||||
}
|
||||
|
||||
centerX() {
|
||||
this.val |= CENTER_X
|
||||
return this
|
||||
const val = this.val | CENTER_X
|
||||
const ret = new Gravity
|
||||
ret.val = val
|
||||
return ret
|
||||
}
|
||||
|
||||
centerY() {
|
||||
this.val |= CENTER_Y
|
||||
return this
|
||||
const val = this.val | CENTER_Y
|
||||
const ret = new Gravity
|
||||
ret.val = val
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
toModel() {
|
||||
return this.val
|
||||
}
|
||||
private static origin = new Gravity
|
||||
|
||||
static Center = Gravity.origin.center()
|
||||
static Left = Gravity.origin.left()
|
||||
static Right = Gravity.origin.right()
|
||||
static Top = Gravity.origin.top()
|
||||
static Bottom = Gravity.origin.bottom()
|
||||
}
|
||||
export function gravity() {
|
||||
return new Gravity
|
||||
|
@ -1,11 +1,15 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { Gravity } from "./gravity";
|
||||
|
||||
|
||||
|
||||
export function modal(context: BridgeContext) {
|
||||
return {
|
||||
toast: (msg: string) => {
|
||||
context.modal.toast({ msg })
|
||||
toast: (msg: string, gravity: Gravity = Gravity.Bottom) => {
|
||||
context.modal.toast({
|
||||
msg,
|
||||
gravity: gravity.toModel(),
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user