Bevy-UI String Parser Utilities
This rust crate provides a set of parsing functions that can be used to
convert strings into various bevy-ui types like Color, Val or UiRect.
The syntax matches CSS, but it doesn't try to replicate it perfectly.
It depends on the nom library for parsing.
Parsers
Color
Parses Color values, such as #f0f or yellow.
use Color;
use color_string_parser;
let color: = color_string_parser;
assert_eq!;
Supported syntax
red,blue-> css color names (see https://drafts.csswg.org/css-color/#named-colors)#f0f,#ff00ff-> hex color (3 or 6 digits)#ff00ff00-> hex color with alpha (8 digits)rgb(1.0, 0.0, 0.0)-> rgb color (0.0-1.0)rgba(1.0, 0.0, 0.0, 1.0)-> rgb color with alpha (0.0-1.0)hsl(0.0, 1.0, 0.5)-> hsl color (0.0-1.0)hsla(0.0, 1.0, 0.5, 1.0)-> hsl color with alpha (0.0-1.0)
Val
Parses Val values, such as 1px or 50%.
use Val;
use val_string_parser;
let value: = val_string_parser;
assert_eq!;
Supported syntax
auto->Val::Auto12px->Val::Px(12.0)12%->Val::Percent(12.0)12vw->Val::Vw(12.0)12vh->Val::Vh(12.0)12vmin->Val::VMin(12.0)12vmax->Val::VMax(12.0)
Rect
Parses UiRect values, such as 25px 50px.
This uses the same ordering as CSS properties like padding or margin,
see mdn for more information.
use ;
use rect_string_parser;
let rect: = rect_string_parser;
assert_eq!;
Supported syntax
10px 20px 30px 40px->top | right | bottom | left10px 20px 10px->top | left and right | bottom10px 20px->top and bottom | left and right10px->top, right, bottom and left
Angle
Parses angles into float values, such as 180deg, returns radians.
use angle_string_parser;
let angle: = angle_string_parser;
assert_eq!;
Supported syntax
180deg->3.141592653591.3rad->1.31.3->1.3
Serde
Each parser also provides a serde deserializer *_serde_parser, for example:
use Deserialize;
use PI;
let foo: Foo = from_str.unwrap;
assert_eq!;
It requires the optional serde feature.
Changelog
v0.1.2made serde feature optionalv0.1.1readme addedv0.1.0initial release