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-demo/src/DraggableDemo.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-01-04 14:43:28 +08:00
import { Panel, Group, vlayout, layoutConfig, draggable, Color, Text, Draggable, modal, Gravity, stack} from "doric";
2020-01-02 20:02:21 +08:00
import { title } from "./utils";
@Entry
class DraggableDemo extends Panel {
build(root: Group) {
let text = (new Text).also(it => {
2020-01-03 19:02:41 +08:00
it.layoutConfig = layoutConfig().just().configAlignment(Gravity.Center)
2020-01-03 18:06:57 +08:00
it.width = 100
it.height = 30
2020-01-02 20:02:21 +08:00
it.textColor = Color.parse('#ff0000')
2020-01-03 18:06:57 +08:00
it.onClick = () => {
modal(context).toast('Clicked')
}
})
let drag: Draggable
drag = draggable({
onDrag: (x: number, y: number) => {
2020-01-04 14:43:28 +08:00
text.text = "x: " + x.toFixed(0) + " y: " + y.toFixed(0)
2020-01-03 18:06:57 +08:00
}
}, [ text ]).apply({
layoutConfig: layoutConfig().just(),
width: 100,
height: 100,
backgroundColor: Color.WHITE
2020-01-02 20:02:21 +08:00
})
vlayout([
title("Draggable Demo"),
2020-01-04 14:43:28 +08:00
stack([
drag,
]).apply({
layoutConfig: layoutConfig().most()
})
2020-01-02 20:02:21 +08:00
])
.apply({
layoutConfig: layoutConfig().most(),
backgroundColor: Color.BLACK
})
.in(root)
}
}