gpui: Fix img aspect ratio overriding existing value - #62367
Merged
MrSubidubi merged 3 commits intoAug 9, 2026
Conversation
MrSubidubi
approved these changes
Aug 9, 2026
MrSubidubi
left a comment
Member
There was a problem hiding this comment.
Nice catch, thank you! Also appreciate you adding a test upfront for this!
MrSubidubi
enabled auto-merge
August 9, 2026 11:21
audivir
pushed a commit
to audivir/zed
that referenced
this pull request
Aug 10, 2026
…s#62367) # Objective The `gpui::img` element always overrides the `aspect_ratio` field, so if you have an image element that applies its own `.aspect_ratio()` it just gets wiped out. ## Solution Only apply the aspect ratio default if one is not already set. ## Testing It's a very minor change but I did add a small test to ensure it actually gets overridden. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase This came from an issue where vertical images inside an element (square in this case, as you'd see in an image gallery) do not behave correctly with `object_fit` values of `ObjectFit::Contain` or `ObjectFit::ScaleDown`. This was simply because despite the image element having a fixed square size (`img().size(px(200.))`), the aspect ratio would be forced to the ratio of the image itself, so vertical images weren't being properly fitted into their containers. Minimal repro for that issue: https://github.com/zaknesler/gpui-object-fit So with this change, you can set `.aspect_square()` and the object fit will behave as you'd expect: <img width="1237" height="986" alt="image" src="https://github.com/user-attachments/assets/5b1045a8-bd71-4b77-8bbd-c3b12112bcb0" /> --- Release Notes: - gpui: Fix image element's aspect ratio overriding existing value
HyacinthHaru
pushed a commit
to HyacinthHaru/z3rm
that referenced
this pull request
Aug 16, 2026
…s#62367) # Objective The `gpui::img` element always overrides the `aspect_ratio` field, so if you have an image element that applies its own `.aspect_ratio()` it just gets wiped out. ## Solution Only apply the aspect ratio default if one is not already set. ## Testing It's a very minor change but I did add a small test to ensure it actually gets overridden. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase This came from an issue where vertical images inside an element (square in this case, as you'd see in an image gallery) do not behave correctly with `object_fit` values of `ObjectFit::Contain` or `ObjectFit::ScaleDown`. This was simply because despite the image element having a fixed square size (`img().size(px(200.))`), the aspect ratio would be forced to the ratio of the image itself, so vertical images weren't being properly fitted into their containers. Minimal repro for that issue: https://github.com/zaknesler/gpui-object-fit So with this change, you can set `.aspect_square()` and the object fit will behave as you'd expect: <img width="1237" height="986" alt="image" src="https://github.com/user-attachments/assets/5b1045a8-bd71-4b77-8bbd-c3b12112bcb0" /> --- Release Notes: - gpui: Fix image element's aspect ratio overriding existing value (cherry picked from commit 59b2ebf)
playdohface
pushed a commit
to playdohface/zed
that referenced
this pull request
Aug 29, 2026
…s#62367) # Objective The `gpui::img` element always overrides the `aspect_ratio` field, so if you have an image element that applies its own `.aspect_ratio()` it just gets wiped out. ## Solution Only apply the aspect ratio default if one is not already set. ## Testing It's a very minor change but I did add a small test to ensure it actually gets overridden. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase This came from an issue where vertical images inside an element (square in this case, as you'd see in an image gallery) do not behave correctly with `object_fit` values of `ObjectFit::Contain` or `ObjectFit::ScaleDown`. This was simply because despite the image element having a fixed square size (`img().size(px(200.))`), the aspect ratio would be forced to the ratio of the image itself, so vertical images weren't being properly fitted into their containers. Minimal repro for that issue: https://github.com/zaknesler/gpui-object-fit So with this change, you can set `.aspect_square()` and the object fit will behave as you'd expect: <img width="1237" height="986" alt="image" src="https://github.com/user-attachments/assets/5b1045a8-bd71-4b77-8bbd-c3b12112bcb0" /> --- Release Notes: - gpui: Fix image element's aspect ratio overriding existing value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
The
gpui::imgelement always overrides theaspect_ratiofield, so if you have an image element that applies its own.aspect_ratio()it just gets wiped out.Solution
Only apply the aspect ratio default if one is not already set.
Testing
It's a very minor change but I did add a small test to ensure it actually gets overridden.
Self-Review Checklist:
Showcase
This came from an issue where vertical images inside an element (square in this case, as you'd see in an image gallery) do not behave correctly with
object_fitvalues ofObjectFit::ContainorObjectFit::ScaleDown.This was simply because despite the image element having a fixed square size (
img().size(px(200.))), the aspect ratio would be forced to the ratio of the image itself, so vertical images weren't being properly fitted into their containers.Minimal repro for that issue: https://github.com/zaknesler/gpui-object-fit
So with this change, you can set
.aspect_square()and the object fit will behave as you'd expect:Release Notes: