cranpose_app_shell/
pointer_event_time.rs1use cranpose_foundation::PointerEvent;
2use cranpose_render_common::Renderer;
3use web_time::Instant;
4
5use crate::{AppShell, ShellApp};
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub struct PointerEventTime {
10 pub platform_time_ms: Option<i64>,
12 pub animation_time_nanos: u64,
14 pub received_at: Instant,
16}
17
18impl PointerEventTime {
19 pub(crate) fn stamp(self, event: PointerEvent) -> PointerEvent {
20 event
21 .with_time_ms(self.platform_time_ms)
22 .with_animation_time_nanos(self.animation_time_nanos)
23 .with_received_at(self.received_at)
24 }
25}
26
27impl ShellApp {
28 pub(crate) fn realtime_pointer_event_time(
29 &self,
30 platform_time_ms: Option<i64>,
31 ) -> PointerEventTime {
32 let received_at = Instant::now();
33 PointerEventTime {
34 platform_time_ms,
35 animation_time_nanos: self
36 .frame_time_nanos_at(received_at)
37 .max(self.last_frame_time_nanos),
38 received_at,
39 }
40 }
41}
42
43impl<R> AppShell<R>
44where
45 R: Renderer,
46 R::Error: std::fmt::Debug,
47{
48 pub fn realtime_pointer_event_time(&self, platform_time_ms: Option<i64>) -> PointerEventTime {
50 self.app.realtime_pointer_event_time(platform_time_ms)
51 }
52
53 pub fn exact_pointer_event_time(&self, platform_time_ms: Option<i64>) -> PointerEventTime {
56 PointerEventTime {
57 platform_time_ms,
58 animation_time_nanos: self.app.last_frame_time_nanos,
59 received_at: Instant::now(),
60 }
61 }
62}