Skip to main content

euv_core/scene/dsl/view_runtime/
impl.rs

1use super::*;
2
3/// Builder methods for `NodeInitPatch` consumed by `view!` procedural macro expansions.
4impl NodeInitPatch {
5    /// Creates an empty `NodeInitPatch` with all modifiers unset.
6    ///
7    /// # Returns
8    ///
9    /// - `Self` - Empty node initialization patch.
10    #[must_use]
11    #[inline(always)]
12    pub fn empty() -> Self {
13        Self::default()
14    }
15
16    /// Sets explicit keyboard focusability on the target node.
17    ///
18    /// # Arguments
19    ///
20    /// - `Self` - Patch builder.
21    /// - `bool` - Whether keyboard focus is enabled.
22    ///
23    /// # Returns
24    ///
25    /// - `Self` - Updated patch builder.
26    #[must_use]
27    #[inline(always)]
28    pub fn with_focusable(mut self, focusable: bool) -> Self {
29        let _: &mut Self = self.set_focusable(Some(focusable));
30        self
31    }
32
33    /// Attaches an `on_click` callback handler to the target node.
34    ///
35    /// # Arguments
36    ///
37    /// - `Self` - Patch builder.
38    /// - `UiEventHandler` - Click event callback.
39    ///
40    /// # Returns
41    ///
42    /// - `Self` - Updated patch builder.
43    #[must_use]
44    #[inline(always)]
45    pub fn with_on_click(mut self, handler: UiEventHandler) -> Self {
46        let _: &mut Self = self.set_on_click(Some(handler));
47        self
48    }
49
50    /// Attaches an `on_change` callback handler to the target node.
51    ///
52    /// # Arguments
53    ///
54    /// - `Self` - Patch builder.
55    /// - `UiEventHandler` - Change event callback.
56    ///
57    /// # Returns
58    ///
59    /// - `Self` - Updated patch builder.
60    #[must_use]
61    #[inline(always)]
62    pub fn with_on_change(mut self, handler: UiEventHandler) -> Self {
63        let _: &mut Self = self.set_on_change(Some(handler));
64        self
65    }
66
67    /// Attaches an `on_scroll` callback handler to the target node.
68    ///
69    /// # Arguments
70    ///
71    /// - `Self` - Patch builder.
72    /// - `UiEventHandler` - Scroll event callback.
73    ///
74    /// # Returns
75    ///
76    /// - `Self` - Updated patch builder.
77    #[must_use]
78    #[inline(always)]
79    pub fn with_on_scroll(mut self, handler: UiEventHandler) -> Self {
80        let _: &mut Self = self.set_on_scroll(Some(handler));
81        self
82    }
83
84    /// Attaches an `on_pointer_down` callback handler to the target node.
85    ///
86    /// # Arguments
87    ///
88    /// - `Self` - Patch builder.
89    /// - `UiEventHandler` - Pointer-down event callback.
90    ///
91    /// # Returns
92    ///
93    /// - `Self` - Updated patch builder.
94    #[must_use]
95    #[inline(always)]
96    pub fn with_on_pointer_down(mut self, handler: UiEventHandler) -> Self {
97        let _: &mut Self = self.set_on_pointer_down(Some(handler));
98        self
99    }
100
101    /// Attaches an `on_pointer_move` callback handler to the target node.
102    ///
103    /// # Arguments
104    ///
105    /// - `Self` - Patch builder.
106    /// - `UiEventHandler` - Pointer-move event callback.
107    ///
108    /// # Returns
109    ///
110    /// - `Self` - Updated patch builder.
111    #[must_use]
112    #[inline(always)]
113    pub fn with_on_pointer_move(mut self, handler: UiEventHandler) -> Self {
114        let _: &mut Self = self.set_on_pointer_move(Some(handler));
115        self
116    }
117
118    /// Attaches an `on_pointer_up` callback handler to the target node.
119    ///
120    /// # Arguments
121    ///
122    /// - `Self` - Patch builder.
123    /// - `UiEventHandler` - Pointer-up event callback.
124    ///
125    /// # Returns
126    ///
127    /// - `Self` - Updated patch builder.
128    #[must_use]
129    #[inline(always)]
130    pub fn with_on_pointer_up(mut self, handler: UiEventHandler) -> Self {
131        let _: &mut Self = self.set_on_pointer_up(Some(handler));
132        self
133    }
134
135    /// Attaches an `on_pointer_enter` callback handler to the target node.
136    ///
137    /// # Arguments
138    ///
139    /// - `Self` - Patch builder.
140    /// - `UiEventHandler` - Pointer-enter event callback.
141    ///
142    /// # Returns
143    ///
144    /// - `Self` - Updated patch builder.
145    #[must_use]
146    #[inline(always)]
147    pub fn with_on_pointer_enter(mut self, handler: UiEventHandler) -> Self {
148        let _: &mut Self = self.set_on_pointer_enter(Some(handler));
149        self
150    }
151
152    /// Attaches an `on_pointer_leave` callback handler to the target node.
153    ///
154    /// # Arguments
155    ///
156    /// - `Self` - Patch builder.
157    /// - `UiEventHandler` - Pointer-leave event callback.
158    ///
159    /// # Returns
160    ///
161    /// - `Self` - Updated patch builder.
162    #[must_use]
163    #[inline(always)]
164    pub fn with_on_pointer_leave(mut self, handler: UiEventHandler) -> Self {
165        let _: &mut Self = self.set_on_pointer_leave(Some(handler));
166        self
167    }
168
169    /// Attaches a unified `on_hover` handler invoked on both `PointerEnter` and `PointerLeave`.
170    ///
171    /// # Arguments
172    ///
173    /// - `Self` - Patch builder.
174    /// - `UiEventHandler` - Hover event callback.
175    ///
176    /// # Returns
177    ///
178    /// - `Self` - Updated patch builder.
179    #[must_use]
180    #[inline(always)]
181    pub fn with_on_hover(mut self, handler: UiEventHandler) -> Self {
182        let leave_handler: UiEventHandler = Rc::clone(&handler);
183        let _: &mut Self = self
184            .set_on_pointer_enter(Some(handler))
185            .set_on_pointer_leave(Some(leave_handler));
186        self
187    }
188
189    /// Attaches an `on_key` callback handler to the target node.
190    ///
191    /// # Arguments
192    ///
193    /// - `Self` - Patch builder.
194    /// - `UiEventHandler` - Key-down event callback.
195    ///
196    /// # Returns
197    ///
198    /// - `Self` - Updated patch builder.
199    #[must_use]
200    #[inline(always)]
201    pub fn with_on_key(mut self, handler: UiEventHandler) -> Self {
202        let _: &mut Self = self.set_on_key_down(Some(handler));
203        self
204    }
205
206    /// Attaches an `on_focus` callback handler to the target node.
207    ///
208    /// # Arguments
209    ///
210    /// - `Self` - Patch builder.
211    /// - `UiEventHandler` - Focus event callback.
212    ///
213    /// # Returns
214    ///
215    /// - `Self` - Updated patch builder.
216    #[must_use]
217    #[inline(always)]
218    pub fn with_on_focus(mut self, handler: UiEventHandler) -> Self {
219        let _: &mut Self = self.set_on_focus(Some(handler));
220        self
221    }
222
223    /// Attaches an `on_blur` callback handler to the target node.
224    ///
225    /// # Arguments
226    ///
227    /// - `Self` - Patch builder.
228    /// - `UiEventHandler` - Blur event callback.
229    ///
230    /// # Returns
231    ///
232    /// - `Self` - Updated patch builder.
233    #[must_use]
234    #[inline(always)]
235    pub fn with_on_blur(mut self, handler: UiEventHandler) -> Self {
236        let _: &mut Self = self.set_on_blur(Some(handler));
237        self
238    }
239
240    /// Attaches semantic `A11yProps` accessibility metadata to the target node.
241    ///
242    /// # Arguments
243    ///
244    /// - `Self` - Patch builder.
245    /// - `A11yProps` - Accessibility role, label, hint, and state metadata.
246    ///
247    /// # Returns
248    ///
249    /// - `Self` - Updated patch builder.
250    #[must_use]
251    #[inline(always)]
252    pub fn with_a11y(mut self, props: A11yProps) -> Self {
253        let _: &mut Self = self.set_a11y(Some(props));
254        self
255    }
256}