From 821f468748ee20775f474249ab44a99e67d3bafe Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Fri, 23 Oct 2026 12:33:47 +0200 Subject: [PATCH] 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) --- app/assets/css/main.css | 194 ++++++++++++++++++++++++++++ app/components/editor/BottomBar.vue | 170 ++++++++++++++++-------- app/components/editor/PartThumb.vue | 38 ++++++ 3 files changed, 348 insertions(+), 54 deletions(-) create mode 100644 app/components/editor/PartThumb.vue diff --git a/app/assets/css/main.css b/app/assets/css/main.css index 40d6dc8..8b7506f 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -4929,3 +4929,197 @@ button.tile:hover { .unused-list a { 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; + } +} diff --git a/app/components/editor/BottomBar.vue b/app/components/editor/BottomBar.vue index 1dc7433..e5ee790 100644 --- a/app/components/editor/BottomBar.vue +++ b/app/components/editor/BottomBar.vue @@ -3,6 +3,8 @@ // 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 // 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 { BASIC_GROUPS } from '~/composables/useParts' import type { ComponentDef, NodeKind } from '~/lib/logic/types' @@ -28,16 +30,51 @@ const cats = computed(() => [ // ── Flyout: opens on pointing, stays while the pointer is over it ── const open = ref(null) -const anchor = ref(0) let timer: ReturnType | undefined const dock = ref() -/** Where the list opens: centred above the pointer, kept inside the canvas. */ +const fly = ref() +/** 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) { const r = dock.value!.getBoundingClientRect() - const half = 130 - anchor.value = Math.min(Math.max(x - r.left, half), Math.max(half, r.width - half)) + at.value = { ...at.value, x: x - r.left, dock: r.width } } +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() +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) { clearTimeout(timer) @@ -52,6 +89,8 @@ function show(id: string, e: PointerEvent) { function leave() { 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) } @@ -73,6 +112,13 @@ function pick(kind: NodeKind, chip?: string, conn?: string) { 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. */ const activeCat = computed(() => { 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. const shown = computed(() => pinned.value.filter(p => p.kind !== 'chip' || p.chip)) 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) { if (e.key === 'Escape' && open.value) { @@ -103,31 +148,35 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))