Skip to content

Commit cfb762c

Browse files
committed
feat: use UI createElement
1 parent fdc6abf commit cfb762c

File tree

3 files changed

+57
-42
lines changed

3 files changed

+57
-42
lines changed

examples/vue3/src/App.vue

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
11
<script setup lang="ts">
22
import { LeaferApp } from 'leafer-vue'
3+
import { ref } from 'vue'
4+
5+
const x = ref(1)
6+
function rightMove() {
7+
x.value += 10
8+
}
39
</script>
410

511
<template>
6-
<LeaferApp>
7-
<template
12+
<div style="display: flex;">
13+
<LeaferApp>
14+
<!-- <template
815
v-for="row in 1000"
916
:key="row"
10-
>
17+
>
1118
<Rect
1219
v-for="col in 1000"
1320
:key="col"
1421
:x="(row - 1) * 20" :y="(col - 1) * 20"
1522
/>
16-
</template>
17-
</LeaferApp>
23+
</template> -->
24+
25+
<Box>
26+
<Rect
27+
:x="x"
28+
:width="20"
29+
:height="20"
30+
fill="red"
31+
/>
32+
<Rect
33+
:x="x + 20"
34+
:width="20"
35+
:height="20"
36+
fill="red"
37+
/>
38+
<Text :x="x + 40" fill="red" text="aa">
39+
aaaa
40+
</Text>
41+
</Box>
42+
</LeaferApp>
43+
<button @click="rightMove">
44+
rightMove
45+
</button>
46+
</div>
1847
</template>

packages/vue3/components/application/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default defineComponent({
77
const canvas = ref<HTMLCanvasElement>()
88

99
function mount() {
10-
const context = new Leafer({ view: window })
10+
const context = new Leafer({ view: canvas.value })
1111

1212
const app = createApp({
1313
render: () => renderSlot(slots, 'default'),

packages/vue3/renderer/renderer.ts

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,16 @@
1-
import { Rect, Text } from 'leafer-ui'
1+
import { UI } from 'leafer-ui'
22
import { createRenderer } from 'vue'
33

44
// export function createRenderer() {
55

66
// }
77

8-
export const renderer = createRenderer<Rect, Rect>({
8+
export const renderer = createRenderer<UI, UI>({
99
createElement(type) {
10-
let element
11-
switch (type) {
12-
case 'Rect':
13-
element = new Rect({
14-
width: 15,
15-
height: 15,
16-
fill: 'rgb(50,205,121)',
17-
})
18-
break
19-
20-
default:
21-
throw new Error(`无${type}`)
22-
break
23-
}
24-
return element
10+
return UI.one({ tag: type })
2511
},
2612
patchProp(el, key, prevValue, nextValue) {
27-
switch (key) {
28-
case 'fill' :
29-
el.fill = nextValue
30-
break
31-
32-
case 'x':
33-
el.x = nextValue
34-
break
35-
36-
case 'y':
37-
el.y = nextValue
38-
break
39-
40-
default:
41-
break
42-
}
13+
el[key] = nextValue
4314
},
4415
insert(el, parent, anchor) {
4516
if (el && parent)
@@ -50,10 +21,10 @@ export const renderer = createRenderer<Rect, Rect>({
5021
el.parent.remove(el)
5122
},
5223
createText(text) {
53-
return new Text({ text })
24+
return new Error('a') as unknown as UI
5425
},
5526
createComment(text) {
56-
return new Text({ text })
27+
return new Error('a') as unknown as UI
5728
},
5829
setText(node, text) {
5930

@@ -62,9 +33,24 @@ export const renderer = createRenderer<Rect, Rect>({
6233

6334
},
6435
parentNode(node) {
65-
return node.parent as unknown as Rect
36+
return node.parent
6637
},
6738
nextSibling(node) {
6839
return null
6940
},
7041
})
42+
43+
// export function createRenderer(options: { prefix?: string } = {}) {
44+
// const { createElement, setText, ...nodeOps } = _nodeOps
45+
// const { prefix = 'pixi' } = options
46+
// const rendererOptions = rendererWithCapture({
47+
// createElement: (...args) => createElement(prefix, ...args),
48+
// setElementText: (...args) => setText(prefix, ...args),
49+
// setText: (...args) => setText(prefix, ...args),
50+
// patchProp,
51+
// ...nodeOps,
52+
// })
53+
// return _createRenderer<Container, Container>(rendererOptions)
54+
// }
55+
56+
// export const createApp = renderer.createApp

0 commit comments

Comments
 (0)