Skip to content

Canvas: a click just outside the canvas doesn't reach the tools - #233

Merged
bflatastic merged 1 commit into
storytold:mainfrom
theironchef:fix/canvas-edge-click
Oct 7, 2026
Merged

bflatastic merged 1 commit into
storytold:mainfrom
theironchef:fix/canvas-edge-click

Conversation

@theironchef

Copy link
Copy Markdown
Contributor

Fixes #232.

Problem: egui reports the canvas response as hovered for a pointer a few pixels outside its rect (its interaction radius). But handle_input (crates/ui-egui/src/canvas.rs) only takes pointer positions inside the rect (hover), and for a press there it fell back to rect.center().

So a click in the band around the canvas reached the active tool at the centre of the view. That band includes just below the document tabs, beside the panel strip and above the hint bar. With the Selection tool the click selected whatever was in the middle, with the Type tool it started text there, and drawing tools drew from there. The middle-button pan had the same fallback.

Change: a primary press, and a middle-button pan, now start only when the pointer is on the canvas itself: && let Some(p) = hover in place of hover.unwrap_or(rect.center()). A press in the band does nothing, as on any other empty part of the window.

Tests

  • New canvas::tests::a_click_just_outside_the_canvas_does_not_reach_the_tool. It lays the canvas out under a 40-point bar, as under the document tabs, with a square in the middle of the view. A click 2 px above the canvas leaves nothing selected, and a click at the canvas centre selects the square.
  • It fails on main ("a click above the canvas selected [NodeId(2)]") and passes with this change.
  • cargo test -p vectorcraft-ui-egui: 526 passed.
  • cargo clippy -p vectorcraft-ui-egui --all-targets -- -D warnings (Rust 1.99): clean.
  • cargo fmt --all -- --check: clean.

I found this by driving a release build on Windows with real mouse input. I didn't run the full cargo xtask ci (wasm step) here.

🤖 Generated with Claude Code

egui counts a press a few pixels outside the canvas as hovering it (its
interaction radius), but the canvas only takes pointer positions inside
its rect, so such a press fell back to the canvas's centre: a click
just below the document tabs or beside the panels selected, typed or
drew in the middle of the view. Presses, and middle-button pans, now
start only on the canvas itself.

Fixes storytold#232.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bflatastic

Copy link
Copy Markdown
Member

Thanks, merged! Good catch with real mouse input: a press inside egui's interaction radius falling back to the view's centre is exactly the kind of bug synthetic tests miss. I checked it against the canvas context menu that landed in #229 (right-click and dismiss), and the two work together. The full cargo xtask ci (wasm included) passed with it rebased onto current main. Thank you for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: A click just outside the canvas edge acts as a click in the centre of the view

2 participants