aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/components/keyboard-layout.vue
blob: 3680f7ce70a251fca4545b30cbe9ea4fd74d31ab (plain)
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

<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"
      :parsed="keys[i]"
      :value="keys[i].value"
      :params="keys[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,
  },
  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.keys.slice(0, keyIndex),
        updatedBinding,
        ...this.keys.slice(keyIndex + 1)
      ])
    }
  }
}
</script>

<style>
.layer {
  position: relative;
}
</style>