Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageMode::KeepAspect interacts in a confusing way with AlignItems #6637

Closed
bzm3r opened this issue Nov 15, 2022 · 6 comments
Closed

ImageMode::KeepAspect interacts in a confusing way with AlignItems #6637

bzm3r opened this issue Nov 15, 2022 · 6 comments
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior

Comments

@bzm3r
Copy link
Contributor

bzm3r commented Nov 15, 2022

Bevy version

0.9

What user did

Programmer is working with bevy_ui ImageBundle and spawned a ImageBundle as a child of a NodeBundle. The NodeBundle is a fixed size, 100px by 100px. The image that they want to show is a pixel art image that is 64px width by 32px tall. They set the ImageMode explicitly to KeepAspect, which they assume to mean is the Aspect Ratio of the image, in this case 2x1 (and this is confirmed by the docs for ImageMode).

What went wrong

The image stretches to fit the 100px by 100px parent, it does not keep the aspect ratio.

Additional information

From the following Bevy Discord question: https://discord.com/channels/691052431525675048/1042098354735300658

@bzm3r bzm3r added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 15, 2022
@nicopap nicopap added A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Nov 15, 2022
@frederickjjoubert
Copy link

Thank you @bzm3r for creating this issue, I am said user :)

@ickshonpe
Copy link
Contributor

ickshonpe commented Nov 17, 2022

Thought about this some more, and I don't think it's a bug, just confusing.

ImageMode::KeepAspect tells the UI to store the image size so it can draw the image with the correct aspect ratio.
The NodeBundle defaults are FlexDirection::Row and AlignItems::Stretch.
FlexDirection::Row means the x-axis is the main-axis and the y-axis is the cross-axis.
AlignItems::Stretch tells the UI to stretch items to fill the entire cross-axis of the Node.
The image height is 32 pixels and the Node's height (the cross-axis) is 100 pixels, so the image height is stretched to 100 pixels.
But with a height of 100 pixels, in order to preserve the aspect ratio the image would have to have a width of 200 pixels.
That won't fit inside the Node, so the image is drawn squashed into a 100x100 square.

To get the image to display correctly, change the flex-direction to FlexDirection::Column. Then the cross-axis will be the x-axis, the image width will be stretched to 100 pixels, and the height will be scaled according to the image's aspect ratio, 100 / 64 * 32 = 50, as desired.

@bzm3r
Copy link
Contributor Author

bzm3r commented Nov 17, 2022

@ickshonpe Any recommendations on what can be done in terms of documentation to make this less confusing?

My guess:

  • the interaction between KeepAspect and AlignItems should be clarified?

Or do we have to go farther than documentation, and rework some of the API? How is this sort of interaction handled in other UI toolkits?

@bzm3r bzm3r changed the title ImageMode::KeepAspect is not respected ImageMode::KeepAspect interacts in a confusing way with AlignItems Nov 17, 2022
@ickshonpe
Copy link
Contributor

ickshonpe commented Nov 18, 2022

I'm putting in a PR that deletes ImageMode. It's confusing and doesn't serve any purpose.

@ickshonpe
Copy link
Contributor

Or do we have to go farther than documentation, and rework some of the API? How is this sort of interaction handled in other UI toolkits?

I think making image aspect ratios independent of flex should work, and be ergonomic and foolproof. Might be a bit hacky though. Implementing it now.

bors bot pushed a commit that referenced this issue Nov 18, 2022
# Objective

Delete `ImageMode`. It doesn't do anything except mislead people into thinking it controls the aspect ratio of images somehow.

Fixes #3933 and #6637

## Solution

Delete `ImageMode`

## Changelog

Removes the `ImageMode` enum.
Removes the `image_mode` field from `ImageBundle`
Removes the `With<ImageMode>` query filter from `image_node_system`
Renames `image_node_system` to` update_image_calculated_size_system`
@bzm3r
Copy link
Contributor Author

bzm3r commented Nov 19, 2022

Closed by: #6674

@bzm3r bzm3r closed this as completed Nov 19, 2022
taiyoungjang pushed a commit to taiyoungjang/bevy that referenced this issue Dec 15, 2022
# Objective

Delete `ImageMode`. It doesn't do anything except mislead people into thinking it controls the aspect ratio of images somehow.

Fixes bevyengine#3933 and bevyengine#6637

## Solution

Delete `ImageMode`

## Changelog

Removes the `ImageMode` enum.
Removes the `image_mode` field from `ImageBundle`
Removes the `With<ImageMode>` query filter from `image_node_system`
Renames `image_node_system` to` update_image_calculated_size_system`
alradish pushed a commit to alradish/bevy that referenced this issue Jan 22, 2023
# Objective

Delete `ImageMode`. It doesn't do anything except mislead people into thinking it controls the aspect ratio of images somehow.

Fixes bevyengine#3933 and bevyengine#6637

## Solution

Delete `ImageMode`

## Changelog

Removes the `ImageMode` enum.
Removes the `image_mode` field from `ImageBundle`
Removes the `With<ImageMode>` query filter from `image_node_system`
Renames `image_node_system` to` update_image_calculated_size_system`
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

Delete `ImageMode`. It doesn't do anything except mislead people into thinking it controls the aspect ratio of images somehow.

Fixes bevyengine#3933 and bevyengine#6637

## Solution

Delete `ImageMode`

## Changelog

Removes the `ImageMode` enum.
Removes the `image_mode` field from `ImageBundle`
Removes the `With<ImageMode>` query filter from `image_node_system`
Renames `image_node_system` to` update_image_calculated_size_system`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

4 participants