AppKit: ContentFit.Cover distorts the image instead of cropping it #6

Open
opened 2026-09-28 21:57:05 -07:00 by rleibman · 0 comments
Owner

Recorded as a gap when the Apple renderer landed and still open: Prop.Fit(ContentFit.Cover) distorts on AppKit. Cover means fill the frame, preserve aspect ratio, crop the overflow — distorting is the one thing it must not do, since it is the fit used for avatars and hero images where the wrong aspect ratio is immediately visible.

NSImageView.imageScaling has no cover mode: .scaleProportionallyUpOrDown is Contain, .scaleAxesIndependently is Fill (and is almost certainly what is wired up now). Cover needs either a layer-backed view with contentsGravity = .resizeAspectFill and masksToBounds = true, or a custom NSView that draws the image into an aspect-fill rect.

Check UIKit at the same time: UIView.ContentMode.scaleAspectFill does the right thing, so that side may already be correct — confirm rather than assume, and say which in the report.

How to verify. Render a deliberately non-square image (e.g. 400x100) into a square frame under each of Contain, Cover and Fill, and assert the drawn aspect ratio: Contain and Cover preserve it, Fill does not. Screenshot the three side by side into docs/screenshots/ — this is a defect that is obvious in a picture and invisible in a log.

See docs/12-component-status.md §12.2.

Recorded as a gap when the Apple renderer landed and still open: `Prop.Fit(ContentFit.Cover)` distorts on AppKit. `Cover` means *fill the frame, preserve aspect ratio, crop the overflow* — distorting is the one thing it must not do, since it is the fit used for avatars and hero images where the wrong aspect ratio is immediately visible. `NSImageView.imageScaling` has no cover mode: `.scaleProportionallyUpOrDown` is `Contain`, `.scaleAxesIndependently` is `Fill` (and is almost certainly what is wired up now). Cover needs either a layer-backed view with `contentsGravity = .resizeAspectFill` and `masksToBounds = true`, or a custom `NSView` that draws the image into an aspect-fill rect. Check UIKit at the same time: `UIView.ContentMode.scaleAspectFill` does the right thing, so that side may already be correct — confirm rather than assume, and say which in the report. **How to verify.** Render a deliberately non-square image (e.g. 400x100) into a square frame under each of `Contain`, `Cover` and `Fill`, and assert the drawn aspect ratio: `Contain` and `Cover` preserve it, `Fill` does not. Screenshot the three side by side into `docs/screenshots/` — this is a defect that is obvious in a picture and invisible in a log. See `docs/12-component-status.md` §12.2.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rleibman/scala-ui#6
No description provided.