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

Val viewport unit variants #8137

Merged
merged 6 commits into from
Mar 21, 2023
Merged

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Mar 20, 2023

Objective

Add viewport variants to Val that specify a percentage length based on the size of the window.

Solution

Add the variants Vw, Vh, VMin and VMax to Val.
Add a physical window size parameter to the from_style function and use it to convert the viewport variants to Taffy Points values.

One issue: It isn't responsive to window resizes. So flex_node_system has to do a full update every time the window size changes. Perhaps this can be fixed with support from Taffy.


Changelog

  • Added Val viewport unit variants Vw, Vh, VMin and VMax.
  • Modified convert module to support the new Val variants.
  • Changed flex_node_system to support the new Val variants.
  • Perform full layout update on screen resizing, to propagate the new viewport size to all nodes.

* Added `Val` viewport unit variants `Vw`, `Vh`, `VMin` and `VMax`.
* Modified `convert` module to support the new `Val` variants.
* Changed `flex_node_system` to support the new `Val` variants.
* Perform full layout update on screen resizing, to propagate the new viewport size to all nodes.
@ickshonpe ickshonpe changed the title AddVal Viewport unit variants Val viewport unit variants Mar 20, 2023
@mockersf
Copy link
Member

Fixes DioxusLabs/taffy#239 for me 😄

@ickshonpe
Copy link
Contributor Author

ickshonpe commented Mar 20, 2023

Having to do a full re-layout on window size changes is annoying, but I don't think even a large FPS drop when resizing really matters that much.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-UI Graphical user interfaces, styles, layouts, and widgets labels Mar 20, 2023
@alice-i-cecile
Copy link
Member

Well done and useful. Agreed on the relayout on window size change. I don't see any clean way around that for now, so we can wait and try something more involved if it's a problem.

@ickshonpe
Copy link
Contributor Author

ickshonpe commented Mar 20, 2023

A hack I've come up with is to have a system that runs on window resize events which iterates through all Style components and marks any with viewport values as changed. I don't think the extra complexity is worth it though for the very minimal and situational performance gains.

crates/bevy_ui/src/flex/mod.rs Show resolved Hide resolved
crates/bevy_ui/src/flex/convert.rs Outdated Show resolved Hide resolved
crates/bevy_ui/src/flex/convert.rs Outdated Show resolved Hide resolved
crates/bevy_ui/src/flex/convert.rs Outdated Show resolved Hide resolved
* Added `LayoutContext` type.
* Replaced `scale_factor` and `physical_size` parameters in `flex` and `convert` module's functions with
a single `LayoutContext` parameter.
* Refactored `convert` modules functions to avoid use of `unreachable!`
* Cleaned up simplified `Val` to taffy conversion functions.
* Added a basic test for `into_length_percentage`.
@cart cart added this pull request to the merge queue Mar 21, 2023
@cart cart merged commit 2d5ef75 into bevyengine:main Mar 21, 2023
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-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants