1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<template>
<div class="layer">
<key-thing
v-for="(key, i) in layout"
:key="i"
:position="position(key)"
:rotation="rotation(key)"
:size="size(key)"
:label="key.label"
:value="normalized[i].value"
:params="normalized[i].params"
@update="handleUpdateBind(i, $event)"
/>
</div>
</template>
<script>
import Key from './key.vue'
export default {
props: ['layout', 'keys'],
emits: ['update'],
components: {
'key-thing': Key,
},
computed: {
normalized() {
return this.layout.map((_, i) => (
this.keys[i] || {
value: '&none',
params: []
}
))
}
},
methods: {
position(key) {
const { x, y } = key
return { x, y }
},
rotation(key) {
const { rx, ry, r } = key
return { x: rx, y: ry, a: r }
},
size(key) {
const { w = 1, u = w, h = 1 } = key
return { u, h }
},
handleUpdateBind(keyIndex, updatedBinding) {
this.$emit('update', [
...this.normalized.slice(0, keyIndex),
updatedBinding,
...this.normalized.slice(keyIndex + 1)
])
}
}
}
</script>
<style>
.layer {
position: relative;
}
</style>
|