zng_wgt_input/
touch.rs

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.
7
8use 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::*;
13
14event_property! {
15    /// Touch contact moved over the widget and cursor capture allows it.
16    pub fn touch_move {
17        event: TOUCH_MOVE_EVENT,
18        args: TouchMoveArgs,
19        filter: |args| args.capture_allows(),
20    }
21
22    /// Touch contact started or ended over the widget, it is enabled and cursor capture allows it.
23    pub fn touch_input {
24        event: TOUCH_INPUT_EVENT,
25        args: TouchInputArgs,
26        filter: |args| args.is_enabled(WIDGET.id()) && args.capture_allows(),
27    }
28
29    /// Touch contact started or ended over the widget, it is disabled and cursor capture allows it.
30    pub fn disabled_touch_input {
31        event: TOUCH_INPUT_EVENT,
32        args: TouchInputArgs,
33        filter: |args| args.is_disabled(WIDGET.id()) && args.capture_allows(),
34    }
35
36    /// Touch contact started over the widget, it is enabled and cursor capture allows it.
37    pub 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    }
42
43    /// Touch contact ended over the widget, it is enabled and cursor capture allows it.
44    pub 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    }
49
50    /// Touch contact canceled over the widget, it is enabled and cursor capture allows it.
51    pub 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    }
56
57    /// Touch tap on the widget and it is enabled.
58    pub fn touch_tap {
59        event: TOUCH_TAP_EVENT,
60        args: TouchTapArgs,
61        filter: |args| args.is_enabled(WIDGET.id()),
62    }
63
64    /// Touch tap on the widget and it is disabled.
65    pub fn disabled_touch_tap {
66        event: TOUCH_TAP_EVENT,
67        args: TouchTapArgs,
68        filter: |args| args.is_disabled(WIDGET.id()),
69    }
70
71    /// Touch contact is now over the widget or a descendant and it is enabled.
72    pub fn touch_enter {
73        event: TOUCHED_EVENT,
74        args: TouchedArgs,
75        filter: |args| args.is_touch_enter_enabled(),
76    }
77
78    /// Touch contact is no longer over the widget or any descendant and it is enabled.
79    pub fn touch_leave {
80        event: TOUCHED_EVENT,
81        args: TouchedArgs,
82        filter: |args| args.is_touch_leave_enabled(),
83    }
84
85    /// 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
91    pub fn touched {
92        event: TOUCHED_EVENT,
93        args: TouchedArgs,
94        filter: |args| args.is_enabled(WIDGET.id()),
95    }
96
97    /// Touch gesture to translate, scale or rotate happened over this widget.
98    pub fn touch_transform {
99        event: TOUCH_TRANSFORM_EVENT,
100        args: TouchTransformArgs,
101        filter: |args| args.is_enabled(WIDGET.id()),
102    }
103
104    /// 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.
106    pub fn touch_long_press {
107        event: TOUCH_LONG_PRESS_EVENT,
108        args: TouchLongPressArgs,
109        filter: |args| args.is_enabled(WIDGET.id()),
110    }
111
112    /// 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.
114    pub fn disabled_touch_long_press {
115        event: TOUCH_LONG_PRESS_EVENT,
116        args: TouchLongPressArgs,
117        filter: |args| args.is_disabled(WIDGET.id()),
118    }
119}