Skip to main content

agg_gui/widget/app/
touch.rs

1//! Touch-input forwarding methods on [`App`] — start/move/end/cancel
2//! plus the active-finger count. Split out of `app.rs` (800-line
3//! guardrail); pure plumbing into [`crate::touch_state`] with the same
4//! screen→world conversion (Y-flip + keyboard lift) the mouse path uses.
5
6use super::super::keyboard_scroll;
7use crate::widget::App;
8
9impl App {
10    pub fn on_touch_start(
11        &mut self,
12        device: crate::touch_state::TouchDeviceId,
13        id: crate::touch_state::TouchId,
14        screen_x: f64,
15        screen_y: f64,
16        force: Option<f32>,
17    ) {
18        let pos = keyboard_scroll::lift_to_world(self.flip_y(screen_x, screen_y));
19        self.touch_state.on_start(device, id, pos, force);
20        crate::touch_state::note_touch_event();
21    }
22    pub fn on_touch_move(
23        &mut self,
24        device: crate::touch_state::TouchDeviceId,
25        id: crate::touch_state::TouchId,
26        screen_x: f64,
27        screen_y: f64,
28        force: Option<f32>,
29    ) {
30        let pos = keyboard_scroll::lift_to_world(self.flip_y(screen_x, screen_y));
31        self.touch_state.on_move(device, id, pos, force);
32        crate::touch_state::note_touch_event();
33    }
34    pub fn on_touch_end(
35        &mut self,
36        device: crate::touch_state::TouchDeviceId,
37        id: crate::touch_state::TouchId,
38    ) {
39        self.touch_state.on_end_or_cancel(device, id);
40        crate::touch_state::note_touch_event();
41    }
42    pub fn on_touch_cancel(
43        &mut self,
44        device: crate::touch_state::TouchDeviceId,
45        id: crate::touch_state::TouchId,
46    ) {
47        self.touch_state.on_end_or_cancel(device, id);
48        crate::touch_state::note_touch_event();
49    }
50    /// Current number of fingers down across all devices.  Used by
51    /// widgets that want to know the gesture has *begun* before the
52    /// first frame has had a chance to produce a delta (where
53    /// `current_multi_touch()` may still be `None`).
54    pub fn active_touch_count(&self) -> usize {
55        self.touch_state.active_count()
56    }
57}