[!NOTE] This crate is part of mevy (tl;dr: more neat macros) so take a look! 🦆
Setup
Multiple bevy versions are supported and managed by features:
# bevy 0.16.0-rc.3
= {="0.2",=["0.16-rc.3"]}
# bevy 0.15
= {="0.2",=["0.15"]}
⭐ The Star of the Crate: CSS-like Notation
The macro ui!() has multiple modes, that are invoked by (1.) the type of delimiters and (2.) if a name is provided:
Tuple Inline Mode
ui!((..)) (inner round braces) will return a tuple of mentioned components only. See this example.
c.spawn;
//^ optional ? (or any token): hovering shows the returned tuple (if LSP used)
/// function as custom fields or p refabs
The order of the components are based on 'first mention' and consistent:
let = ui!;
Tuple Function Mode
If a name is defined before the inner braces, a function will be defined returning an impl Bundle of its content:
ui!
// is the same as:
Edit Function Mode
Defining a name and then using curly brackets {} instead, will define a function that mutates existing components:
- The parameters of this function are
&mut ..of the components to be mutated - Custom fields will be
inserted, anEntityCommandswill be then added to the parameters - Using
_instead of a calue will keep ste already existing one:- e.g.
box_shadow: _ _ 10pxwill only affect the blur radius, since x and y are 'kept' and spread & color not mentioned
- e.g.
ui!
// does the same as:
Neat Notation
Inside the macro there you can write those things:
0px=Val::Px(0.)0%=Val::Percent(0.)0vh=Val::Vh(0.)0vw=Val::Vw(0.)0vmin=Val::VMin(0.)0vmax=Val::VMax(0.)#ff0000=Color::Srgba(Srgba::hex("#ff0000").unwrap())- checked by the compiler (and LSP), throwing a custom error if not valid!
red|RED=bevy::color::palettes::css::RED
Custom Fields
Currently, There are 2 ways to add those:
- a
fnthat returns something thatimpl Bundle - the
newmethod of a struct thatimpl Bundle
c.spawn;
Edge Selection (CSS-like)
border: 5px; // 5px to all edges
border: 5px 2px; // 5px vertical, 2px horizontal
border: 5px 2px 8px; // 5px top, 2px horizontal, 8px bottom
border: 5px 2px 4px 1px // (clockwise) top right bottom left
Corner Selection (CSS-like)
border-radius: 5px; // 5px to all corners
border-radius: 5px 0px; // 5px top-left/right, 0px bottom-left/right
border-radius: 5px 2px 8px; // 5px top-left, 2px top-right, 8px bottom
border-radius: 5px 2px 4px 1px // (clockwise) top-left top-right bottom-right bottom-left
Limitations
At the moment, you can only use variables in custom fields. It's planned to work for built-in fields soon™.
Built-In Fields
Here's a list of all available out of the box fields, Val order same as in bevy
- numbers can be written as int or float
- enum variants can also be written in snake case
ui!