Module aframe::component [−][src]
Expand description
High-level API
component_def!
component_struct!
component!
simple_enum!
complex_enum!
Low-level API
A component_struct is simply a type that implements these 2 traits:
pub trait Component: Display + std::fmt::Debug + std::any::Any
{
fn clone(&self) -> Box<dyn Component>;
fn eq(&self, other: &'static dyn Component) -> bool;
fn as_map(&self) -> HashMap<Cow<'static, str>, Cow<'static, str>>;
}
pub trait ConstDefault
{
const DEFAULT: Self;
}As long as clone provides a valid clone, eq provides a valid equality
check, and as_map provides a serialization of keys to values that Aframe
can understand, and a DEFAULT value is provided that can be evaluated at
compile time, a struct is a valid component.
A ComponentReg is slightly more complicated, but details on its low-level
API may be added here at a later date.
Macros
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.
A macro to instantiate a component. Mimics struct creation syntax, but allows
any number of fields to be left out (in which case defaults will be used).
Note that the ability to leave out fields does not extend to struct_like
enum variants created in this macro. For example: component!{component::Camera}
will create a camera component with all its fields set to default values,
whereas component!{component::Camera, active = false} will create a
camera component with all its fields set to default values except the
active field.
Top-level macro to define components. Usage resembles struct creation syntax.
The js! macro is available for writing inline javascript, and returns a
js_sys::Function object. This macro calls into on expressions passed into the
fields expecting function, allowing the js! macro to be used as a catch-all.
Takes the optional fields described in the table below.
While component_def! creates a component that Aframe can access from its
own runtime, the component_struct! macro creates a Rust struct that mimics
the internal details of that Aframe component. Component structs are already
provided for Aframe’s built-in components (WIP: not all components are defined
yet. Once all aframe components are defined, calling component_struct!
should only be necessary for locally-defined components. Once all components
from Aframe have been defined, component_def! and component_struct! may
be merged into a single macro to do the heavy-lifting of both at once). The
component must be already registered in aframe before this struct may be used
(although constructing it before that is safe). There are 2 variation of
syntax provided, depending on the desired resulting Display implementation.
Defines an enum in which each variant maps to a single string (via a
Display implementation). This can be combined with component_def!
to crate fields with a limited number of possiblities.
Structs
Component registration definition.
A vector containing a tuple of components along with their property name
The type here may look daunting, but all this is just to allow you to create
a Cow<'static, [T]> field in a component.
Additional properties for the Material component. Contains a slice or vector of property names to property values.
A property for a ComponentReg