1#[derive(Clone)]
5pub struct InputHitTarget {
6 pub input_index: usize,
7 pub input_id: Option<String>,
8 pub entity_id: Option<strata_primitives::EntityId>,
9 pub current_value: String,
10 pub font_size: f32,
11 pub line_height: f32,
12 pub is_mono: bool,
13 pub font_family: strata_primitives::AtomId,
14 pub content_box_x: f32,
15 pub content_box_y: f32,
16 pub content_box_width: f32,
17 pub on_input: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
18 pub on_change: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
19 pub on_submit: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
20 pub on_focus: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
21 pub on_blur: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
22}
23
24#[derive(Clone)]
26pub struct ActiveInput {
27 pub input_index: usize,
28 pub input_id: Option<String>,
29 pub entity_id: Option<strata_primitives::EntityId>,
30 pub state: strata_dom::text_input::TextInputState,
31 pub on_input: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
32 pub on_change: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
33 pub on_submit: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
34 pub on_blur: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
35}
36
37impl std::fmt::Debug for ActiveInput {
38 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39 f.debug_struct("ActiveInput")
40 .field("text", &self.state.text.get())
41 .field("cursor", &self.state.cursor_index.get())
42 .finish()
43 }
44}
45
46#[derive(Debug, Clone)]
48pub struct ActiveScrollbar {
49 pub bounds: strata_layout::Rect,
50 pub track_bounds: strata_layout::Rect,
51 pub thumb_bounds: strata_layout::Rect,
52 pub scroll_y: f32,
53 pub max_scroll_y: f32,
54 pub content_h: f32,
55 pub is_id: bool,
56 pub id: String,
57 pub path: Vec<usize>,
58 pub available_travel: f32,
59}
60
61#[derive(Debug, Clone)]
63pub struct ScrollbarDrag {
64 pub is_id: bool,
65 pub id: String,
66 pub path: Vec<usize>,
67 pub start_pointer_y: f32,
68 pub start_scroll_y: f32,
69 pub available_travel: f32,
70 pub max_scroll_y: f32,
71}
72
73#[derive(Debug, Clone)]
75pub struct SmoothScrollTracker {
76 pub container_path: Vec<usize>,
77 pub container_id: String,
78 pub is_id: bool,
79 pub max_scroll_y: f32,
80 pub available_travel: f32,
81 pub bounds_y: f32,
82 pub current_y: f32,
84 pub target_y: f32,
86 pub start_y: f32,
88 pub initial_velocity: f32,
90 pub start_time: std::time::Instant,
92 pub last_event_time: std::time::Instant,
94 pub omega: f32,
96}
97
98#[derive(Debug, Clone)]
100pub struct ScrollTarget {
101 pub path: Vec<usize>,
102 pub id: Option<String>,
103 pub bounds: strata_layout::Rect,
104 pub max_scroll_x: f32,
105 pub max_scroll_y: f32,
106}
107pub fn path_to_node_id(path: &[usize]) -> u64 {
109 let mut hash = 0xcbf29ce484222325u64;
110 for &idx in path {
111 hash ^= idx as u64;
112 hash = hash.wrapping_mul(0x100000001b3u64);
113 }
114 hash
115}
116
117#[derive(Debug, Clone, Copy, PartialEq, Eq)]
119pub enum EditCommand {
120 Undo,
121 Redo,
122 Cut,
123 Copy,
124 Paste,
125 SelectAll,
126}
127
128#[derive(Debug, Clone, Copy, PartialEq, Eq)]
130pub enum PointerDownAction {
131 Ignored,
133 CaretMoved,
135 FocusChanged,
137 DomListenerInvoked,
139}
140
141impl PointerDownAction {
142 #[inline]
143 pub fn is_handled(self) -> bool {
144 self != PointerDownAction::Ignored
145 }
146
147 #[inline]
148 pub fn needs_rebuild(self) -> bool {
149 matches!(
150 self,
151 PointerDownAction::FocusChanged | PointerDownAction::DomListenerInvoked
152 )
153 }
154
155 #[inline]
156 pub fn needs_redraw(self) -> bool {
157 self != PointerDownAction::Ignored
158 }
159}
160
161#[derive(Debug, Clone, Copy, PartialEq, Eq)]
163pub enum PointerMoveAction {
164 Ignored,
166 SelectionDragged,
168 DomListenerInvoked,
170}
171
172impl PointerMoveAction {
173 #[inline]
174 pub fn is_handled(self) -> bool {
175 self != PointerMoveAction::Ignored
176 }
177
178 #[inline]
179 pub fn needs_rebuild(self) -> bool {
180 self == PointerMoveAction::DomListenerInvoked
181 }
182
183 #[inline]
184 pub fn needs_redraw(self) -> bool {
185 self != PointerMoveAction::Ignored
186 }
187}
188
189#[derive(Debug, Clone, Copy, PartialEq, Eq)]
191pub enum PointerUpAction {
192 Ignored,
194 SelectionEnded,
196 DomListenerInvoked,
198}
199
200impl PointerUpAction {
201 #[inline]
202 pub fn is_handled(self) -> bool {
203 self != PointerUpAction::Ignored
204 }
205
206 #[inline]
207 pub fn needs_rebuild(self) -> bool {
208 self == PointerUpAction::DomListenerInvoked
209 }
210
211 #[inline]
212 pub fn needs_redraw(self) -> bool {
213 self != PointerUpAction::Ignored
214 }
215}
216
217#[derive(Debug, Clone, Copy, PartialEq, Eq)]
219pub enum KeyDispatchResult {
220 Ignored,
222 RedrawOnly,
224 NeedsRebuild,
226}
227
228impl KeyDispatchResult {
229 #[inline]
230 pub fn is_handled(self) -> bool {
231 self != KeyDispatchResult::Ignored
232 }
233
234 #[inline]
235 pub fn needs_rebuild(self) -> bool {
236 self == KeyDispatchResult::NeedsRebuild
237 }
238
239 #[inline]
240 pub fn needs_redraw(self) -> bool {
241 self != KeyDispatchResult::Ignored
242 }
243}
244
245#[derive(Clone)]
247pub struct DynamicTextBinding {
248 pub path: Vec<usize>,
249 pub closure: std::rc::Rc<dyn Fn() -> String>,
250 pub last_value: String,
251}
252
253impl std::fmt::Debug for DynamicTextBinding {
254 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
255 f.debug_struct("DynamicTextBinding")
256 .field("path", &self.path)
257 .field("last_value", &self.last_value)
258 .finish()
259 }
260}
261
262#[derive(Debug, Clone, Default, PartialEq, Eq)]
264pub struct InteractionContext<'a> {
265 pub hovered_path: Option<&'a [usize]>,
266 pub focused_path: Option<&'a [usize]>,
267 pub is_mouse_down: bool,
268 pub is_dark_mode: bool,
269}
270
271#[derive(Debug, Clone)]
273pub(crate) struct CascadeElementMeta {
274 pub tag: &'static str,
275 pub classes: Vec<String>,
276 pub id: Option<String>,
277 pub attributes: Vec<(String, String)>,
278 pub pseudo_state: strata_style::selector::PseudoState,
279}
280
281#[derive(Debug, Clone)]
283pub struct ActiveDomDrag {
284 pub source_path: Vec<usize>,
285 pub start_pos: (f32, f32),
286 pub started: bool,
287 pub last_over_path: Option<Vec<usize>>,
288 pub data_transfer: std::rc::Rc<std::cell::RefCell<std::collections::HashMap<String, String>>>,
289}