lumen_engine/node/
schema.rs1use super::{
2 ids::NodeId,
3 ports::{InputPortDef, PortRef},
4 property::PropertyValue,
5};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[repr(u8)]
9pub enum PropertyKind {
10 Float = 0,
11 Int = 1,
12 Bool = 2,
13 String = 3,
14 Color = 4,
15 Vec2 = 5,
16 Enum = 6,
17 Paint = 7,
18}
19
20#[cfg(any(feature = "json", feature = "metadata"))]
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub struct EnumOptionDef {
23 pub name: &'static str,
24 pub label: &'static str,
25 pub value: i64,
26}
27
28#[cfg(any(feature = "json", feature = "metadata"))]
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub struct EnumDef {
31 pub name: &'static str,
32 pub options: &'static [EnumOptionDef],
33}
34
35#[cfg(any(feature = "json", feature = "metadata"))]
36pub trait NodeEnum {
37 fn enum_def() -> &'static EnumDef;
38}
39
40#[derive(Debug, Clone, Copy, PartialEq)]
41pub struct PropertyDef {
42 pub id: &'static str,
43 pub expected: PropertyKind,
44 #[cfg(any(feature = "json", feature = "metadata"))]
45 pub enum_def: Option<&'static EnumDef>,
46 #[cfg(feature = "metadata")]
47 pub name: &'static str,
48 #[cfg(feature = "metadata")]
49 pub description: &'static str,
50 #[cfg(feature = "metadata")]
51 pub constraints: PropertyConstraints,
52}
53
54#[cfg(feature = "metadata")]
55#[derive(Debug, Clone, Copy, Default, PartialEq)]
56pub struct PropertyConstraints {
57 pub min: Option<f64>,
58 pub max: Option<f64>,
59 pub step: Option<f64>,
60 pub format: Option<&'static str>,
61 pub multiline: bool,
62 pub recommended_rows: Option<u32>,
63 pub role: Option<&'static str>,
64}
65
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
67#[repr(u8)]
68pub enum NodeCategory {
69 Compositing = 0,
70 Processing = 1,
71 Source = 2,
72 Output = 3,
73 Vector = 4,
74}
75
76#[derive(Debug, Clone)]
77pub struct NodeSchemaDef {
78 pub kind: &'static str,
79 pub name: &'static str,
80 pub description: &'static str,
81 pub category: NodeCategory,
82 pub inputs: &'static [InputPortDef],
83 pub properties: Vec<PropertyDef>,
84 pub default_properties: Vec<(&'static str, PropertyValue)>,
85}
86
87#[cfg(feature = "metadata")]
88pub trait NodeSchema: Default {
89 fn schema() -> NodeSchemaDef;
90}
91
92#[cfg(feature = "json")]
93pub trait JsonNode: Default {
94 fn from_json(
95 id: NodeId,
96 params: Option<&serde_json::Map<String, serde_json::Value>>,
97 ) -> anyhow::Result<Self>
98 where
99 Self: Sized;
100
101 fn set_input_json(&mut self, port: &str, source: PortRef) -> anyhow::Result<()>;
102}