Skip to main content

dampen_core/ir/
mod.rs

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