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

44 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-01-03 18:06:57 +08:00
import { Panel, Group, vlayout, layoutConfig, draggable, Color, Text, Draggable, modal, Gravity, loge} 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 18:06:57 +08:00
it.layoutConfig = layoutConfig().just().configAlignmnet(Gravity.Center)
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
let lastX: number = 0
let lastY: number = 0
drag = draggable({
onDrag: (x: number, y: number) => {
lastX += x
lastY += y
drag.translationX = lastX
drag.translationY = lastY
loge(lastX)
text.text = "x: " + lastX.toFixed(0) + " y: " + lastY.toFixed(0)
}
}, [ 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-03 18:06:57 +08:00
drag
2020-01-02 20:02:21 +08:00
])
.apply({
layoutConfig: layoutConfig().most(),
backgroundColor: Color.BLACK
})
.in(root)
}
}