Skip to content

gpui: Keep explicitly sized images at their given size - #63103

Open
nolight132 wants to merge 1 commit into
zed-industries:mainfrom
nolight132:main
Open

gpui: Keep explicitly sized images at their given size#63103
nolight132 wants to merge 1 commit into
zed-industries:mainfrom
nolight132:main

Conversation

@nolight132

Copy link
Copy Markdown
Contributor

Objective

img sets the image's intrinsic aspect ratio on the element style whenever the caller didn't set one. When the element also has an explicit width and height, the intrinsic ratio still participates in layout and can resize the element.

This also defeats ObjectFit::Cover (#61383): once the element grows to match the image's ratio, there is nothing left to crop, so the image renders whole and rounded corners are computed against the inflated rectangle.

Solution

Only assign the intrinsic aspect ratio when at least one dimension of the element is Auto, i.e. when the ratio is actually needed to derive a missing size. The element now keeps its given size with both dimensions definite.

Testing

  • Added image_object_fit_cover_crops_portrait_to_fixed_element_bounds, a portrait counterpart of the existing cover test that uses an absolute .size(px(100.)) instead of size_full(). It fails on main (sprite bounds come out 100x200) and passes with this change.
  • cargo test -p gpui passes.
  • Verified visually on Linux Wayland with the example below.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Showcase

A 300x400 portrait image rendered at a fixed square size:

img(portrait_300x400)
    .size(px(160.))
    .rounded_full()
    .object_fit(ObjectFit::Cover)
Before After
before after

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Aug 23, 2026
@RemcoSmitsDev RemcoSmitsDev added the area:gpui GPUI rendering framework support label Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpui GPUI rendering framework support cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants