Skip to content

fix(renderer): guard card shadow from clipping at canvas edge - #25

Merged
suradet-ps merged 2 commits into
mainfrom
fix/card-shadow-padding-guard
Aug 25, 2026
Merged

fix(renderer): guard card shadow from clipping at canvas edge#25
suradet-ps merged 2 commits into
mainfrom
fix/card-shadow-padding-guard

Conversation

@suradet-ps

Copy link
Copy Markdown
Owner

Problem

The code-card drop shadow paints up to blur + offsetY (30px) beyond the card edge, but the canvas padding is user-controlled down to 16px (UI slider minimum). The shadow was silently clipped at the canvas edge — the exact 'painted overflow invisible to text metrics' class of bug measureText() is blind to.

Changes

  1. refactor — move the hardcoded shadow values (shadowBlur 20 / offsetY 10) from canvas.rs into shared constants in renderer::layout; the SVG pipeline now derives dy/stdDeviation from the same constants (single source of truth).
  2. fixcompute_layout clamps the effective padding to CARD_SHADOW_SAFE_MARGIN (30px) whenever the window frame is on, so the shadow always fits inside the canvas. Split-screen dividers follow the clamped card_y instead of raw options.padding.
  3. tests — 3 new pure-math unit tests in layout.rs (no DOM needed): padding below the margin is raised, padding at/above it is untouched, and the no-frame path is unaffected.

Verification

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace ✓ (13 renderer tests, incl. 3 new)

Known limitation (follow-up)

The SVG drop-shadow filter region (x="-10%" y="-5%") is percentage-based and can also clip on very short cards; out of scope here.

Single source of truth for shadow blur/offset shared by the canvas and SVG
pipelines. SVG derives dy/stdDeviation from the same values, so the two
renderers cannot drift apart.
The card drop shadow paints up to blur + offsetY beyond the card edge, but
text metrics (measureText) are blind to painted overflow. compute_layout now
clamps the effective padding to CARD_SHADOW_SAFE_MARGIN when the window frame
is on, so a small padding (UI minimum is 16px, shadow extent is 30px) can no
longer cut the shadow off at the canvas edge. The split-screen divider now
follows the clamped card_y instead of raw options.padding.
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
codeshot Ready Ready Preview Aug 25, 2026 5:53am

@suradet-ps
suradet-ps merged commit 0cbee29 into main Aug 25, 2026
13 checks passed
@suradet-ps
suradet-ps deleted the fix/card-shadow-padding-guard branch August 25, 2026 06:05
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.

1 participant