Skip to content

Make drawRoundedImage keep aspect ratio with centered cover fit - #65

Merged
treeform merged 1 commit into
masterfrom
rounded-cover
Sep 1, 2026
Merged

treeform merged 1 commit into
masterfrom
rounded-cover

Conversation

@treeform

@treeform treeform commented Sep 1, 2026

Copy link
Copy Markdown
Owner

What

Follow-up to #64 — this commit was pushed to the rounded-image branch just after that PR merged, so it never landed.

drawRoundedImage now keeps the image's aspect ratio instead of stretching: the image is scaled uniformly to cover the destination rect, centered, and the overflow is cropped (CSS object-fit: cover behavior).

How

Only the UV mapping changes; the nine-piece geometry is untouched. A uniform cover scale (max(size.x / imgW, size.y / imgH)) shifts the UV origin to a centered, aspect-matched sub-rect of the atlas entry, and all rect and fan vertices map through that shared sub-rect, so UVs stay continuous across pieces.

Verified

Framebuffer captures via tests/manual_rounded_image.nim --screenshot: a wide 300x200 rect crops the source's top/bottom rows, a tall 150x400 rect crops the left/right columns, and in both the color-block proportions match the original 48x48 debug.9patch.

🤖 Generated with Claude Code

The image is scaled uniformly to cover the destination rect,
centered, and the overflow is cropped instead of stretching.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@treeform
treeform merged commit d1e3ec0 into master Sep 1, 2026
7 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.

1 participant