Skip to main content

sim_lib_scene/
kinds.rs

1//! Scene node kinds.
2//!
3//! Scene node kinds are open metadata, never a closed kernel enum: a scene node
4//! is an `Expr::Map` carrying a `kind` entry whose value is a symbol in the
5//! `scene` namespace (for example `scene/graph`). This module lists the minimum
6//! baseline scene vocabulary and provides recognition helpers. New kinds can be
7//! added by libs without touching the kernel; the recognized set here is the
8//! baseline the universal lenses rely on.
9
10use sim_kernel::Symbol;
11
12/// The namespace every scene node `kind` symbol lives in.
13pub const SCENE_NAMESPACE: &str = "scene";
14
15/// The map key that tags a scene node with its kind.
16pub const KIND_KEY: &str = "kind";
17
18/// The baseline scene node kind names (the local part of the `scene/*` symbol).
19///
20/// The recognized baseline, not a closed universe: [`is_known_kind`] returns
21/// `false` for an unrecognized kind so a malformed scene fails closed, while
22/// libs may extend the runtime set through registration.
23pub const SCENE_KINDS: &[&str] = &[
24    "box",
25    "stack",
26    "grid",
27    "text",
28    "field",
29    "button",
30    "badge",
31    "icon",
32    "tree",
33    "table",
34    "graph",
35    "node",
36    "edge",
37    "plot",
38    "matrix",
39    "knob",
40    "slider",
41    "meter",
42    "waveform",
43    "spectrum",
44    "timeline",
45    "keyboard",
46    "piano-roll",
47    "player-rack",
48    "object-roll",
49    "canvas",
50    "overlay",
51    "embed",
52    "patch",
53];
54
55/// The qualified symbol for a scene node kind name, e.g. `scene/graph`.
56pub fn scene_kind(name: &str) -> Symbol {
57    Symbol::qualified(SCENE_NAMESPACE, name)
58}
59
60/// Is `name` a recognized baseline scene node kind (local part only)?
61pub fn is_known_kind_name(name: &str) -> bool {
62    SCENE_KINDS.contains(&name)
63}
64
65/// Is `symbol` a recognized baseline scene node kind (`scene/<known>`)?
66pub fn is_known_kind(symbol: &Symbol) -> bool {
67    symbol.namespace.as_deref() == Some(SCENE_NAMESPACE) && is_known_kind_name(&symbol.name)
68}