Skip to content

Draw tab: live stroke preview uses the selected pen's colour and thickness - #1793

Closed
alosslessdev wants to merge 1 commit into
storytold:mainfrom
alosslessdev:draw/pen-preview
Closed

alosslessdev wants to merge 1 commit into
storytold:mainfrom
alosslessdev:draw/pen-preview

Conversation

@alosslessdev

Copy link
Copy Markdown
Contributor

Fixes #1786.

The Draw tab's live stroke preview now uses the selected pen's colour and thickness, so the line under the pointer is the ink that will be committed — the highlighter preview is a thick yellow line, not a thin blue one.

What changed

  • crates/ui-egui/src/grid.rs: the in-progress stroke is painted with session.draw_color and session.draw_width (falling back to 2 pt when no width has been set).
  • ink_color: parses #RRGGBB into a painter colour, defaulting to pen blue on bad input; no panics.
  • A UI test (crates/ui-egui/tests/draw_preview.rs) drives a pointer drag with a red 8 pt pen and asserts the painted path carries exactly that colour and width.

Control order, labels and menus are unchanged; they are separate PRs (#1783, #1784, #1785). Cut from main, independent of #1767/#1187.

Verification

  • cargo fmt --all -- --check
  • cargo clippy -p gridcraft-ui-egui --all-targets -- -D warnings
  • cargo test -p gridcraft-ui-egui (full crate suite, including the new preview test)
  • docs/ui-parity.md revision history updated; contributors/people.toml entry per AGENTS.md

@alosslessdev

Copy link
Copy Markdown
Contributor Author

Round-trip test: Excel 16.0 (Build 20430) ↔ GridCraft @ 7b3d09e

Result: this PR's preview change is fine, but Excel pen strokes do not round-trip through main's XLSX reader. An existing PR already owns that fix, so I stopped before opening a duplicate.

What Excel writes

A 0.35 mm red pen stroke drawn with Excel's Draw tab (blank workbook, SaveAs .xlsx) contains:

  • xl/ink/ink1.xml — InkML: brush #E71224, width 0.035 cm; trace 5 1 24575,'-4'0'0,"1420"536"0,513 195 0,-71-27-8191 (X/Y in 1/1000 cm, with first/second differences, per InkML §3.2).
  • xl/drawings/drawing1.xml — mc:AlternateContent → mc:Choice → xdr:contentPart r:id (relationship type customXml) plus an mc:Fallback.
  • xl/media/image1.png — the raster fallback.

Excel → GridCraft

gridcraft-cli info excel-ink-red.xlsx --json reports:

"images": 1,
"shapes": 0

The stroke is imported from the fallback PNG as a picture, not as editable ink, so Ink to Shape cannot act on it. Saving from GridCraft writes the picture back; Excel reopens a picture, not ink.

GridCraft → Excel

draw.pen {color:"#D13B2F", width:8} + draw.stroke saved to .xlsx opens in Excel repair-free with one object (135 × 43.2 pt), but as a freeform shape (Shapes.Count = 1, Type = 5), not an Ink content part (Type = 23). Excel's resave keeps a shape, not InkML.

Duplicate

#1187 ("Draw: typed ink, Excel InkML and Draw with Trackpad") already implements this: crates/xlsx/src/inkml.rs parses the same difference-encoded traces and brush units, and writes InkML behind mc:AlternateContent with a DrawingML fallback and tests. The fix belongs in #1187; no new PR was opened. #551 is closed. The "external Excel rendering and repair-free opening remain unverified" note in docs/file-format-parity.md is now half-verified: Excel opens the current DrawingML ink repair-free, but not as editable ink.

This PR

cargo test -p gridcraft-ui-egui --test draw_preview passes. One minor preview/commit mismatch: the preview paints draw_width as a float, while draw.stroke rounds the width to an integer (stored in the fill red channel), so 1.5 pt previews at 1.5 but commits at 2. Independent of the round-trip issue.

I stopped before the all-pens/eraser matrix because #1187 already owns the InkML work.

@alosslessdev

Copy link
Copy Markdown
Contributor Author

Closing in favour of #1187, which shares stroke_shape() between the preview and draw.stroke and covers #1786. The Excel/InkML round-trip findings above remain the evidence for #1187's crates/xlsx/src/inkml.rs work.

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.

Draw tab: live stroke preview uses the selected pen's colour and thickness

1 participant