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

bevy_ui: Implement CSS-like calculations for Style API #15307

Closed
vveisard opened this issue Sep 19, 2024 · 3 comments
Closed

bevy_ui: Implement CSS-like calculations for Style API #15307

vveisard opened this issue Sep 19, 2024 · 3 comments
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible

Comments

@vveisard
Copy link

vveisard commented Sep 19, 2024

What problem does this solve or what need does it fill?

When styling UI elements we often need to calculate styles properties using multiple values with mixed units (eg, a mixture of percents and pixels).

What solution would you like?

I propose implementing Val::Calc for bevy_ui::geometry::Val which represents a calculation to be evaluated. This should resemble the calc API in the web: https://developer.mozilla.org/en-US/docs/Web/CSS/calc

I would like to use plain arithmetic operators to create such calculations.

Usage of this API would look like:

NodeBundle {
  style: Style {
    position_type: PositionType::Absolute,
    height: Val::Percent(100.0) - Val::Px(10.0),
    ..default()
  },
  ..default()
},

What alternative(s) have you considered?

Workarounds without calculations resemble workarounds present in the web before calc: ie, dummy elements, manual calculation by measuring using JavaScript (which means you have to do your layout twice), etc. All poor solutions.

@vveisard vveisard added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Sep 19, 2024
@vveisard vveisard changed the title bevy_ui: Implement CSS "calc" for Style API bevy_ui: Implement CSS-like calculations for Style API Sep 19, 2024
@alice-i-cecile alice-i-cecile added A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Sep 19, 2024
@alice-i-cecile
Copy link
Member

Changes to layout like this first need to be implemented upstream in taffy, then exposed to users in Bevy :)

@nicoburns
Copy link
Contributor

Taffy issue for this feature is DioxusLabs/taffy#225

@vveisard
Copy link
Author

I see.

This issue is a duplicate of #5893, closing.

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

No branches or pull requests

3 participants