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

Split Val into two enums, one with an Auto variant and one without #8096

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Mar 15, 2023

Objective

Problem with Val:

  • Val's Auto variant doesn't make sense for certain Style fields, such as the gap properties. In those cases internally Auto just gets mapped to Taffy's LengthPercentage::Points(0.). It's never ideal to have multiple representations for the same concept like this.

Problems with UiRect:

  • UiRect is confusingly named (nothing it represents is a rectangle).
  • For padding and borders non-numeric UiRect fields are meaningless (at the moment at least, may change).
  • The documentation for UiRect has to explain its different behaviour for each of the four use cases.
  • New features might mean the requirements for each of these style properties diverge even further.

Relevant discussions at #7656 and #7969

Combination of the changes from #7710 and #7569

Solution

Rename Val to Num.
Add a new Val enum without an Auto variant.
Split UiRect into distinct Margin, Padding and Border types.
Implement the UiRect constructor functions using macros.


Changelog

  • Added a new enum Num that represents numeric values only and does not have an Auto variant.
  • Removed UiRect.
  • Added the Margin, Padding, and Border types and implemented their common functionality with macros.
  • Added new error types: NumArithmeticError and NumConversionError.
  • Changed geometry helper functions to accept impl Into<Val> values.
  • Changed Style to use the UiRect replacements.
  • Updated from_style.

Migration Guide

  • UiRect has been split into distinct Margin, Padding and Border types, with the same functionality. Padding and Border have Num fields. Margin has Val fields.
  • The Num enum replaces Val in contexts where only numeric values are needed.

        Added a type `Breadth`, that is similar to `Val` but with only evaluatable variants.
        Gave UiRect a type parameter, so it can take `Breadth` or `Val` values.
        Added tests for `Breadth` and `UiRect`.
        Changed style properties to use `Breadth` instead of `Val` for the padding and border properties.
        Changed `bevy_ui::flex::convert::from_rect` to take an `UiRect<T: Into<Val>>` instead of a `UiRect`.
        Made minimal necessary changes to the examples.
…padding and border values in `bevy_ui::flex::convert::from_style`
* Renamed `Val` to `AutoVal`
* Renamed `Breadth` to `Val`
* Renamed `ValArithmeticError` to `AutoValArithmeticError`
* Renamed `BreadthArithmeticError` to `ValArithmeticError`
* Renamed `BreadthConversionError` to `ValConversionError`
* removed `UiRect` and added `Border`, `Padding` and `Margin` types.
* fixed examples
* fixed convert and added the style conversion helper functions from the grid PR.
* renamed tests to use the correct names for the new types.
@ickshonpe ickshonpe changed the title Split Val into Val and AutoVal types and split UiRect into Margin, Padding and Border types Split Val into Val and AutoVal, and split UiRect into Margin, Padding and Border Mar 15, 2023
@nicoburns nicoburns added the A-UI Graphical user interfaces, styles, layouts, and widgets label Mar 15, 2023
@ickshonpe ickshonpe changed the title Split Val into Val and AutoVal, and split UiRect into Margin, Padding and Border Split up Val and UiRect Mar 18, 2023
@ickshonpe ickshonpe changed the title Split up Val and UiRect AutoVal Apr 26, 2023
@ickshonpe ickshonpe changed the title AutoVal Split Val into two enums, one with an Auto variant and one without Aug 10, 2023
@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use C-Code-Quality A section of code that is hard to understand or change labels Sep 4, 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-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants