STORE & HOOKS
useWhiteboardLayout
Given a widths map, returns grid-snapped { x, y } positions for the initial layout of a row of panels.
PREVIEW
{
"positions": {
"settings": {
"x": 20,
"y": 20
},
"layers": {
"x": 260,
"y": 20
},
"inspector": {
"x": 500,
"y": 20
}
},
"panelWidth": {
"settings": 220,
"layers": 220,
"inspector": 220
},
"layout": {
"startX": 20,
"y": 20,
"gap": 20
}
}SOURCE
import { useWhiteboardLayout, WHITEBOARD_GRID } from '@objectifthunes/whiteboard'
const WIDTHS = { settings: 220, layers: 220, inspector: 220 }
export function App() {
const opts = useMemo(
() => ({ widths: WIDTHS, startX: 20, y: 20, gap: WHITEBOARD_GRID }),
[],
)
const { positions } = useWhiteboardLayout(opts)
return (
<WhiteboardShell>
<FloatingPanel title="Settings" defaultPosition={positions.settings} />
<FloatingPanel title="Layers" defaultPosition={positions.layers} />
<FloatingPanel title="Inspector" defaultPosition={positions.inspector} />
</WhiteboardShell>
)
}NOTES
The hook re-derives positions whenever the widths object identity changes. Inline literals (widths={{ a: 100 }}) recompute on every render — wrap in useMemo or hoist to module scope.
Returns { layout, panelWidth, positions }. Positions are snapped to the canvas grid (multiples of WHITEBOARD_GRID) so panels line up out of the gate.