R parts in the bottom bar as drawn tiles in a strip that scrolls sideways
Pointing at a kind of part shows each one as it looks on the canvas, in a strip the mouse wheel scrolls sideways, like a city builder's. Pin and edit sit on each tile's corner. Components get a tab per group, opening on the first group with something that can go in the circuit. The list stays open while a part is dragged out of it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
97c650a2b8
commit
821f468748
|
|
@ -4929,3 +4929,197 @@ button.tile:hover {
|
||||||
.unused-list a {
|
.unused-list a {
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Part tiles in the bottom bar's flyouts ─────────────────────── */
|
||||||
|
.flyout.part-flyout {
|
||||||
|
width: max-content;
|
||||||
|
max-width: min(780px, 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-tabs {
|
||||||
|
display: flex;
|
||||||
|
gap: 2px;
|
||||||
|
padding: 2px 2px 4px;
|
||||||
|
overflow-x: auto;
|
||||||
|
scrollbar-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-tabs button {
|
||||||
|
flex-shrink: 0;
|
||||||
|
padding: 4px 9px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-tabs button:hover {
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-tabs button.active {
|
||||||
|
background: var(--panel-2);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-tabs .count {
|
||||||
|
margin-left: 3px;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.strip-wrap {
|
||||||
|
position: relative;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-strip {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 2px 2px 6px;
|
||||||
|
overflow-x: auto;
|
||||||
|
scroll-behavior: smooth;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: var(--border) transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.strip-arrow {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 2;
|
||||||
|
top: 0;
|
||||||
|
bottom: 6px;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
width: 30px;
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.strip-arrow.left {
|
||||||
|
left: 0;
|
||||||
|
background: linear-gradient(90deg, rgb(26 33 43) 45%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.strip-arrow.right {
|
||||||
|
right: 0;
|
||||||
|
background: linear-gradient(270deg, rgb(26 33 43) 45%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-slot {
|
||||||
|
position: relative;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-tile {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
width: 100px;
|
||||||
|
height: 100px;
|
||||||
|
padding: 6px 6px 7px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 10px;
|
||||||
|
background: var(--panel);
|
||||||
|
text-align: center;
|
||||||
|
cursor: grab;
|
||||||
|
transition:
|
||||||
|
border-color 0.12s,
|
||||||
|
transform 0.12s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-tile:hover {
|
||||||
|
border-color: var(--accent);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-tile.active {
|
||||||
|
border-color: var(--accent);
|
||||||
|
background: rgb(76 194 255 / 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-tile.blocked {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.45;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-tile.blocked:hover {
|
||||||
|
transform: none;
|
||||||
|
border-color: var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-art {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
flex: 1;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-thumb {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
max-height: 56px;
|
||||||
|
overflow: visible;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-thumb .node.ghost {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-name {
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.2;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-meta {
|
||||||
|
font-size: 10px;
|
||||||
|
line-height: 1;
|
||||||
|
color: var(--muted);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-key {
|
||||||
|
position: absolute;
|
||||||
|
top: 5px;
|
||||||
|
left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-lock {
|
||||||
|
position: absolute;
|
||||||
|
top: 6px;
|
||||||
|
left: 6px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pin (and edit) sit on the tile's top right corner, shown on pointing. */
|
||||||
|
.part-slot .pin-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 3px;
|
||||||
|
right: 3px;
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
background: var(--panel-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-slot .pin-btn.edit {
|
||||||
|
top: 27px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-slot:hover .pin-btn {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.part-tile {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
// button per kind of part. Pointing at one opens its parts above it; click
|
// button per kind of part. Pointing at one opens its parts above it; click
|
||||||
// a part to place it (or drag it onto the canvas), pin it to keep it on the
|
// a part to place it (or drag it onto the canvas), pin it to keep it on the
|
||||||
// bar itself. Components and your connector types have their own buttons.
|
// bar itself. Components and your connector types have their own buttons.
|
||||||
|
// Parts and components show as drawn tiles in a strip, like a city
|
||||||
|
// builder's: the mouse wheel scrolls it sideways.
|
||||||
import { shortCount } from '~/lib/logic/analyze'
|
import { shortCount } from '~/lib/logic/analyze'
|
||||||
import { BASIC_GROUPS } from '~/composables/useParts'
|
import { BASIC_GROUPS } from '~/composables/useParts'
|
||||||
import type { ComponentDef, NodeKind } from '~/lib/logic/types'
|
import type { ComponentDef, NodeKind } from '~/lib/logic/types'
|
||||||
|
|
@ -28,16 +30,51 @@ const cats = computed<Cat[]>(() => [
|
||||||
|
|
||||||
// ── Flyout: opens on pointing, stays while the pointer is over it ──
|
// ── Flyout: opens on pointing, stays while the pointer is over it ──
|
||||||
const open = ref<string | null>(null)
|
const open = ref<string | null>(null)
|
||||||
const anchor = ref(0)
|
|
||||||
let timer: ReturnType<typeof setTimeout> | undefined
|
let timer: ReturnType<typeof setTimeout> | undefined
|
||||||
|
|
||||||
const dock = ref<HTMLElement>()
|
const dock = ref<HTMLElement>()
|
||||||
/** Where the list opens: centred above the pointer, kept inside the canvas. */
|
const fly = ref<HTMLElement>()
|
||||||
|
/** Pointer position along the dock, the dock's width and the flyout's, in px. */
|
||||||
|
const at = ref({ x: 0, dock: 0, fly: 250 })
|
||||||
|
/** Where the flyout opens: centred above the pointer, kept inside the canvas. */
|
||||||
|
const anchor = computed(() => {
|
||||||
|
const half = at.value.fly / 2
|
||||||
|
return Math.min(Math.max(at.value.x, half), Math.max(half, at.value.dock - half))
|
||||||
|
})
|
||||||
function anchorAt(x: number) {
|
function anchorAt(x: number) {
|
||||||
const r = dock.value!.getBoundingClientRect()
|
const r = dock.value!.getBoundingClientRect()
|
||||||
const half = 130
|
at.value = { ...at.value, x: x - r.left, dock: r.width }
|
||||||
anchor.value = Math.min(Math.max(x - r.left, half), Math.max(half, r.width - half))
|
|
||||||
}
|
}
|
||||||
|
function measure() {
|
||||||
|
if (fly.value) at.value = { ...at.value, fly: fly.value.offsetWidth }
|
||||||
|
const el = strip.value
|
||||||
|
edges.value = el ? { left: el.scrollLeft > 4, right: el.scrollLeft + el.clientWidth < el.scrollWidth - 4 } : { left: false, right: false }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── The strip of tiles: sideways with the wheel, arrows at the ends ──
|
||||||
|
const strip = ref<HTMLElement>()
|
||||||
|
const edges = ref({ left: false, right: false })
|
||||||
|
function onWheel(e: WheelEvent) {
|
||||||
|
const el = strip.value
|
||||||
|
if (!el || Math.abs(e.deltaX) > Math.abs(e.deltaY)) return
|
||||||
|
e.preventDefault()
|
||||||
|
el.scrollLeft += e.deltaY
|
||||||
|
}
|
||||||
|
function page(dir: number) {
|
||||||
|
strip.value?.scrollBy({ left: dir * strip.value.clientWidth * 0.8, behavior: 'smooth' })
|
||||||
|
}
|
||||||
|
|
||||||
|
const placeable = (d: ComponentDef) => d.id !== ed.def.value.id && ed.canPlace(d.id)
|
||||||
|
|
||||||
|
/** The component group shown; your own components first. */
|
||||||
|
const compTab = ref('')
|
||||||
|
const compGroup = computed(
|
||||||
|
() =>
|
||||||
|
componentGroups.value.find(g => g.name === compTab.value) ??
|
||||||
|
// Untouched: the first group with something that can go in here.
|
||||||
|
componentGroups.value.find(g => g.defs.some(placeable)) ??
|
||||||
|
componentGroups.value[0],
|
||||||
|
)
|
||||||
|
|
||||||
function show(id: string, e: PointerEvent) {
|
function show(id: string, e: PointerEvent) {
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
|
|
@ -52,6 +89,8 @@ function show(id: string, e: PointerEvent) {
|
||||||
|
|
||||||
function leave() {
|
function leave() {
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
|
// While a part is dragged out of it, the flyout stays (it closes when the drag ends).
|
||||||
|
if (ed.dragPart.value) return
|
||||||
timer = setTimeout(() => (open.value = null), 220)
|
timer = setTimeout(() => (open.value = null), 220)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,6 +112,13 @@ function pick(kind: NodeKind, chip?: string, conn?: string) {
|
||||||
open.value = null
|
open.value = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function endDrag() {
|
||||||
|
dragEnd()
|
||||||
|
open.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
watch([open, compTab, () => compGroup.value?.defs.length], () => nextTick(measure))
|
||||||
|
|
||||||
/** Which button the part being placed belongs to, to show it as active. */
|
/** Which button the part being placed belongs to, to show it as active. */
|
||||||
const activeCat = computed(() => {
|
const activeCat = computed(() => {
|
||||||
const p = ed.placing.value
|
const p = ed.placing.value
|
||||||
|
|
@ -88,7 +134,6 @@ const portsOk = computed(() => ed.canPlaceKind('portin'))
|
||||||
// Pinned parts sit on the bar; a pinned component this project lacks is left out.
|
// Pinned parts sit on the bar; a pinned component this project lacks is left out.
|
||||||
const shown = computed(() => pinned.value.filter(p => p.kind !== 'chip' || p.chip))
|
const shown = computed(() => pinned.value.filter(p => p.kind !== 'chip' || p.chip))
|
||||||
const named = (p: { kind: NodeKind }) => p.kind === 'chip' || p.kind === 'nand'
|
const named = (p: { kind: NodeKind }) => p.kind === 'chip' || p.kind === 'nand'
|
||||||
const placeable = (d: ComponentDef) => d.id !== ed.def.value.id && ed.canPlace(d.id)
|
|
||||||
|
|
||||||
function onKey(e: KeyboardEvent) {
|
function onKey(e: KeyboardEvent) {
|
||||||
if (e.key === 'Escape' && open.value) {
|
if (e.key === 'Escape' && open.value) {
|
||||||
|
|
@ -103,31 +148,35 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
|
||||||
<template>
|
<template>
|
||||||
<div ref="dock" class="bottom-dock" @pointerdown.stop>
|
<div ref="dock" class="bottom-dock" @pointerdown.stop>
|
||||||
<Transition name="flyout">
|
<Transition name="flyout">
|
||||||
<div v-if="open" class="flyout" :style="{ left: `${anchor}px` }" @pointerenter="stay" @pointerleave="leave">
|
<div v-if="open" ref="fly" class="flyout" :class="{ 'part-flyout': open !== 'connectors' }" :style="{ left: `${anchor}px` }" @pointerenter="stay" @pointerleave="leave">
|
||||||
<!-- Built-in parts -->
|
<!-- Built-in parts -->
|
||||||
<template v-if="group">
|
<template v-if="group">
|
||||||
<p class="flyout-head">{{ group.name }}</p>
|
<p class="flyout-head">{{ group.name }}</p>
|
||||||
<ul class="flyout-list">
|
<div class="strip-wrap">
|
||||||
<li v-for="p in group.parts" :key="p.kind">
|
<button v-if="edges.left" class="strip-arrow left" title="Scroll left" @click="page(-1)"><Icon name="lucide:chevron-left" class="size-4" /></button>
|
||||||
<button
|
<div ref="strip" class="part-strip" @wheel="onWheel" @scroll="measure">
|
||||||
class="flyout-item"
|
<div v-for="p in group.parts" :key="p.kind" class="part-slot">
|
||||||
:class="{ blocked: !ed.canPlaceKind(p.kind), active: ed.placing.value?.kind === p.kind && !ed.placing.value?.chip }"
|
<button
|
||||||
:title="p.hint"
|
class="part-tile"
|
||||||
draggable="true"
|
:class="{ blocked: !ed.canPlaceKind(p.kind), active: ed.placing.value?.kind === p.kind && !ed.placing.value?.chip }"
|
||||||
@click="pick(p.kind)"
|
:title="p.hint"
|
||||||
@dragstart="dragStart($event, p.kind)"
|
draggable="true"
|
||||||
@dragend="dragEnd"
|
@click="pick(p.kind)"
|
||||||
>
|
@dragstart="dragStart($event, p.kind)"
|
||||||
<span v-if="p.kind === 'nand'" class="nand-badge">&</span>
|
@dragend="endDrag"
|
||||||
<Icon v-else :name="p.icon" class="size-4 shrink-0" />
|
>
|
||||||
<span class="grow truncate">{{ p.name }}</span>
|
<span class="part-art"><EditorPartThumb :kind="p.kind" /></span>
|
||||||
<kbd v-if="p.key">{{ p.key }}</kbd>
|
<span class="part-name">{{ p.name }}</span>
|
||||||
</button>
|
<kbd v-if="p.key" class="part-key">{{ p.key }}</kbd>
|
||||||
<button class="pin-btn" :class="{ on: isPinned(p.kind) }" :title="isPinned(p.kind) ? 'Unpin from the bar' : 'Pin to the bar, to have it at hand'" @click="togglePin(p.kind)">
|
<Icon v-if="!ed.canPlaceKind(p.kind)" name="lucide:lock" class="part-lock size-3.5" />
|
||||||
<Icon :name="isPinned(p.kind) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
</button>
|
||||||
</button>
|
<button class="pin-btn" :class="{ on: isPinned(p.kind) }" :title="isPinned(p.kind) ? 'Unpin from the bar' : 'Pin to the bar, to have it at hand'" @click="togglePin(p.kind)">
|
||||||
</li>
|
<Icon :name="isPinned(p.kind) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
||||||
</ul>
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button v-if="edges.right" class="strip-arrow right" title="Scroll right" @click="page(1)"><Icon name="lucide:chevron-right" class="size-4" /></button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Connector types -->
|
<!-- Connector types -->
|
||||||
|
|
@ -162,33 +211,46 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
|
||||||
|
|
||||||
<!-- Components, by group -->
|
<!-- Components, by group -->
|
||||||
<template v-else-if="open === 'components'">
|
<template v-else-if="open === 'components'">
|
||||||
<div class="flyout-scroll">
|
<div v-if="componentGroups.length > 1" class="part-tabs" role="tablist">
|
||||||
<template v-for="g in componentGroups" :key="g.name">
|
<button
|
||||||
<p class="flyout-head">{{ g.name }}</p>
|
v-for="g in componentGroups"
|
||||||
<ul class="flyout-list">
|
:key="g.name"
|
||||||
<li v-for="d in g.defs" :key="d.id">
|
role="tab"
|
||||||
<button
|
:aria-selected="compGroup?.name === g.name"
|
||||||
class="flyout-item"
|
:class="{ active: compGroup?.name === g.name }"
|
||||||
:class="{ blocked: !placeable(d), active: ed.placing.value?.chip === d.id }"
|
@click="compTab = g.name"
|
||||||
:title="d.id === ed.def.value.id ? 'You are editing this one' : d.description || ''"
|
>
|
||||||
:draggable="placeable(d)"
|
{{ g.name }} <span class="count">{{ g.defs.length }}</span>
|
||||||
@click="pick('chip', d.id)"
|
</button>
|
||||||
@dragstart="dragStart($event, 'chip', d.id)"
|
</div>
|
||||||
@dragend="dragEnd"
|
<p v-else class="flyout-head">{{ compGroup?.name ?? 'Components' }}</p>
|
||||||
>
|
<div class="strip-wrap">
|
||||||
<Icon name="lucide:box" class="size-4 shrink-0" />
|
<button v-if="edges.left" class="strip-arrow left" title="Scroll left" @click="page(-1)"><Icon name="lucide:chevron-left" class="size-4" /></button>
|
||||||
<span class="grow truncate">{{ d.name }}</span>
|
<div ref="strip" class="part-strip" @wheel="onWheel" @scroll="measure">
|
||||||
<span v-if="ed.transistors(d.id)" class="flyout-note">{{ shortCount(ed.transistors(d.id)) }}T</span>
|
<div v-for="d in compGroup?.defs ?? []" :key="d.id" class="part-slot">
|
||||||
</button>
|
<button
|
||||||
<button v-if="d.id !== ed.def.value.id" class="pin-btn" title="Open it and edit inside (or double-click it on the canvas)" @click="ed.open(d.id), (open = null)">
|
class="part-tile"
|
||||||
<Icon name="lucide:pencil" class="size-3.5" />
|
:class="{ blocked: !placeable(d), active: ed.placing.value?.chip === d.id }"
|
||||||
</button>
|
:title="d.id === ed.def.value.id ? 'You are editing this one' : d.description || ''"
|
||||||
<button class="pin-btn" :class="{ on: isPinned('chip', d) }" :title="isPinned('chip', d) ? 'Unpin from the bar' : 'Pin to the bar'" @click="togglePin('chip', d)">
|
:draggable="placeable(d)"
|
||||||
<Icon :name="isPinned('chip', d) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
@click="pick('chip', d.id)"
|
||||||
</button>
|
@dragstart="dragStart($event, 'chip', d.id)"
|
||||||
</li>
|
@dragend="endDrag"
|
||||||
</ul>
|
>
|
||||||
</template>
|
<span class="part-art"><EditorPartThumb kind="chip" :chip="d.id" /></span>
|
||||||
|
<span class="part-name">{{ d.name }}</span>
|
||||||
|
<span v-if="d.id === ed.def.value.id" class="part-meta">editing</span>
|
||||||
|
<span v-else-if="ed.transistors(d.id)" class="part-meta">{{ shortCount(ed.transistors(d.id)) }} transistors</span>
|
||||||
|
</button>
|
||||||
|
<button class="pin-btn" :class="{ on: isPinned('chip', d) }" :title="isPinned('chip', d) ? 'Unpin from the bar' : 'Pin to the bar'" @click="togglePin('chip', d)">
|
||||||
|
<Icon :name="isPinned('chip', d) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
||||||
|
</button>
|
||||||
|
<button v-if="d.id !== ed.def.value.id" class="pin-btn edit" title="Open it and edit inside (or double-click it on the canvas)" @click="ed.open(d.id), (open = null)">
|
||||||
|
<Icon name="lucide:pencil" class="size-3.5" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button v-if="edges.right" class="strip-arrow right" title="Scroll right" @click="page(1)"><Icon name="lucide:chevron-right" class="size-4" /></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
<button class="flyout-new grow" @click="ed.createComponent(), (open = null)"><Icon name="lucide:plus" class="size-4" /> New component</button>
|
<button class="flyout-new grow" @click="ed.createComponent(), (open = null)"><Icon name="lucide:plus" class="size-4" /> New component</button>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
<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>
|
||||||
Loading…
Reference in New Issue