Add an enum with only the numeric variants of Val#7569
Add an enum with only the numeric variants of Val#7569ickshonpe wants to merge 7 commits intobevyengine:mainfrom
Val#7569Conversation
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`
alice-i-cecile
left a comment
There was a problem hiding this comment.
I definitely like this direction. Unusable values should be unrepresentable. Great implementations with nice error types!
Labelling this with controversial, since this is a major use-facing UX change.
|
This seems like a reasonable change to introduce (although IMO it does add friction when authoring styles as you have to remember which properties correspond to which types). I'm not keen on the name though. Perhaps |
I think if we went that way, using And then we could implement |
I like this better than |
Problem
The
Stylepropertiespaddingandbordercan be assigned values ofVal::AutoorVal::Undefinedwhen only the numeric variants make sense. There isn't a sensible way for the UI to determine these values automatically, except to just set them to zero.Solution
Breadthwith only the evaluatable variants ofVal.UiRectgeneric.Style'spaddingandborderfields toUiRect<Breadth>.I'm not sure I like the name
Breadth, but it's shorter thanThicknessand seems more descriptive thanLength.Another option would be to rename
ValtoAutoValand renameBreadthtoVal.AutoValwould be used a lot more though, so this might be annoying.Perhaps
NumValorEValforEvaluatableValue.Numwould be nice but ambiguous with a lot of other things.There might be objections to making
UiRectgeneric. Could be divided intoNumRectandAutoRector something instead. Don't care either way, or about any of the namings.Changelog
Breadth, that is similar toValbut withoutVal's non-numeric variants.UiRectinto a generic struct.paddingandborderfields ofStyletoUiRect<Breadth>.Migration Guide
UiRectis now a generic struct with a type parameter, which isValby default.A new enum
Breadthhas been added which is similar toValbut withoutVal's non-numeric variantsVal::AutoandVal::Undefined.The
paddingandborderfields ofStylehave been changed to typeUiRect<Breadth>. Anypaddingandbordervalues ofVal::AutoorVal::Undefinedshould be replaced withBreadth::Px(0.), which is the default value forBreadth.