Added Cover and Contain scaling modes for ImageNode#24786
Open
Kees-van-Beilen wants to merge 4 commits into
Open
Added Cover and Contain scaling modes for ImageNode#24786Kees-van-Beilen wants to merge 4 commits into
Cover and Contain scaling modes for ImageNode#24786Kees-van-Beilen wants to merge 4 commits into
Conversation
- Added Cover and Contain variants in ImageScalingMode - Modified image_scaling test to now also show Cover and Contain
ickshonpe
suggested changes
Jun 28, 2026
Contributor
There was a problem hiding this comment.
Technically seems good, both Cover and Contain seem to work correctly with different aspect ratios and compose with clipping etc.
I think though the API doesn't need to be per-axis and the image rect calculations would be better placed in the image extraction function.
| Border(u32), // shader flags | ||
| } | ||
|
|
||
| #[derive(Default, Clone, Copy, Debug, PartialEq)] |
Contributor
There was a problem hiding this comment.
I'm not sure it makes sense for this to be a per-axis settings, aspect-ratio preservation is inherently 2d. And it'd probably clarify whatever the clamp_v_to_cover confusion is about.
| atlas_scaling: Option<Vec2>, | ||
| flip_x: bool, | ||
| flip_y: bool, | ||
| scaling_mode: UiItemScaling, |
Contributor
There was a problem hiding this comment.
I think it would make more sense to do the image fit calculations in the extraction function. The prepare function isn't the best place for logic like this.
Suggested change
| scaling_mode: UiItemScaling, |
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.
CoverandContainvariants inNodeImageModeCoverandContainObjective
ImageNodeto preserve aspect ratio #21560Solution
Contain&CovertoNodeImageModebounding_rect_sizeinprepare_nodesfor images. Which replacesrect_sizein the point ans position calculation.UiItemScaling, which is a per axis scaling mode (Stretch, Contain, Cover), toExtractedUiItem::Node. To ensure future refactors remain easyTesting
image_node_resizingexample to also test the new modes, these changes have been pushed.RectandTextureAtlasbehaviour, which seems to be in order.Showcase
Click to view showcase
This PR adds the following public cases:
NodeImageMode::ContainNodeImageMode::CoverThese do exactly the same as their css counterparts. Example showcase of the new scaling modes in action: