Honor media aspect ratios in masonry cards #3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "t3code/fix-masonry-media-aspect-ratios"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The masonry layout sized every media box from a hash of the post ID (
[320, 400, 480, 360][masonry_card_variant(post)]) and cropped the image to fit (ContentFit::Cover), so a 2:3 portrait and a 9:1 panorama both landed in the same shapeless box. Column weights used the same fake heights, so packing ignored what the posts actually looked like.Reddit listings declare the media's native pixel size, so this carries it through
PostSummary(media_width/media_height, serde defaults keep old cached feeds valid) and derives each card's media height from the real aspect ratio against the live column width, clamped to 160–560 px so extremes crop instead of dominating a column. Posts without declared dimensions keep the old varied estimates, which measured heights already replace once rows allocate.core: extract dimensions frompreview.images[0].source, the gallery cover'smedia_metadata.s.x/y, and video rendition sizes, withthumbnail_width/heightas a fallback (api.rs)adwaita:masonry_media_heightnow scalesheight / width × column widthinstead of hashing; the same heights drive both the rendered media box and the column-packing weightsBefore
The stairwell (2:3 portrait) and the square cat photo are cropped into nearly the same flat box as the wide shots.
After
Portrait and square media keep their shape and the columns pack by real height.
Tests
masonry_media_keeps_the_declared_aspect_ratio(adwaita): portrait fills, panorama clamps, heights scale with column width, unknown/zero dimensions fall backcargo test: core 114 passed, adwaita 75 passed (no-default-features; the default-feature build hits a pre-existing boring-sys/clang issue in this sandbox).