Skip to content

Commit 7a0bf26

Browse files
committed
feat(ui): normalize canvas cursor states
1 parent b618543 commit 7a0bf26

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/simulator/src/engine.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,44 @@ export function renderCanvas(scope) {
290290
ctx.stroke()
291291
ctx.fill()
292292
}
293-
if (simulationArea.hover !== undefined) {
294-
simulationArea.canvas.style.cursor = 'pointer'
295-
} else if (simulationArea.mouseDown) {
296-
simulationArea.canvas.style.cursor = 'grabbing'
297-
} else {
298-
simulationArea.canvas.style.cursor = 'default'
293+
// Current object under the mouse (Node / Wire / undefined)
294+
const hover = simulationArea.hover;
295+
const type = hover?.objectType;
296+
297+
//Mouse is pressed → dragging or panning
298+
if (simulationArea.mouseDown) {
299+
// While dragging nodes or panning the canvas
300+
simulationArea.canvas.style.cursor = 'grabbing';
301+
302+
}
303+
//Mouse is hovering over something
304+
else if (hover) {
305+
306+
// Hovering over a Node
307+
if (type === 'Node') {
308+
simulationArea.canvas.style.cursor = 'crosshair';
309+
310+
// Hovering over a Wire
311+
}
312+
else if (type === 'Wire') {
313+
simulationArea.canvas.style.cursor = 'pointer';
314+
315+
// Hovering over other objects (modules, subcircuits, etc.)
316+
}
317+
else {
318+
simulationArea.canvas.style.cursor = 'move';
319+
}
320+
321+
}
322+
//Idle canvas (no hover, no mouse down)
323+
else {
324+
// Default canvas interaction state
325+
simulationArea.canvas.style.cursor = 'grab';
326+
}
327+
328+
329+
299330
}
300-
}
301331

302332
/**
303333
* Function to move multiple objects and panes window

0 commit comments

Comments
 (0)