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

Better image aspect ratio handling #79

Open
nicopap opened this issue Aug 27, 2023 · 0 comments
Open

Better image aspect ratio handling #79

nicopap opened this issue Aug 27, 2023 · 0 comments
Labels
C-layout relates to the cuicui_layout crate specifically C-sprite relates to the cuicui_layout_bevy_sprite crate specifically T-enhancement New feature or request

Comments

@nicopap
Copy link
Owner

nicopap commented Aug 27, 2023

One interesting property of bevy-lunex is that it avoids at all costs breaking image aspect ratio.

I'm not sure how it does it, but it's something cuicui_layout is bad at keeping.

Currently, only images spawned as leaf nodes preserve aspect ratio, when one of the two axis is marked as LeafRule::Content, it will delegate to the content_sized module the computation of this axis, when constraint on the other is declared.

Current cuicui_layout limitations:

  • Images used as "root" will stretch to fit, we'd like to "crop" the image (similarly to the bevy ScalingMode)
  • Images used as background for container nodes will always stretch to fit the container, and there is no way to constraint the container to a good aspect ratio for its background image.
  • A way to work around this is to use ninepatch. In fact, the bevy-lunex cyberpunk example would benefit from ninepatch as details get discarded when the screen aspect ratio changes.

I'm really not in favor of adding a new Rule type for this. I want to make the logic for layouting as minimalist as possible, to make it possible to reason about it.

I think it's something that could be solved in a downstream crate (cuicui_layout_bevy_ui or/and cuicui_layout_bevy_sprite)

^^ I changed opinion on this. After writing a tutorial on cuicui_layout, I'm convinced that an explicit way to keep aspect ratio is ideal. It enables an homogeneous interpretation (and source!) as to how a specific node's size is computed. I think a new set of rules is the best approach here.

@nicopap nicopap added T-enhancement New feature or request C-ui relates to the cuicui_layout_bevy_ui crate specifically C-sprite relates to the cuicui_layout_bevy_sprite crate specifically labels Aug 27, 2023
@nicopap nicopap added C-layout relates to the cuicui_layout crate specifically and removed C-ui relates to the cuicui_layout_bevy_ui crate specifically labels Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-layout relates to the cuicui_layout crate specifically C-sprite relates to the cuicui_layout_bevy_sprite crate specifically T-enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant