1//! Touch events, [`on_touch_move`](fn@on_touch_move), [`on_touch_tap`](fn@on_touch_tap),
2//! [`on_touch_start`](fn@on_touch_start) and more.
3//!
4//! There events are low level and directly tied to touch inputs.
5//! Before using them review the [`gesture`](super::gesture) events, in particular the
6//! [`on_click`](fn@super::gesture::on_click) event.
78use zng_ext_input::touch::{
9 TOUCH_INPUT_EVENT, TOUCH_LONG_PRESS_EVENT, TOUCH_MOVE_EVENT, TOUCH_TAP_EVENT, TOUCH_TRANSFORM_EVENT, TOUCHED_EVENT, TouchInputArgs,
10 TouchLongPressArgs, TouchMoveArgs, TouchTapArgs, TouchTransformArgs, TouchedArgs,
11};
12use zng_wgt::prelude::*;
1314event_property! {
15/// Touch contact moved over the widget and cursor capture allows it.
16pub fn touch_move {
17 event: TOUCH_MOVE_EVENT,
18 args: TouchMoveArgs,
19 filter: |args| args.capture_allows(),
20 }
2122/// Touch contact started or ended over the widget, it is enabled and cursor capture allows it.
23pub fn touch_input {
24 event: TOUCH_INPUT_EVENT,
25 args: TouchInputArgs,
26 filter: |args| args.is_enabled(WIDGET.id()) && args.capture_allows(),
27 }
2829/// Touch contact started or ended over the widget, it is disabled and cursor capture allows it.
30pub fn disabled_touch_input {
31 event: TOUCH_INPUT_EVENT,
32 args: TouchInputArgs,
33 filter: |args| args.is_disabled(WIDGET.id()) && args.capture_allows(),
34 }
3536/// Touch contact started over the widget, it is enabled and cursor capture allows it.
37pub fn touch_start {
38 event: TOUCH_INPUT_EVENT,
39 args: TouchInputArgs,
40 filter: |args| args.is_touch_start() && args.is_enabled(WIDGET.id()) && args.capture_allows(),
41 }
4243/// Touch contact ended over the widget, it is enabled and cursor capture allows it.
44pub fn touch_end {
45 event: TOUCH_INPUT_EVENT,
46 args: TouchInputArgs,
47 filter: |args| args.is_touch_end() && args.is_enabled(WIDGET.id()) && args.capture_allows(),
48 }
4950/// Touch contact canceled over the widget, it is enabled and cursor capture allows it.
51pub fn touch_cancel {
52 event: TOUCH_INPUT_EVENT,
53 args: TouchInputArgs,
54 filter: |args| args.is_touch_cancel() && args.is_enabled(WIDGET.id()) && args.capture_allows(),
55 }
5657/// Touch tap on the widget and it is enabled.
58pub fn touch_tap {
59 event: TOUCH_TAP_EVENT,
60 args: TouchTapArgs,
61 filter: |args| args.is_enabled(WIDGET.id()),
62 }
6364/// Touch tap on the widget and it is disabled.
65pub fn disabled_touch_tap {
66 event: TOUCH_TAP_EVENT,
67 args: TouchTapArgs,
68 filter: |args| args.is_disabled(WIDGET.id()),
69 }
7071/// Touch contact is now over the widget or a descendant and it is enabled.
72pub fn touch_enter {
73 event: TOUCHED_EVENT,
74 args: TouchedArgs,
75 filter: |args| args.is_touch_enter_enabled(),
76 }
7778/// Touch contact is no longer over the widget or any descendant and it is enabled.
79pub fn touch_leave {
80 event: TOUCHED_EVENT,
81 args: TouchedArgs,
82 filter: |args| args.is_touch_leave_enabled(),
83 }
8485/// Touch contact entered or left the widget and descendants area and it is enabled.
86 ///
87 /// You can use the [`is_touch_enter`] and [`is_touch_leave`] methods to determinate the state change.
88 ///
89 /// [`is_touch_enter`]: TouchedArgs::is_touch_enter
90 /// [`is_touch_leave`]: TouchedArgs::is_touch_leave
91pub fn touched {
92 event: TOUCHED_EVENT,
93 args: TouchedArgs,
94 filter: |args| args.is_enabled(WIDGET.id()),
95 }
9697/// Touch gesture to translate, scale or rotate happened over this widget.
98pub fn touch_transform {
99 event: TOUCH_TRANSFORM_EVENT,
100 args: TouchTransformArgs,
101 filter: |args| args.is_enabled(WIDGET.id()),
102 }
103104/// Single touch contact was made and held in place for a duration of time (default 500ms) on
105 /// the widget and the widget is enabled.
106pub fn touch_long_press {
107 event: TOUCH_LONG_PRESS_EVENT,
108 args: TouchLongPressArgs,
109 filter: |args| args.is_enabled(WIDGET.id()),
110 }
111112/// Single touch contact was made and held in place for a duration of time (default 500ms) on
113 /// the widget and the widget is disabled.
114pub fn disabled_touch_long_press {
115 event: TOUCH_LONG_PRESS_EVENT,
116 args: TouchLongPressArgs,
117 filter: |args| args.is_disabled(WIDGET.id()),
118 }
119}