Skip to main content

arcs/components/
mod.rs

1//! Common components used by the `arcs` CAD library.
2
3mod bounding_box;
4mod dimension;
5mod drawing_object;
6mod layer;
7mod name;
8mod selected;
9mod spatial_entity;
10mod styles;
11mod viewport;
12mod vtable;
13
14pub use bounding_box::BoundingBox;
15pub use dimension::Dimension;
16pub use drawing_object::{DrawingObject, Geometry};
17pub use layer::Layer;
18pub use name::{Name, NameTable};
19pub use selected::Selected;
20pub use spatial_entity::{Space, SpatialEntity};
21pub use styles::{LineStyle, PointStyle, WindowStyle};
22pub use viewport::Viewport;
23pub(crate) use vtable::ComponentVtable;
24
25use specs::World;
26
27/// Get an iterator over the [`ComponentVtable`] for all known
28/// [`specs::Component`] types.
29pub(crate) fn known_components(
30) -> impl Iterator<Item = &'static ComponentVtable> + 'static {
31    lazy_static::lazy_static! {
32        static ref VTABLES: Vec<ComponentVtable> = vec![
33            ComponentVtable::for_type::<BoundingBox>(),
34            ComponentVtable::for_type::<DrawingObject>(),
35            ComponentVtable::for_type::<Layer>(),
36            ComponentVtable::for_type::<Name>(),
37            ComponentVtable::for_type::<LineStyle>(),
38            ComponentVtable::for_type::<PointStyle>(),
39            ComponentVtable::for_type::<Selected>(),
40            ComponentVtable::for_type::<WindowStyle>(),
41            ComponentVtable::for_type::<Viewport>(),
42        ];
43    }
44
45    VTABLES.iter()
46}
47
48/// Register all [`specs::Component`]s.
49pub fn register(world: &mut World) {
50    log::debug!("Registering all components");
51
52    for component in known_components() {
53        log::debug!("Registering {}", component.name());
54        component.register(world);
55    }
56
57    world.insert(Space::default());
58}