1use crate::pod::{CursorShape, DragEvent, PointerKind, SwipeDir};
4
5use super::VeloxEngine;
6
7impl VeloxEngine {
8 pub fn cursor_shape(&self) -> CursorShape {
10 let hits = self.cached_hit_regions();
11 if hits.is_empty() {
12 return CursorShape::Default;
13 }
14
15 if self.interaction.is_pressed && self.has_pressed_hit {
17 if let Some(hit) = hits
18 .iter()
19 .rev()
20 .find(|h| h.id == Some(self.pressed_hit_id))
21 {
22 if hit.on_drag().is_some() {
23 return match hit.cursor {
24 Some(
25 c @ (CursorShape::Pointer
26 | CursorShape::Text
27 | CursorShape::ResizeEW
28 | CursorShape::ResizeNS
29 | CursorShape::ResizeNWSE
30 | CursorShape::ResizeNESW
31 | CursorShape::Move
32 | CursorShape::Crosshair),
33 ) => c,
34 Some(CursorShape::NotAllowed) => CursorShape::NotAllowed,
35 _ => CursorShape::Grabbing,
36 };
37 }
38 }
39 }
40
41 let Some((px, py)) = self.interaction.pointer_pos else {
42 return CursorShape::Default;
43 };
44
45 for hit in hits.iter().rev() {
47 let effective = hit.bounds.intersect(hit.clip);
48 if effective.contains(px, py) {
49 if let Some(explicit) = hit.cursor {
50 if explicit == CursorShape::Grab && self.interaction.is_pressed {
51 return CursorShape::Grabbing;
52 }
53 return explicit;
54 }
55 if hit.on_key_input().is_some() {
56 return CursorShape::Text;
57 }
58 if hit.on_drag().is_some() {
59 return if self.interaction.is_pressed {
60 CursorShape::Grabbing
61 } else {
62 CursorShape::Grab
63 };
64 }
65 if hit.on_click().is_some() || hit.on_long_press().is_some() {
66 return CursorShape::Pointer;
67 }
68 if hit.occlude {
69 return CursorShape::Default;
70 }
71 }
72 }
73 CursorShape::Default
74 }
75
76 #[inline]
78 pub fn dispatch_pointer_down_with_kind(
79 &mut self,
80 px: i16,
81 py: i16,
82 kind: PointerKind,
83 ) -> bool {
84 self.active_pointer_kind = kind;
85 self.dispatch_pointer_down(px, py)
86 }
87
88 #[inline]
90 pub fn dispatch_mouse_down(&mut self, px: i16, py: i16) -> bool {
91 self.dispatch_pointer_down_with_kind(px, py, PointerKind::Mouse)
92 }
93
94 #[inline]
96 pub fn dispatch_touch_down(&mut self, px: i16, py: i16) -> bool {
97 self.dispatch_pointer_down_with_kind(px, py, PointerKind::Touch)
98 }
99
100 #[inline(never)]
102 pub fn dispatch_pointer_down(&mut self, px: i16, py: i16) -> bool {
103 let Some(root_id) = self.root_pod else {
104 return false;
105 };
106 self.ensure_hits_available();
107 self.interaction.pointer_pos = Some((px, py));
108 self.interaction.is_pressed = true;
109 self.interaction.focus_visible = false;
111 self.press_start_x = px;
112 self.press_start_y = py;
113 self.has_pressed_hit = false;
114 self.drag_fired_on_down = false;
115 self.press_hold_ms = 0;
116 self.repeat_accum_ms = 0;
117 self.long_press_fired = false;
118 self.long_press_handled = false;
119 self.last_drag_vy = 0;
120 self.interaction_dirty = true;
121
122 let mut hit_focused: Option<u16> = None;
123 let mut matched_passive = false;
124 let hits = self.cached_hit_regions();
125 for hit in hits.iter().rev() {
126 let effective = hit.bounds.intersect(hit.clip);
127 if effective.contains(px, py) {
128 if hit_focused.is_none() {
129 if let Some(fidx) = hit.focus_index {
130 hit_focused = Some(fidx);
131 self.interaction.focused_index = Some(fidx);
132 }
133 }
134 if self.allows_drag_scroll() {
135 if let Some((scroll_id, max_s)) = hit.scroll_target {
136 self.motion.set_scroll_inertia(scroll_id, 0, max_s);
137 }
138 }
139 if let Some(on_drag) = hit.on_drag() {
140 if let Some(hid) = hit.id {
141 self.pressed_hit_id = hid;
142 self.has_pressed_hit = true;
143 }
144 self.drag_fired_on_down = true;
145 let drag_ev = DragEvent {
146 x: px,
147 y: py,
148 local_x: (px - hit.bounds.x).clamp(0, hit.bounds.w),
149 local_y: (py - hit.bounds.y).clamp(0, hit.bounds.h),
150 width: hit.bounds.w.max(1),
151 height: hit.bounds.h.max(1),
152 delta_x: 0,
153 delta_y: 0,
154 };
155 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
156 let mods = self.modifiers;
157 {
158 let mut acx = self
159 .make_action_scope(owner, (px, py), drag_ev)
160 .with_modifiers(mods);
161 on_drag(&mut acx);
162 }
163 self.flush_async_after_event();
164 return true;
165 }
166 if hit.on_click().is_some() || hit.on_long_press().is_some() {
167 if let Some(hid) = hit.id {
168 self.pressed_hit_id = hid;
169 self.has_pressed_hit = true;
170 }
171 return true;
172 }
173 if hit.active_bg_or_focus() {
174 matched_passive = true;
175 }
176 if hit.occlude {
177 if hit_focused.is_none() {
178 self.interaction.focused_index = None;
179 }
180 return true;
181 }
182 }
183 }
184 if hit_focused.is_none() {
186 self.interaction.focused_index = None;
187 }
188 matched_passive
189 }
190
191 #[inline(never)]
193 pub fn dispatch_pointer_secondary_down(&mut self, px: i16, py: i16) -> bool {
194 let Some(root_id) = self.root_pod else {
195 return false;
196 };
197 self.ensure_hits_available();
198 self.interaction.pointer_pos = Some((px, py));
199 self.interaction.focus_visible = false;
200 self.interaction_dirty = true;
201
202 let hits = self.cached_hit_regions();
203 for hit in hits.iter().rev() {
204 let effective = hit.bounds.intersect(hit.clip);
205 if effective.contains(px, py) {
206 if let Some(fidx) = hit.focus_index {
207 self.interaction.focused_index = Some(fidx);
208 }
209 if let Some(on_secondary) = hit.on_secondary_click() {
210 let drag_ev = DragEvent {
211 x: px,
212 y: py,
213 local_x: (px - hit.bounds.x).clamp(0, hit.bounds.w),
214 local_y: (py - hit.bounds.y).clamp(0, hit.bounds.h),
215 width: hit.bounds.w.max(1),
216 height: hit.bounds.h.max(1),
217 delta_x: 0,
218 delta_y: 0,
219 };
220 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
221 let mods = self.modifiers;
222 {
223 let mut acx = self
224 .make_action_scope(owner, (px, py), drag_ev)
225 .with_modifiers(mods);
226 on_secondary(&mut acx);
227 }
228 self.flush_async_after_event();
229 return true;
230 }
231 if hit.occlude {
232 return true;
233 }
234 }
235 }
236 false
237 }
238
239 #[inline(never)]
241 pub fn dispatch_pointer_move(&mut self, px: i16, py: i16) -> bool {
242 let Some(root_id) = self.root_pod else {
243 return false;
244 };
245 self.ensure_hits_available();
246 let prev_pos = self.interaction.pointer_pos;
247 let (prev_x, prev_y) = prev_pos.unwrap_or((px, py));
248 let dx = px.saturating_sub(prev_x);
249 let dy = py.saturating_sub(prev_y);
250 self.interaction.pointer_pos = Some((px, py));
251
252 let hits = self.cached_hit_regions();
253 if !self.interaction.is_pressed {
254 let hover_changed = hits.iter().any(|h| {
255 if !h.has_hover_bg {
256 return false;
257 }
258 let eff = h.bounds.intersect(h.clip);
259 let was_in = prev_pos.is_some_and(|(ox, oy)| eff.contains(ox, oy));
260 was_in != eff.contains(px, py)
261 });
262 if hover_changed {
263 self.interaction_dirty = true;
264 }
265
266 let mods = self.modifiers;
268 let mut fired_any = false;
269 for hit in hits.iter().rev() {
270 let eff = hit.bounds.intersect(hit.clip);
271 let was_in = prev_pos.is_some_and(|(ox, oy)| eff.contains(ox, oy));
272 let is_in = eff.contains(px, py);
273 if was_in && !is_in {
274 if let Some(on_hover) = hit.on_hover() {
275 let ev = DragEvent {
276 x: px,
277 y: py,
278 local_x: (px - hit.bounds.x).clamp(0, hit.bounds.w),
279 local_y: (py - hit.bounds.y).clamp(0, hit.bounds.h),
280 width: hit.bounds.w.max(1),
281 height: hit.bounds.h.max(1),
282 delta_x: dx,
283 delta_y: dy,
284 };
285 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
286 let mut acx = self
287 .make_action_scope(owner, (px, py), ev)
288 .with_modifiers(mods);
289 on_hover(false, &mut acx);
290 fired_any = true;
291 }
292 }
293 }
294 for hit in hits.iter().rev() {
295 let eff = hit.bounds.intersect(hit.clip);
296 let was_in = prev_pos.is_some_and(|(ox, oy)| eff.contains(ox, oy));
297 let is_in = eff.contains(px, py);
298 if is_in {
299 let ev = DragEvent {
300 x: px,
301 y: py,
302 local_x: (px - hit.bounds.x).clamp(0, hit.bounds.w),
303 local_y: (py - hit.bounds.y).clamp(0, hit.bounds.h),
304 width: hit.bounds.w.max(1),
305 height: hit.bounds.h.max(1),
306 delta_x: dx,
307 delta_y: dy,
308 };
309 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
310 if !was_in {
311 if let Some(on_hover) = hit.on_hover() {
312 let mut acx = self
313 .make_action_scope(owner, (px, py), ev)
314 .with_modifiers(mods);
315 on_hover(true, &mut acx);
316 fired_any = true;
317 }
318 }
319 if let Some(on_move) = hit.on_pointer_move() {
320 let mut acx = self
321 .make_action_scope(owner, (px, py), ev)
322 .with_modifiers(mods);
323 on_move(&mut acx);
324 fired_any = true;
325 }
326 if hit.occlude {
327 break;
328 }
329 }
330 }
331 if fired_any {
332 self.flush_async_after_event();
333 self.interaction_dirty = true;
334 return true;
335 }
336 return false;
337 }
338 if dx == 0 && dy == 0 {
339 return false;
340 }
341
342 let (sx, sy) = (self.press_start_x, self.press_start_y);
343 let slop = self.gesture_config.drag_slop_px;
344 if (px - sx).abs() > slop || (py - sy).abs() > slop {
345 self.press_hold_ms = 0;
346 self.repeat_accum_ms = 0;
347 self.long_press_fired = true;
348 }
349
350 for hit in hits.iter().rev() {
352 let effective = hit.bounds.intersect(hit.clip);
353 let matches_pressed = self.has_pressed_hit && hit.id == Some(self.pressed_hit_id);
354 if matches_pressed || effective.contains(sx, sy) {
355 if let Some(on_drag) = hit.on_drag() {
356 let drag_ev = DragEvent {
357 x: px,
358 y: py,
359 local_x: (px - hit.bounds.x).clamp(0, hit.bounds.w),
360 local_y: (py - hit.bounds.y).clamp(0, hit.bounds.h),
361 width: hit.bounds.w.max(1),
362 height: hit.bounds.h.max(1),
363 delta_x: dx,
364 delta_y: dy,
365 };
366 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
367 let mods = self.modifiers;
368 {
369 let mut acx = self
370 .make_action_scope(owner, (px, py), drag_ev)
371 .with_modifiers(mods);
372 on_drag(&mut acx);
373 }
374 self.flush_async_after_event();
375 self.interaction_dirty = true;
376 return true;
377 }
378 if hit.occlude && effective.contains(sx, sy) {
379 break;
380 }
381 }
382 }
383
384 if !self.allows_drag_scroll() {
387 return false;
388 }
389 let mut scroll_to_apply: Option<((u32, i16), bool)> = None;
390 for hit in hits.iter().rev() {
391 let effective = hit.bounds.intersect(hit.clip);
392 if effective.contains(sx, sy) {
393 if let Some(target) = hit.scroll_target {
394 scroll_to_apply = Some((target, hit.scroll_horizontal));
395 break;
396 }
397 if hit.occlude {
398 break;
399 }
400 }
401 }
402
403 if let Some(((scroll_id, max_s), is_horiz)) = scroll_to_apply {
404 let delta = if is_horiz { dx } else { dy };
405 if delta != 0 {
406 let delta_scroll = -delta;
407 self.last_drag_vy = delta_scroll;
408 self.motion.set_scroll_inertia(scroll_id, 0, max_s);
409 let cur = self.motion.scroll_offset(scroll_id);
410 let next = cur.saturating_add(delta_scroll).clamp(0, max_s.max(0));
411 self.motion.set_scroll_offset(scroll_id, next);
412 self.interaction_dirty = true;
413 return true;
414 }
415 }
416 false
417 }
418
419 #[inline(never)]
421 pub fn dispatch_pointer_leave(&mut self) -> bool {
422 let Some((prev_x, prev_y)) = self.interaction.pointer_pos.take() else {
423 return false;
424 };
425 let Some(root_id) = self.root_pod else {
426 return false;
427 };
428 self.ensure_hits_available();
429 let hits = self.cached_hit_regions();
430 let was_hovered = hits.iter().any(|h| {
431 h.has_hover_bg && h.bounds.intersect(h.clip).contains(prev_x, prev_y)
432 });
433 let mods = self.modifiers;
434 let mut fired_leave = false;
435 for hit in hits.iter().rev() {
436 if hit.bounds.intersect(hit.clip).contains(prev_x, prev_y) {
437 if let Some(on_hover) = hit.on_hover() {
438 let ev = DragEvent::default();
439 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
440 let mut acx = self
441 .make_action_scope(owner, (prev_x, prev_y), ev)
442 .with_modifiers(mods);
443 on_hover(false, &mut acx);
444 fired_leave = true;
445 }
446 }
447 }
448 if fired_leave {
449 self.flush_async_after_event();
450 }
451 if was_hovered || fired_leave {
452 self.interaction_dirty = true;
453 }
454 was_hovered || fired_leave
455 }
456
457 #[inline(never)]
459 pub fn dispatch_pointer_up(&mut self, px: i16, py: i16) -> bool {
460 self.ensure_hits_available();
461 self.interaction.pointer_pos = Some((px, py));
462 let was_pressed = self.interaction.is_pressed;
463 let was_long_press_handled = self.long_press_handled;
464 let expected_id = if self.has_pressed_hit {
465 Some(self.pressed_hit_id)
466 } else {
467 None
468 };
469 self.has_pressed_hit = false;
470 let was_drag_fired = self.drag_fired_on_down;
471 self.drag_fired_on_down = false;
472 self.interaction.is_pressed = false;
473 self.press_hold_ms = 0;
474 self.repeat_accum_ms = 0;
475 self.long_press_fired = false;
476 self.long_press_handled = false;
477 self.interaction_dirty = true;
478
479 if !was_pressed {
480 return false;
481 }
482
483 let (sx, sy) = (self.press_start_x, self.press_start_y);
484 let dx = px - sx;
485 let dy = py - sy;
486 let slop = self.gesture_config.drag_slop_px;
487 let moved_far = dx.abs() > slop || dy.abs() > slop;
488
489 if !moved_far {
490 if was_long_press_handled {
491 return true;
492 }
493 return self.trigger_click_internal(px, py, true, expected_id, !was_drag_fired);
494 }
495
496 if self.allows_drag_scroll() {
498 let swipe_th = self.gesture_config.swipe_threshold_px;
499 let edge_w = self.gesture_config.edge_back_width_px;
500 if dx.abs() >= swipe_th || dy.abs() >= swipe_th {
501 let dir = if dx.abs() >= dy.abs() {
502 if dx > 0 {
503 SwipeDir::Right
504 } else {
505 SwipeDir::Left
506 }
507 } else if dy > 0 {
508 SwipeDir::Down
509 } else {
510 SwipeDir::Up
511 };
512 if self.dispatch_swipe(sx, sy, dir) {
513 self.last_drag_vy = 0;
514 return true;
515 }
516 if matches!(self.active_pointer_kind, PointerKind::Touch)
518 && sx <= self.viewport.x + edge_w
519 && dx >= edge_w
520 && dx.abs() > dy.abs() * 2
521 {
522 if self.dispatch_navigate_back() {
523 self.last_drag_vy = 0;
524 return true;
525 }
526 }
527 }
528
529 if self.last_drag_vy.abs() > 1 {
531 let hits = self.cached_hit_regions();
532 let mut scroll_target: Option<(u32, i16)> = None;
533 for hit in hits.iter().rev() {
534 if hit.bounds.intersect(hit.clip).contains(sx, sy) {
535 if let Some(t) = hit.scroll_target {
536 scroll_target = Some(t);
537 break;
538 }
539 if hit.occlude {
540 break;
541 }
542 }
543 }
544 if let Some((scroll_id, max_s)) = scroll_target {
545 self.motion
546 .set_scroll_inertia(scroll_id, self.last_drag_vy, max_s);
547 self.last_drag_vy = 0;
548 return true;
549 }
550 }
551 }
552 self.last_drag_vy = 0;
553 false
554 }
555
556 #[inline(never)]
558 pub fn dispatch_swipe(&mut self, x: i16, y: i16, dir: SwipeDir) -> bool {
559 let Some(root_id) = self.root_pod else {
560 return false;
561 };
562 self.ensure_hits_available();
563 let hits = self.cached_hit_regions();
564 let mut any_handled = false;
565 for hit in hits.iter().rev() {
566 if hit.bounds.intersect(hit.clip).contains(x, y) {
567 if let Some(cb) = hit.on_swipe() {
568 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
569 let stopped = {
570 let mut action = self.make_action_scope(owner, (x, y), DragEvent::default());
571 cb(dir, &mut action);
572 action.is_propagation_stopped()
573 };
574 self.interaction_dirty = true;
575 any_handled = true;
576 if stopped {
577 break;
578 }
579 }
580 if hit.occlude {
581 break;
582 }
583 }
584 }
585 if any_handled {
586 self.flush_async_after_event();
587 }
588 any_handled
589 }
590
591
592 #[inline(never)]
593 pub(super) fn dispatch_scroll_axis_at(&mut self, px: i16, py: i16, delta: i16, prefer_horiz: bool) -> bool {
594 let Some(root_id) = self.root_pod else {
595 return false;
596 };
597 self.ensure_hits_available();
598 let hits = self.cached_hit_regions();
600 let mods = self.modifiers;
601 for hit in hits.iter().rev() {
602 if hit.bounds.intersect(hit.clip).contains(px, py) {
603 if let Some(on_wheel) = hit.on_wheel() {
604 let ev = crate::pod::WheelEvent {
605 x: px,
606 y: py,
607 local_x: (px - hit.bounds.x).clamp(0, hit.bounds.w),
608 local_y: (py - hit.bounds.y).clamp(0, hit.bounds.h),
609 width: hit.bounds.w.max(1),
610 height: hit.bounds.h.max(1),
611 delta_x: if prefer_horiz { delta } else { 0 },
612 delta_y: if prefer_horiz { 0 } else { delta },
613 };
614 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
615 {
616 let mut acx = self
617 .make_action_scope(owner, (px, py), DragEvent::default())
618 .with_modifiers(mods);
619 on_wheel(ev, &mut acx);
620 }
621 self.flush_async_after_event();
622 self.interaction_dirty = true;
623 return true;
624 }
625 if hit.occlude {
626 break;
627 }
628 }
629 }
630 let mut preferred: crate::arena::SmallVec<(u32, i16), 8> = crate::arena::SmallVec::new();
632 let mut fallback: crate::arena::SmallVec<(u32, i16), 8> = crate::arena::SmallVec::new();
633 for hit in self.cached_hit_regions().iter().rev() {
634 if hit.bounds.intersect(hit.clip).contains(px, py) {
635 if let Some(t) = hit.scroll_target {
636 if hit.scroll_horizontal == prefer_horiz {
637 let _ = preferred.push(t);
638 } else if !prefer_horiz {
639 let _ = fallback.push(t);
640 }
641 }
642 if hit.occlude {
643 break;
644 }
645 }
646 }
647 let candidates = if !preferred.is_empty() {
648 preferred.as_slice()
649 } else {
650 fallback.as_slice()
651 };
652 if candidates.is_empty() {
653 return false;
654 }
655 for &(list_id, max_s) in candidates {
656 self.motion.set_scroll_inertia(list_id, 0, max_s);
657 let cur = self.motion.scroll_offset(list_id);
658 let next = cur.saturating_add(delta).clamp(0, max_s.max(0));
659 if next != cur {
660 self.motion.set_scroll_offset(list_id, next);
661 self.interaction_dirty = true;
662 return true;
663 }
664 }
665 true
667 }
668
669 #[inline(never)]
671 pub fn dispatch_pinch_at(&mut self, px: i16, py: i16, delta_scale_x1000: i16) -> bool {
672 self.last_pinch_delta_x1000 = delta_scale_x1000;
673 let Some(root_id) = self.root_pod else {
674 self.interaction_dirty = true;
675 return true;
676 };
677 self.ensure_hits_available();
678 let hits = self.cached_hit_regions();
679 let mods = self.modifiers;
680 let mut handled = false;
681 for hit in hits.iter().rev() {
682 if hit.bounds.intersect(hit.clip).contains(px, py) {
683 if let Some(on_pinch) = hit.on_pinch() {
684 let ev = crate::pod::PinchEvent {
685 x: px,
686 y: py,
687 local_x: (px - hit.bounds.x).clamp(0, hit.bounds.w),
688 local_y: (py - hit.bounds.y).clamp(0, hit.bounds.h),
689 width: hit.bounds.w.max(1),
690 height: hit.bounds.h.max(1),
691 delta_scale_x1000,
692 };
693 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
694 let stopped = {
695 let mut acx = self
696 .make_action_scope(owner, (px, py), DragEvent::default())
697 .with_modifiers(mods);
698 on_pinch(ev, &mut acx);
699 acx.is_propagation_stopped()
700 };
701 handled = true;
702 if stopped {
703 break;
704 }
705 }
706 if hit.occlude {
707 break;
708 }
709 }
710 }
711 if handled {
712 self.flush_async_after_event();
713 }
714 self.interaction_dirty = true;
715 true
716 }
717
718 pub fn dispatch_click(&mut self, px: i16, py: i16) -> bool {
720 self.interaction.pointer_pos = Some((px, py));
721 let hit = self.trigger_click_internal(px, py, false, None, true);
722 if hit {
723 self.interaction_dirty = true;
724 }
725 hit
726 }
727
728 #[inline(never)]
729 pub(super) fn trigger_click_internal(
730 &mut self,
731 px: i16,
732 py: i16,
733 require_pressed_match: bool,
734 expected_id: Option<u32>,
735 allow_drag_fallback: bool,
736 ) -> bool {
737 let Some(root_id) = self.root_pod else {
738 return false;
739 };
740 self.ensure_hits_available();
741 self.interaction.focus_visible = false;
742 let hits = self.cached_hit_regions();
743 for hit in hits.iter().rev() {
744 let effective = hit.bounds.intersect(hit.clip);
745 if effective.contains(px, py) {
746 if let Some(fidx) = hit.focus_index {
747 self.interaction.focused_index = Some(fidx);
748 self.interaction_dirty = true;
749 }
750 if let Some(on_click) = hit.on_click() {
751 if require_pressed_match && hit.id != expected_id {
752 return false;
753 }
754 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
755 {
756 let mut acx =
757 self.make_action_scope(owner, (px, py), DragEvent::default());
758 on_click(&mut acx);
759 }
760 self.flush_async_after_event();
761 return true;
762 }
763 if let Some(on_drag) = hit.on_drag() {
764 if require_pressed_match && hit.id != expected_id {
765 return false;
766 }
767 if !allow_drag_fallback {
768 return true;
769 }
770 let drag_ev = DragEvent {
771 x: px,
772 y: py,
773 local_x: (px - hit.bounds.x).clamp(0, hit.bounds.w),
774 local_y: (py - hit.bounds.y).clamp(0, hit.bounds.h),
775 width: hit.bounds.w.max(1),
776 height: hit.bounds.h.max(1),
777 delta_x: 0,
778 delta_y: 0,
779 };
780 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
781 let mods = self.modifiers;
782 {
783 let mut acx = self
784 .make_action_scope(owner, (px, py), drag_ev)
785 .with_modifiers(mods);
786 on_drag(&mut acx);
787 }
788 self.flush_async_after_event();
789 return true;
790 }
791 if hit.occlude {
792 return false;
793 }
794 }
795 }
796 false
797 }
798
799 #[inline(never)]
801 pub(super) fn trigger_hold_action(&mut self, px: i16, py: i16, is_long_press: bool) -> bool {
802 let Some(root_id) = self.root_pod else {
803 return false;
804 };
805 self.ensure_hits_available();
806 let hits = self.cached_hit_regions();
807 for hit in hits.iter().rev() {
808 let effective = hit.bounds.intersect(hit.clip);
809 if effective.contains(px, py) {
810 if is_long_press {
811 if let Some(on_long_press) = hit.on_long_press() {
812 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
813 {
814 let mut acx =
815 self.make_action_scope(owner, (px, py), DragEvent::default());
816 on_long_press(&mut acx);
817 }
818 self.flush_async_after_event();
819 self.interaction_dirty = true;
820 return true;
821 }
822 } else if hit.auto_repeat {
823 if let Some(on_click) = hit.on_click() {
824 let owner = Self::resolve_hit_pod(root_id, hit.owner_pod);
825 {
826 let mut acx =
827 self.make_action_scope(owner, (px, py), DragEvent::default());
828 on_click(&mut acx);
829 }
830 self.flush_async_after_event();
831 self.interaction_dirty = true;
832 return true;
833 }
834 }
835 if hit.occlude {
836 return false;
837 }
838 }
839 }
840 false
841 }
842
843 pub fn scroll(&mut self, list_id: u32, delta_y: i16) {
845 let cur = self.motion.scroll_offset(list_id);
846 let next = cur.saturating_add(delta_y);
847 if next != cur {
848 self.motion.set_scroll_offset(list_id, next);
849 self.interaction_dirty = true;
850 }
851 }
852}