BF box designer: cable sockets drag and reorder like pins, taking their lines along; port parts no wider than their title
Sockets on a component's box could not be dragged in the designer and got pushed around when other pins moved. They are now picked and dragged like any pin (onto or past a neighbour they swap), and the lines split out of a socket move with it as one block. The In and Out port parts measured their title at nearly twice its size, so they were much wider than what they show. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3563ee9a95
commit
652b048dbc
|
|
@ -82,10 +82,13 @@ const nameBox = computed(() => {
|
||||||
return { x: c.x - w / 2, y: c.y - 0.55, w, h: 1.1 }
|
return { x: c.x - w / 2, y: c.y - 0.55, w, h: 1.1 }
|
||||||
})
|
})
|
||||||
|
|
||||||
/** Pins on both edges, to drag up and down. */
|
/** Pins on both edges, cable sockets too, to drag up and down. */
|
||||||
const pins = computed(() => [
|
const pins = computed(() => [
|
||||||
...shape.value.inputs.filter(p => !p.bus).map(p => ({ ...p, side: 'in' as const })),
|
...shape.value.inputs.filter(p => p.dx === 0).map(p => ({ ...p, side: 'in' as const })),
|
||||||
...shape.value.outputs.filter(p => !p.bus).map(p => ({ ...p, side: 'out' as const })),
|
...shape.value.outputs.filter(p => p.dx > 0).map(p => ({ ...p, side: 'out' as const })),
|
||||||
|
// Pins on the other edge than usual (lines of a socket that run the other way) stay with their edge.
|
||||||
|
...shape.value.inputs.filter(p => p.dx > 0).map(p => ({ ...p, side: 'out' as const })),
|
||||||
|
...shape.value.outputs.filter(p => p.dx === 0).map(p => ({ ...p, side: 'in' as const })),
|
||||||
])
|
])
|
||||||
|
|
||||||
const shapes = computed(() => def.value?.design?.shapes ?? [])
|
const shapes = computed(() => def.value?.design?.shapes ?? [])
|
||||||
|
|
@ -108,7 +111,7 @@ type Drag =
|
||||||
| { type: 'resize'; id: string; handle: 'a' | 'b'; orig: FaceShape }
|
| { type: 'resize'; id: string; handle: 'a' | 'b'; orig: FaceShape }
|
||||||
| { type: 'scale'; key: string }
|
| { type: 'scale'; key: string }
|
||||||
| { type: 'box'; start: { x: number; y: number }; cur: { x: number; y: number }; add: boolean }
|
| { type: 'box'; start: { x: number; y: number }; cur: { x: number; y: number }; add: boolean }
|
||||||
| { type: 'pin'; key: string; side: 'in' | 'out'; start: number; rows: { key: string; dy: number; set: boolean }[]; index: number }
|
| { type: 'pin'; key: string; side: 'in' | 'out'; start: number; rows: { key: string; dy: number; set: boolean; port?: string }[]; index: number }
|
||||||
const drag = ref<Drag | null>(null)
|
const drag = ref<Drag | null>(null)
|
||||||
|
|
||||||
function onDown(e: PointerEvent) {
|
function onDown(e: PointerEvent) {
|
||||||
|
|
@ -157,9 +160,9 @@ function onDown(e: PointerEvent) {
|
||||||
if (id.startsWith('pin:')) {
|
if (id.startsWith('pin:')) {
|
||||||
const key = id.slice(4)
|
const key = id.slice(4)
|
||||||
const pin = pins.value.find(x => x.key === key)!
|
const pin = pins.value.find(x => x.key === key)!
|
||||||
const side = pins.value.filter(x => x.side === pin.side)
|
const side = pins.value.filter(x => x.side === pin.side).sort((a, b) => a.dy - b.dy)
|
||||||
const pinAt = def.value.design?.pinAt ?? {}
|
const pinAt = def.value.design?.pinAt ?? {}
|
||||||
drag.value = { type: 'pin', key, side: pin.side, start: p.y, rows: side.map(x => ({ key: x.key, dy: x.dy, set: pinAt[x.key] !== undefined })), index: side.findIndex(x => x.key === key) }
|
drag.value = { type: 'pin', key, side: pin.side, start: p.y, rows: side.map(x => ({ key: x.key, dy: x.dy, set: pinAt[x.key] !== undefined, ...(x.port ? { port: x.port } : {}) })), index: side.findIndex(x => x.key === key) }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const handle = el!.getAttribute('data-handle') as 'a' | 'b' | null
|
const handle = el!.getAttribute('data-handle') as 'a' | 'b' | null
|
||||||
|
|
@ -236,28 +239,31 @@ function onMove(e: PointerEvent) {
|
||||||
}
|
}
|
||||||
if (d.type === 'pin') {
|
if (d.type === 'pin') {
|
||||||
const row = d.rows[d.index]!
|
const row = d.rows[d.index]!
|
||||||
|
// A cable socket takes the lines split out of it along: they move as one block.
|
||||||
|
const block = d.rows.filter(r => r === row || (r.port && r.port === row.key))
|
||||||
|
const others = d.rows.filter(r => !block.includes(r))
|
||||||
|
const span = Math.max(...block.map(r => r.dy)) - row.dy
|
||||||
const want = Math.max(0, Math.round(row.dy + p.y - d.start))
|
const want = Math.max(0, Math.round(row.dy + p.y - d.start))
|
||||||
const next = d.rows[d.index + 1]
|
const above = others.filter(r => r.dy < row.dy).at(-1)
|
||||||
const prevRow = d.rows[d.index - 1]
|
const below = others.find(r => r.dy > row.dy + span)
|
||||||
const pinAt = (design().pinAt ??= {})
|
const pinAt = (design().pinAt ??= {})
|
||||||
if ((next && want >= next.dy) || (prevRow && want <= prevRow.dy)) {
|
const putBlock = (top: number) => {
|
||||||
|
for (const r of block) pinAt[r.key] = top + (r.dy - row.dy)
|
||||||
|
}
|
||||||
|
if ((below && want + span >= below.dy) || (above && want <= above.dy)) {
|
||||||
// Onto or past a neighbour: the pins change order. The others stay where they are, this one goes where it is dragged.
|
// Onto or past a neighbour: the pins change order. The others stay where they are, this one goes where it is dragged.
|
||||||
const others = d.rows.filter((_, i) => i !== d.index)
|
|
||||||
const at = others.filter(r => r.dy < want || (r.dy === want && want > row.dy)).length
|
const at = others.filter(r => r.dy < want || (r.dy === want && want > row.dy)).length
|
||||||
const order = [...others.slice(0, at), row, ...others.slice(at)].map(r => r.key)
|
const order = [...others.slice(0, at), ...block, ...others.slice(at)].map(r => r.key)
|
||||||
const keep = (design().pinOrder ?? []).filter(k => !d.rows.some(r => r.key === k))
|
const keep = (design().pinOrder ?? []).filter(k => !d.rows.some(r => r.key === k))
|
||||||
design().pinOrder = [...keep, ...order]
|
design().pinOrder = [...keep, ...order]
|
||||||
for (const r of others) pinAt[r.key] = r.dy
|
for (const r of others) pinAt[r.key] = r.dy
|
||||||
pinAt[row.key] = want
|
putBlock(want)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Dragging a pin moves it and the pins below it on that edge: a gap opens above it.
|
// Moved along its own gap: it and the pins below it on that edge go, so a gap opens above it.
|
||||||
const prev = d.index > 0 ? d.rows[d.index - 1]!.dy : -1
|
const delta = Math.max(Math.round(p.y - d.start), (above ? above.dy + 1 : 0) - row.dy)
|
||||||
const delta = Math.max(Math.round(p.y - d.start), prev + 1 - row.dy)
|
putBlock(row.dy + delta)
|
||||||
d.rows.forEach((r, i) => {
|
for (const r of others) if (r.dy > row.dy && r.set) pinAt[r.key] = Math.max(0, r.dy + delta)
|
||||||
if (i === d.index) pinAt[r.key] = Math.max(0, r.dy + delta)
|
|
||||||
else if (i > d.index && r.set) pinAt[r.key] = Math.max(0, r.dy + delta)
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (d.type === 'move') {
|
if (d.type === 'move') {
|
||||||
|
|
|
||||||
|
|
@ -763,9 +763,9 @@ export function portLines(node: CircuitNode, get: DefLookup): { name: string; en
|
||||||
*/
|
*/
|
||||||
function portShape(node: CircuitNode, get: DefLookup): Shape {
|
function portShape(node: CircuitNode, get: DefLookup): Shape {
|
||||||
const lines = portLines(node, get)
|
const lines = portLines(node, get)
|
||||||
// Wide enough for the longest line name, and for the title: "<type> in · <name>".
|
// Wide enough for the longest line name, and for the title "<type> in · <name>" (9px letters, about a third of a square each).
|
||||||
const title = `${(node.conn && get.conn?.(node.conn)?.name) || 'Port'} out${node.label?.trim() ? ` · ${node.label.trim()}` : ''}`
|
const title = `${(node.conn && get.conn?.(node.conn)?.name) || 'Port'} out${node.label?.trim() ? ` · ${node.label.trim()}` : ''}`
|
||||||
const w = Math.max(4, Math.ceil(lines.reduce((m, l) => Math.max(m, l.name.length), 0) * LABEL_CHAR + 2.6), Math.ceil(title.length * 0.42 + 1.2))
|
const w = Math.max(4, Math.ceil(lines.reduce((m, l) => Math.max(m, l.name.length), 0) * LABEL_CHAR + 2.6), Math.ceil(title.length * 0.34 + 0.8))
|
||||||
const inner = node.kind === 'portin' ? w : 0
|
const inner = node.kind === 'portin' ? w : 0
|
||||||
const face: 1 | -1 = node.kind === 'portin' ? 1 : -1
|
const face: 1 | -1 = node.kind === 'portin' ? 1 : -1
|
||||||
const bus: PinInfo = { key: 'bus', label: '', dx: inner, dy: 0, bus: true, conn: node.conn }
|
const bus: PinInfo = { key: 'bus', label: '', dx: inner, dy: 0, bus: true, conn: node.conn }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue