Flip UI image
Objective
Fixes #3225, Allow for flippable UI Images
Solution
Add flip_x and flip_y fields to UiImage, and swap the UV coordinates accordingly in ui_prepare_nodes.
Changelog
- Changes UiImage to a struct with texture, flip_x, and flip_y fields.
- Adds flip_x and flip_y fields to ExtractedUiNode.
- Changes extract_uinodes to extract the flip_x and flip_y values from UiImage.
- Changes prepare_uinodes to swap the UV coordinates as required.
- Changes UiImage derefs to texture field accesses.
I'd probably prefer a singular
Flipcomponent, which is reused across sprites and UI images, but I won't block on that.
Yes, I'm trying to keep things as close to sprites as possible (with the least breaking changes).
I chose FlipImage rather than Flip because a lot of people already find the UI confusing, so I wanted to be extra clear about what it's flipping. Most of the ambiguity is in the Style component though so maybe Flip is fine. Or it could be FlipTexture.
I don't think it should be a separate component. What happens if I add the FlipImage component to a PbrBundle? Is the image file used for texture flipped?
I would prefer to have two fields flip_x and flip_y in an existing UI component, maybe UiImage
I don't think it should be a separate component. What happens if I add the
FlipImagecomponent to aPbrBundle? Is the image file used for texture flipped?I would prefer to have two fields
flip_xandflip_yin an existing UI component, maybeUiImage
I agree that would be better, it's just that I was worried it'd break a lot of existing code that expects UiImage to be a newtype.
ImageMode is only used as a marker component for the image widget at the moment, the flip_x/y fields could be added to it as an alternative? Or would it be better to just have the changes to ExtractedUiNode and ui_prepare_nodes in this PR, and have another PR for the interface?
I agree that would be better, it's just that I was worried it'd break a lot of existing code that expects UiImage to be a newtype.
Yep, no worries about breaking existing code here :) This sort of migration is very easy. Not immediately sure about your other question though.
bors r+
Pull request successfully merged into main.
Build succeeded:
- build-and-install-on-iOS
- build-android
- build (macos-latest)
- build (ubuntu-latest)
- build-wasm
- build (windows-latest)
- build-without-default-features (bevy)
- build-without-default-features (bevy_ecs)
- build-without-default-features (bevy_reflect)
- check-compiles
- check-doc
- check-missing-examples-in-docs
- ci
- markdownlint
- run-examples
- run-examples-on-wasm
- run-examples-on-windows-dx12