dampen_core/ir/
mod.rs

1pub mod layout;
2pub mod node;
3pub mod span;
4pub mod style;
5pub mod theme;
6
7use std::collections::HashMap;
8
9pub use layout::{
10    Alignment, Breakpoint, Direction, Justification, LayoutConstraints, Length, Padding,
11};
12pub use node::InterpolatedPart;
13pub use node::{AttributeValue, EventBinding, EventKind, WidgetKind, WidgetNode};
14pub use span::Span;
15pub use style::{
16    Background, Border, BorderRadius, BorderStyle, Color, Gradient, ImageFit, Shadow,
17    StyleProperties, Transform,
18};
19pub use theme::{
20    FontWeight, IcedPaletteColors, SpacingScale, StateSelector, StyleClass, Theme, ThemeDocument,
21    ThemeError, ThemeErrorKind, ThemePalette, Typography, WidgetState,
22};
23
24/// A complete parsed Dampen UI document.
25///
26/// This is the root structure returned by the parser. It contains
27/// the document's schema version and the root widget tree.
28///
29/// # Example
30///
31/// ```rust
32/// use dampen_core::{parse, DampenDocument};
33///
34/// let xml = r#"<dampen><column><text value="Hello" /></column></dampen>"#;
35/// let doc: DampenDocument = parse(xml).unwrap();
36/// assert_eq!(doc.version.major, 1);
37/// ```
38#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
39pub struct DampenDocument {
40    /// Schema version for compatibility checking
41    pub version: SchemaVersion,
42
43    /// Root widget of the UI tree
44    pub root: WidgetNode,
45
46    /// Theme definitions
47    pub themes: HashMap<String, crate::ir::theme::Theme>,
48
49    /// Style class definitions
50    pub style_classes: HashMap<String, crate::ir::theme::StyleClass>,
51
52    /// Global theme name
53    pub global_theme: Option<String>,
54}
55
56impl Default for DampenDocument {
57    /// Creates a default document with version 1.0 and an empty root column.
58    fn default() -> Self {
59        Self {
60            version: SchemaVersion { major: 1, minor: 0 },
61            root: WidgetNode::default(),
62            themes: HashMap::new(),
63            style_classes: HashMap::new(),
64            global_theme: None,
65        }
66    }
67}
68
69/// Schema version for compatibility checking.
70///
71/// Versions follow semantic versioning:
72/// - Major: Breaking changes
73/// - Minor: Backward-compatible additions
74///
75/// Files without an explicit version default to 1.0.
76#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
77pub struct SchemaVersion {
78    /// Major version number
79    pub major: u16,
80    /// Minor version number
81    pub minor: u16,
82}
83
84impl Default for SchemaVersion {
85    /// Default version is 1.0
86    fn default() -> Self {
87        Self { major: 1, minor: 0 }
88    }
89}