Skip to content

Draw: the live pen stroke is drawn as the ink it commits (fixes #1786) - #3229

Merged
h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
hectorviov:fix/ink-preview-pen-colour
Nov 3, 2026
Merged

h-a-n-a-s-h-i merged 2 commits into
storytold:mainfrom
hectorviov:fix/ink-preview-pen-colour

Conversation

@hectorviov

@hectorviov hectorviov commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1786

What

While you drag with a pen on the Draw tab, the stroke under the pointer was always painted blue at 2 pt, whatever pen or highlighter was chosen. The committed stroke uses the chosen pen, so the preview and the result disagreed: a yellow highlighter previewed as a thin blue line. In Excel the line you draw is the ink that will be committed.

crates/ui-egui/src/grid/interact.rs gets pen_ink(color, width, theme), which gives the colour and width the stroke will have:

  • the pen's colour (pen blue when none is set or the hex doesn't parse), resolved as Ink shapes resolve theirs;
  • the pen's width as draw.stroke stores it (2 pt by default, 0.5–40 pt, whole points);
  • the 45 % translucency Ink shapes are painted with above 8 pt (a highlighter).

The live preview uses it.

Comparison

Pen GridCraft main (178f3eb), while dragging GridCraft with this PR, while dragging Committed ink (both)
red, 3 pt blue, 2 pt red, 3 pt red, 3 pt
yellow highlighter, 12 pt blue, 2 pt yellow at 45 %, 12 pt yellow at 45 %, 12 pt
none set yet blue, 2 pt blue, 2 pt blue, 2 pt

Excel: the line under the pointer is the ink that will be committed, as the issue describes. I couldn't draw with a pen in Excel on this machine (pointer drags there didn't register), so that column wasn't observed by me.

Tests

  • grid::interact::tests::the_pen_preview_is_the_ink_the_stroke_commits covers a pen colour and width, the defaults, a bad colour and a too-thin width, and a translucent highlighter. It fails when the helper returns the old constant (blue, 2 pt).
  • cargo xtask ci passes.

Anything a reviewer should look at first

  • The width rounding and the 8 pt threshold copy what draw.stroke and chartview already do, so the preview can't drift from the committed ink without one of those tests noticing. If you'd prefer, the threshold could become a shared constant in the engine.
  • docs/ui-parity.md gets a change note and a revision row.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Pen-stroke previews now match the selected pen’s color and thickness. Invalid colors or widths use consistent fallback values.
    • Ink strokes scale correctly with sheet zoom. Strokes wider than 8 points appear translucent, while narrower strokes retain their original color.
  • Documentation
    • Updated the Draw tab’s review notes to reflect the pen-stroke preview behavior.

While dragging with a pen, the stroke under the pointer was always
painted blue at 2 pt, whatever pen or highlighter was chosen, so the
preview and the committed ink disagreed (a highlighter previewed as a
thin blue line). The preview now uses the colour and width draw.stroke
stores (pen blue and 2 pt by default, 0.5-40 pt, whole points) and the
translucency Ink shapes are painted with above 8 pt.

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

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The live pen-stroke preview now uses the configured pen color and width, resolved against the workbook theme. Ink wider than 8 points receives reduced color intensity. Tests cover preview defaults and styling, plus rendered ink alpha at multiple zoom levels.

Changes: Pen stroke preview and ink rendering

Layer / File(s) Summary
Width-based ink styling
crates/ui-egui/src/chartview.rs, crates/ui-egui/tests/it/ink_render.rs, crates/ui-egui/tests/it/main.rs
Ink wider than 8 points uses reduced color intensity based on point width, not zoom-scaled width. Integration tests check stroke alpha at 50%, 100%, and 200% zoom.
Resolve and render pen preview values
crates/ui-egui/src/grid/interact.rs, docs/ui-parity.md
The preview uses configured color and width. pen_ink applies fallback values, clamps and rounds widths, and applies the wide-ink styling. Unit tests cover these cases, and the UI parity history records the preview change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: prxnvt, echelon

Merge Risk: Minimal · up to 2adfd

The preview matches the committed stroke in the examined cases. No merge-blocking issue was found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: the live pen stroke now matches the committed ink. The issue reference is relevant and does not obscure the title.
Linked Issues check Passed [#1786] The live Draw-tab preview now calls pen_ink with session.draw_color and session.draw_width. pen_ink uses pen blue for unset or invalid colors, uses 2 pt for nonpositive widths, and app…
Out of Scope Changes check Passed The changes remain within [#1786]. The chartview::ink_color change makes committed ink use point width for the same preview-versus-commit behavior. The unit and integration tests verify that behavio…
Full details: Linked Issues check

Explanation

[#1786] The live Draw-tab preview now calls pen_ink with session.draw_color and session.draw_width. pen_ink uses pen blue for unset or invalid colors, uses 2 pt for nonpositive widths, and applies the committed width clamping and rounding. The preview scales the point width by zoom. The preview uses the same theme resolution and wide-ink translucency as committed ink. The unit test covers selected values, defaults, invalid input, thin input, and highlighter styling. The integration test verifies translucency by point width at multiple zoom levels.

Full details: Out of Scope Changes check

Explanation

The changes remain within [#1786]. The chartview::ink_color change makes committed ink use point width for the same preview-versus-commit behavior. The unit and integration tests verify that behavior. The documentation change records the Draw-tab parity update. No changes affect the issue's excluded control order, labels, or menus.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 4 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 2fe3bfc and 2adfd55.

Files selected for processing: 4
  • crates/ui-egui/src/chartview.rs
  • crates/ui-egui/src/grid/interact.rs
  • crates/ui-egui/tests/it/ink_render.rs
  • crates/ui-egui/tests/it/main.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

@hectorviov

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread crates/ui-egui/src/grid/interact.rs Resolved
…n and once committed

Addresses CodeRabbit review on storytold#3229, "Use the same translucency
threshold as committed ink": the preview judged the pen by its width in
points, the committed stroke by its width on screen, so at 50% a 12 pt
highlighter turned opaque once committed and at 200% a 6 pt pen turned
translucent. Both now use chartview::ink_color, which goes by the
stroke's width in points, so the two agree and neither changes with
the zoom.

Test: ink_render::ink_translucency_follows_the_pen_not_the_zoom.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit cb4b7af into storytold:main Nov 3, 2026
1 check passed
@echelon

echelon commented Nov 3, 2026

Copy link
Copy Markdown
Member

Merged — thank you @hectorviov 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.

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

3 participants