windjammer_ui/components/generated/
vnode.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use crate::vnode_ffi;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub struct VNode {
7    pub handle: u64,
8}
9
10impl VNode {
11    /// Create a new div element
12    #[inline]
13    pub fn div() -> VNode {
14        VNode {
15            handle: vnode_ffi::vnode_element("div"),
16        }
17    }
18    /// Create a new span element
19    #[inline]
20    pub fn span() -> VNode {
21        VNode {
22            handle: vnode_ffi::vnode_element("span"),
23        }
24    }
25    /// Create a new button element
26    #[inline]
27    pub fn button() -> VNode {
28        VNode {
29            handle: vnode_ffi::vnode_element("button"),
30        }
31    }
32    /// Create a new input element
33    #[inline]
34    pub fn input() -> VNode {
35        VNode {
36            handle: vnode_ffi::vnode_element("input"),
37        }
38    }
39    /// Create a new text node
40    #[inline]
41    pub fn text(content: String) -> VNode {
42        VNode {
43            handle: vnode_ffi::vnode_text(content.as_str()),
44        }
45    }
46    /// Create any HTML element by tag name
47    #[inline]
48    pub fn element(tag: String) -> VNode {
49        VNode {
50            handle: vnode_ffi::vnode_element(tag.as_str()),
51        }
52    }
53    /// Add a CSS class (takes owned String)
54    #[inline]
55    pub fn add_class(self, class: String) -> VNode {
56        vnode_ffi::vnode_class(self.handle, class.as_str());
57        self
58    }
59    /// Add inline style (takes owned String)
60    #[inline]
61    pub fn add_style(self, style: String) -> VNode {
62        vnode_ffi::vnode_style(self.handle, style.as_str());
63        self
64    }
65    /// Add an attribute (takes owned Strings)
66    #[inline]
67    pub fn add_attr(self, name: String, value: String) -> VNode {
68        vnode_ffi::vnode_attr(self.handle, name.as_str(), value.as_str());
69        self
70    }
71    /// Add a child VNode
72    #[inline]
73    pub fn child(self, child: VNode) -> VNode {
74        vnode_ffi::vnode_child(self.handle, child.handle);
75        self
76    }
77    /// Add text content (takes owned String)
78    #[inline]
79    pub fn add_text(self, text: String) -> VNode {
80        let text_node = VNode::text(text);
81        vnode_ffi::vnode_child(self.handle, text_node.handle);
82        self
83    }
84    /// Set id attribute
85    #[inline]
86    pub fn set_id(self, id: String) -> VNode {
87        vnode_ffi::vnode_attr(self.handle, "id", id.as_str());
88        self
89    }
90    /// Set placeholder (for inputs)
91    #[inline]
92    pub fn set_placeholder(self, text: String) -> VNode {
93        vnode_ffi::vnode_attr(self.handle, "placeholder", text.as_str());
94        self
95    }
96    /// Set type attribute (for inputs/buttons)
97    #[inline]
98    pub fn set_type(self, t: String) -> VNode {
99        vnode_ffi::vnode_attr(self.handle, "type", t.as_str());
100        self
101    }
102    /// Set value attribute
103    #[inline]
104    pub fn set_value(self, v: String) -> VNode {
105        vnode_ffi::vnode_attr(self.handle, "value", v.as_str());
106        self
107    }
108    /// Set disabled attribute
109    #[inline]
110    pub fn set_disabled(self, d: bool) -> VNode {
111        if d {
112            vnode_ffi::vnode_attr(self.handle, "disabled", "true")
113        }
114        self
115    }
116    /// Get the raw handle (for interop with Rust code)
117    #[inline]
118    pub fn raw_handle(&self) -> u64 {
119        self.handle
120    }
121}
122
123/// Create a container with padding
124#[inline]
125pub fn container() -> VNode {
126    VNode::div()
127        .add_class("wj-container".to_string())
128        .add_style("padding: 16px".to_string())
129}
130
131/// Create a flex row
132#[inline]
133pub fn row() -> VNode {
134    VNode::div().add_style("display: flex; flex-direction: row; gap: 8px".to_string())
135}
136
137/// Create a flex column
138#[inline]
139pub fn column() -> VNode {
140    VNode::div().add_style("display: flex; flex-direction: column; gap: 8px".to_string())
141}
142
143/// Create a spacer element
144#[inline]
145pub fn spacer() -> VNode {
146    VNode::div().add_style("flex: 1".to_string())
147}
148
149/// Create a horizontal divider
150#[inline]
151pub fn divider() -> VNode {
152    VNode::element("hr".to_string())
153        .add_style("border: 0; border-top: 1px solid #333; margin: 8px 0".to_string())
154}