zng/
touch.rs

1//! Touch service, properties, events and other types.
2//!
3//! The example below defines a window that shows the active touches and prints the touch state changes. The
4//! touch's text follows the first touch position.
5//!
6//! ```
7//! use zng::prelude::*;
8//! # let _scope = APP.defaults();
9//!
10//! # let _ =
11//! Window! {
12//!     child_align = layout::Align::TOP_LEFT;
13//!     child = Text! {
14//!         txt = touch::TOUCH.positions().map(|p| {
15//!             let mut t = Txt::from("[\n");
16//!             for p in p {
17//!                 use std::fmt::Write as _;
18//!                 writeln!(&mut t, "   ({:?}, {:?})", p.touch, p.position).unwrap();
19//!             }
20//!             t.push(']');
21//!             t.end_mut();
22//!             t
23//!         });
24//!         font_size = 1.4.em();
25//!         layout::offset = touch::TOUCH.positions().map(|p| match p.first() {
26//!             Some(p) => layout::Vector::from(p.position.to_vector()) - layout::Vector::new(0, 100.pct()),
27//!             None => layout::Vector::zero(),
28//!         });
29//!     };
30//!     touch::on_touch_input = hn!(|args: &touch::TouchInputArgs| {
31//!         println!("touch {:?} {:?}", args.touch, args.phase);
32//!     });
33//! }
34//! # ;
35//! ```
36//!
37//! Touch events are send to the top widget under the touch point. This module also provides touch exclusive gestures like
38//! tap, touch enter/leave and [`on_touch_transform`]. Note some touch gestures are composed with others in [`gesture`] to provide the
39//! final pointer gestures. You should prefer using [`gesture::on_click`] over [`on_touch_tap`], unless you really want to exclusively
40//! touch clicks.
41//!
42//! [`on_touch_tap`]: fn@on_touch_tap
43//! [`on_touch_transform`]: fn@on_touch_transform
44//! [`gesture`]: crate::gesture
45//! [`gesture::on_click`]: fn@crate::gesture::on_click
46//!
47//! # Full API
48//!
49//! See [`zng_ext_input::touch`] and [`zng_wgt_input::touch`] for the full touch API.
50
51pub use zng_ext_input::touch::{
52    TOUCH, TOUCH_INPUT_EVENT, TOUCH_LONG_PRESS_EVENT, TOUCH_MOVE_EVENT, TOUCH_TAP_EVENT, TOUCH_TRANSFORM_EVENT, TOUCHED_EVENT, TouchConfig,
53    TouchForce, TouchId, TouchInputArgs, TouchLongPressArgs, TouchMove, TouchMoveArgs, TouchPhase, TouchPosition, TouchTapArgs,
54    TouchTransformArgs, TouchTransformInfo, TouchTransformMode, TouchUpdate, TouchedArgs,
55};
56
57pub use zng_wgt_input::touch::{
58    on_disabled_touch_input, on_disabled_touch_long_press, on_disabled_touch_tap, on_pre_disabled_touch_input,
59    on_pre_disabled_touch_long_press, on_pre_disabled_touch_tap, on_pre_touch_cancel, on_pre_touch_end, on_pre_touch_enter,
60    on_pre_touch_input, on_pre_touch_leave, on_pre_touch_long_press, on_pre_touch_move, on_pre_touch_start, on_pre_touch_tap,
61    on_pre_touch_transform, on_pre_touched, on_touch_cancel, on_touch_end, on_touch_enter, on_touch_input, on_touch_leave,
62    on_touch_long_press, on_touch_move, on_touch_start, on_touch_tap, on_touch_transform, on_touched,
63};
64
65pub use zng_wgt_input::{is_cap_touched, is_touched, is_touched_from_start, touch_transform};