ui

Macro ui 

Source
ui!() { /* proc-macro */ }
Expand description

Provides CSS-like syntax to either edit or create bevy_ui components.

§Available fields

To see a full list of built-in fields, see readme of mevy_ui, here are some examples:

cmd.spawn(ui!((
    size: 50px 50px;
    background: #ff0000;
    box_shadow: 0px 0px 5px 5px #ff0000;
    border: 5px #00ff00;
)));

The same, but ‘slim’:

cmd.spawn(ui!( w:50 h:50 bg:#f00 shadow:0+0+5+5#f00 border:5#0f0 ));

§Possible Modes

Depending on the delimiters & if there is a name defined, the function of this macro differs:

  • ‘Slim’ Inline Tuple Mode | ui!{ w:8 h:8 l:2 t:2 }
    • returns a tuple of mentioned UI components
  • Inline Tuple Mode | ui!{( width: 1px; )}:
    • returns a tuple of mentioned UI components
  • Function Tuple Mode | ui!{func_name( width: 1px; )}:
    • defines a function that returns a tuple of mentioned UI components
    • these can then be used as fields like this: ui!{( func_name; )}
  • Function Edit Mode | ui!{func_name{ width: 2px; }}
    • defines a function, that edits mentioned UI components
    • the parameters of this function = the needed mutable components
    • using _ will keep the original values: e.g. border: _ #ff0000;

§Custom Fields

Every function that returns any Bundle (even if it is just -> impl Bundle) can be used as custom field.