39 lines
1.6 KiB
Vue
39 lines
1.6 KiB
Vue
<script setup lang="ts">
|
|
// A small picture of a part, drawn the way the canvas draws it, for the
|
|
// parts dock: you see what you are about to place.
|
|
import { GRID as G } from '~/lib/logic/geometry'
|
|
import { newPanelRows } from '~/lib/logic/panels'
|
|
import type { CircuitNode, NodeKind } from '~/lib/logic/types'
|
|
|
|
const props = defineProps<{ kind: NodeKind; chip?: string }>()
|
|
const ed = useEditor()
|
|
|
|
const node = computed<CircuitNode>(() => {
|
|
const n: CircuitNode = { id: 'thumb', kind: props.kind, x: 0, y: 0 }
|
|
if (props.chip) n.chip = props.chip
|
|
if (props.kind === 'panel' || props.kind === 'outpanel') n.rows = newPanelRows(3)
|
|
if (props.kind === 'bundle' || props.kind === 'split') n.bits = 4
|
|
if (props.kind === 'note') n.label = 'Note'
|
|
if (props.kind === 'tag' || props.kind === 'ref') n.label = 'CLK'
|
|
return n
|
|
})
|
|
const shape = computed(() => ed.shape(node.value))
|
|
|
|
/** The part and its pins, with a little room around. */
|
|
const box = computed(() => {
|
|
const s = shape.value
|
|
const xs = [s.body.x, s.body.x + s.body.w, ...s.inputs.map(p => p.dx), ...s.outputs.map(p => p.dx)]
|
|
const ys = [s.body.y, s.body.y + s.body.h, ...s.inputs.map(p => p.dy), ...s.outputs.map(p => p.dy)]
|
|
const pad = 0.6
|
|
const x0 = Math.min(...xs) - pad
|
|
const y0 = Math.min(...ys) - pad
|
|
return `${x0 * G} ${y0 * G} ${(Math.max(...xs) + pad - x0) * G} ${(Math.max(...ys) + pad - y0) * G}`
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<svg class="part-thumb" :viewBox="box" preserveAspectRatio="xMidYMid meet" aria-hidden="true">
|
|
<EditorNodeView :node="node" :shape="shape" :selected="false" ghost />
|
|
</svg>
|
|
</template>
|