Macro aframe::complex_enum

source ·
macro_rules! complex_enum {
    ($(#[$outer:meta])* $name:ident $(, $variant:ident $fmt:expr => { $($field:ident: $ty:ty),* })*) => { ... };
}
Expand description

A macro to define an enum in which each variant maps to an arbitrary number of fields which will themselves be flattened into fields of the component itself. Works similarly to the component_struct! macro.

// For example:
use aframe::complex_enum;
 
complex_enum!
(AnimationLoop, 
    Amount "{}" => { looping: u32 },
    Forever "true" => {}
);
component_struct!
(Animation,
    // ...
    looping: "loop" AnimationLoop = AnimationLoop::Amount{looping: 0},
    // ...
);
 
// Another example is as follows:
 
complex_enum!
(
    /// Doc comment for GeometryPrimitive enum
    GeometryPrimitive, 
    Box
    "primitive: box; width: {}; height: {}; depth: {}; segmentsWidth: {}; \
    segmentsHeight: {}; segmentsDepth: {}" => 
    {  
        width: f32,
        height: f32,
        depth: f32,
        segments_width: u32,
        segments_height: u32,
        segments_depth: u32
    },
    Circle
    "primitive: circle; radius: {}; segments: {}; \
    thetaStart: {}; thetaLength: {}" =>
    {
        radius: f32,
        segments: u32,
        theta_start: f32,
        theta_length: f32
    },
    // ...
);
component_struct!
(
    /// This doc comment will be captured
    Geometry,
    primitive: "" GeometryPrimitive = GeometryPrimitive::Box
    {
        width: 1.0,
        height: 1.0,
        depth: 1.0,
        segments_width: 1,
        segments_height: 1,
        segments_depth: 1,
    },
    // ...
);