You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Objective
This PR implements `FromStr` for `Val`, so developers can parse values
like `10px` and `50%`
## Testing
Added tests for this. I think they cover pretty much everything, and
it's a fairly simple unit test.
## Limitations
Currently the following float values are not parsed:
- `inf`, `-inf`, `+infinity`, `NaN`
- `2.5E10`, `2.5e10`, `2.5E-10`
For my use case this is perfectly fine but other developers might want
to support these values
Copy file name to clipboardExpand all lines: crates/bevy_ui/src/geometry.rs
+128Lines changed: 128 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,16 @@ use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
10
10
///
11
11
/// This enum allows specifying values for various [`Node`](crate::Node) properties in different units,
12
12
/// such as logical pixels, percentages, or automatically determined values.
13
+
///
14
+
/// `Val` also implements [`core::str::FromStr`] to allow parsing values from strings in the format `#.#px`. Whitespaces between the value and unit is allowed. The following units are supported:
15
+
/// * `px`: logical pixels
16
+
/// * `%`: percentage
17
+
/// * `vw`: percentage of the viewport width
18
+
/// * `vh`: percentage of the viewport height
19
+
/// * `vmin`: percentage of the viewport's smaller dimension
20
+
/// * `vmax`: percentage of the viewport's larger dimension
21
+
///
22
+
/// Additionally, `auto` will be parsed as [`Val::Auto`].
0 commit comments