Skip to content

feat(ui-egui): a pen on the page picks up a pen, typing goes back (#9) - #238

Merged
DWAA1660 merged 5 commits into
AlienTechSoftware:mainfrom
DWAA1660:feat/auto-pen-mode/9
Nov 14, 2026
Merged

DWAA1660 merged 5 commits into
AlienTechSoftware:mainfrom
DWAA1660:feat/auto-pen-mode/9

Conversation

@DWAA1660

Copy link
Copy Markdown
Collaborator

Parts 1 and 2 of #9: OneNote's automatic switching between drawing and typing.

What changes

  1. Automatic pen mode. A pen that touches the page while the caret is the pointer picks up the pen last in hand (colour and thickness included), and that same touch draws.
  2. Automatic typing mode. Typing with a pen, the eraser or another ink tool in hand goes back to the caret, and the words land where the caret was before the pen. Shortcuts (Ctrl/Cmd/Alt + key) don't switch.

Only a contact that reports a force counts as a pen. A mouse or a finger on a touch screen changes nothing. In practice this works where the pen's pressure reaches the window: Windows (winit WM_POINTER) and the web build (pointer events). On macOS and Linux winit drops tablet fields, so tools are still picked by hand there (see stylus.rs).

Part 3 (fingers pan and pinch the canvas) is not included, so this PR does not close #9.

How

  • Stylus::landed() reports where a pen came down this frame (a touch Start with a force).
  • NoteCraftApp::switch_by_device runs before the page each frame.
  • egui gives a press to whatever widget was under it on the previous frame, which was the text, not the ink layer. So the app asks the ink layer for one frame to take the press as its own (inkpad::claim_press → ctx.set_dragged_id). Without that, the touch that switched the tool drew nothing.
  • The caret's text box is not drawn while a pen is in hand, so it has lost the keyboard. The typed text is held, the caret's line is given focus again at the caret's old position, and the text is replayed once it has the keyboard (replay_typing). A leftover cross-line selection is dropped so there is a text box to type into.
  • docs/gaps.md describes the behaviour.

Tests

  • UI test a_pen_on_the_page_picks_up_the_last_pen_and_typing_puts_it_down checks:
    • a finger touch with no force changes nothing and draws nothing;
    • a pen touch picks up the last pen (red) and draws one stroke;
    • Ctrl+B keeps the pen in hand;
    • typing Z goes back to the caret and inserts Z exactly where the caret was.
  • Unit test a_pen_landing_is_seen_for_its_frame_only.
  • cargo xtask ci passes locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y4im4nvZvQHZdShop1ff8w

DWAA1660 and others added 5 commits November 13, 2026 18:37
…ienTechSoftware#9)

OneNote's automatic switching between drawing and typing, parts 1 and 2
of AlienTechSoftware#9:

- A pen that touches the page while the caret is the pointer picks up
  the pen last in hand (colour, thickness and all), and that same touch
  draws. Only a contact that reports a force counts as a pen, so a mouse
  or a finger on a touch screen changes nothing. That means Windows and
  the web build, where the pen's pressure reaches the window.
- Typing with an ink tool in hand goes back to the caret. The words land
  where the caret was before the pen. Shortcuts such as Ctrl+B do not
  switch.

Stylus::landed reports a pen coming down. The press that switched the
tool began before the ink layer existed, so the window asks the ink layer
(inkpad::claim_press) to take it as its own. Typed text is held until the
caret's line has the keyboard again, then replayed.

Part 3 of AlienTechSoftware#9 (fingers pan and pinch the canvas) is not included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y4im4nvZvQHZdShop1ff8w
@DWAA1660
DWAA1660 merged commit fda8134 into AlienTechSoftware:main Nov 14, 2026
10 checks passed
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.

Automatic switch between drawing and typing like in onenote

1 participant