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 clip_bounds: strata_layout::Rect,
51 pub border_radius: strata_style::types::BorderRadius,
52 pub is_top_layer: bool,
53 pub track_bounds: strata_layout::Rect,
54 pub thumb_bounds: strata_layout::Rect,
55 pub scroll_y: f32,
56 pub max_scroll_y: f32,
57 pub content_h: f32,
58 pub is_id: bool,
59 pub id: String,
60 pub path: Vec<usize>,
61 pub available_travel: f32,
62}
63
64#[derive(Debug, Clone)]
66pub struct ScrollbarDrag {
67 pub is_id: bool,
68 pub id: String,
69 pub path: Vec<usize>,
70 pub start_pointer_y: f32,
71 pub start_scroll_y: f32,
72 pub available_travel: f32,
73 pub max_scroll_y: f32,
74}
75
76#[derive(Debug, Clone)]
78pub struct SmoothScrollTracker {
79 pub container_path: Vec<usize>,
80 pub container_id: String,
81 pub is_id: bool,
82 pub max_scroll_y: f32,
83 pub available_travel: f32,
84 pub bounds_y: f32,
85 pub current_y: f32,
87 pub target_y: f32,
89 pub start_y: f32,
91 pub initial_velocity: f32,
93 pub start_time: std::time::Instant,
95 pub last_event_time: std::time::Instant,
97 pub omega: f32,
99}
100
101#[derive(Debug, Clone)]
103pub struct ScrollTarget {
104 pub path: Vec<usize>,
105 pub id: Option<String>,
106 pub bounds: strata_layout::Rect,
107 pub max_scroll_x: f32,
108 pub max_scroll_y: f32,
109}
110pub fn path_to_node_id(path: &[usize]) -> u64 {
112 let mut hash = 0xcbf29ce484222325u64;
113 for &idx in path {
114 hash ^= idx as u64;
115 hash = hash.wrapping_mul(0x100000001b3u64);
116 }
117 hash
118}
119
120#[derive(Debug, Clone, Copy, PartialEq, Eq)]
122pub enum EditCommand {
123 Undo,
124 Redo,
125 Cut,
126 Copy,
127 Paste,
128 SelectAll,
129}
130
131#[derive(Debug, Clone, Copy, PartialEq, Eq)]
133pub enum PointerDownAction {
134 Ignored,
136 CaretMoved,
138 FocusChanged,
140 DomListenerInvoked,
142}
143
144impl PointerDownAction {
145 #[inline]
146 pub fn is_handled(self) -> bool {
147 self != PointerDownAction::Ignored
148 }
149
150 #[inline]
151 pub fn needs_rebuild(self) -> bool {
152 matches!(
153 self,
154 PointerDownAction::FocusChanged | PointerDownAction::DomListenerInvoked
155 )
156 }
157
158 #[inline]
159 pub fn needs_redraw(self) -> bool {
160 self != PointerDownAction::Ignored
161 }
162}
163
164#[derive(Debug, Clone, Copy, PartialEq, Eq)]
166pub enum PointerMoveAction {
167 Ignored,
169 SelectionDragged,
171 DomListenerInvoked,
173}
174
175impl PointerMoveAction {
176 #[inline]
177 pub fn is_handled(self) -> bool {
178 self != PointerMoveAction::Ignored
179 }
180
181 #[inline]
182 pub fn needs_rebuild(self) -> bool {
183 self == PointerMoveAction::DomListenerInvoked
184 }
185
186 #[inline]
187 pub fn needs_redraw(self) -> bool {
188 self != PointerMoveAction::Ignored
189 }
190}
191
192#[derive(Debug, Clone, Copy, PartialEq, Eq)]
194pub enum PointerUpAction {
195 Ignored,
197 SelectionEnded,
199 DomListenerInvoked,
201}
202
203impl PointerUpAction {
204 #[inline]
205 pub fn is_handled(self) -> bool {
206 self != PointerUpAction::Ignored
207 }
208
209 #[inline]
210 pub fn needs_rebuild(self) -> bool {
211 self == PointerUpAction::DomListenerInvoked
212 }
213
214 #[inline]
215 pub fn needs_redraw(self) -> bool {
216 self != PointerUpAction::Ignored
217 }
218}
219
220#[derive(Debug, Clone, Copy, PartialEq, Eq)]
222pub enum KeyDispatchResult {
223 Ignored,
225 RedrawOnly,
227 NeedsRebuild,
229}
230
231impl KeyDispatchResult {
232 #[inline]
233 pub fn is_handled(self) -> bool {
234 self != KeyDispatchResult::Ignored
235 }
236
237 #[inline]
238 pub fn needs_rebuild(self) -> bool {
239 self == KeyDispatchResult::NeedsRebuild
240 }
241
242 #[inline]
243 pub fn needs_redraw(self) -> bool {
244 self != KeyDispatchResult::Ignored
245 }
246}
247
248#[derive(Clone)]
250pub struct DynamicTextBinding {
251 pub path: Vec<usize>,
252 pub closure: std::rc::Rc<dyn Fn() -> String>,
253 pub last_value: String,
254}
255
256impl std::fmt::Debug for DynamicTextBinding {
257 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
258 f.debug_struct("DynamicTextBinding")
259 .field("path", &self.path)
260 .field("last_value", &self.last_value)
261 .finish()
262 }
263}
264
265#[derive(Debug, Clone, Default, PartialEq, Eq)]
267pub struct InteractionContext<'a> {
268 pub hovered_path: Option<&'a [usize]>,
269 pub focused_path: Option<&'a [usize]>,
270 pub is_mouse_down: bool,
271 pub is_dark_mode: bool,
272}
273
274#[derive(Debug, Clone)]
276pub(crate) struct CascadeElementMeta {
277 pub tag: &'static str,
278 pub classes: Vec<String>,
279 pub id: Option<String>,
280 pub attributes: Vec<(String, String)>,
281 pub pseudo_state: strata_style::selector::PseudoState,
282}
283
284#[derive(Debug, Clone)]
286pub struct ActiveDomDrag {
287 pub source_path: Vec<usize>,
288 pub start_pos: (f32, f32),
289 pub started: bool,
290 pub last_over_path: Option<Vec<usize>>,
291 pub data_transfer: std::rc::Rc<std::cell::RefCell<std::collections::HashMap<String, String>>>,
292}