zng_wgt_input/
mouse.rs

1//! Mouse events, [`on_mouse_move`](fn@on_mouse_move), [`on_mouse_enter`](fn@on_mouse_enter),
2//! [`on_mouse_down`](fn@on_mouse_down) and more.
3//!
4//! There events are low level and directly tied to a mouse device.
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::mouse::{
9    MOUSE_CLICK_EVENT, MOUSE_HOVERED_EVENT, MOUSE_INPUT_EVENT, MOUSE_MOVE_EVENT, MOUSE_WHEEL_EVENT, MouseClickArgs, MouseHoverArgs,
10    MouseInputArgs, MouseMoveArgs, MouseWheelArgs,
11};
12use zng_wgt::prelude::*;
13
14event_property! {
15    /// Mouse cursor moved over the widget and cursor capture allows it.
16    pub fn mouse_move {
17        event: MOUSE_MOVE_EVENT,
18        args: MouseMoveArgs,
19        filter: |args| args.capture_allows(),
20    }
21
22    /// Mouse button pressed or released while the cursor is over the widget, the widget is enabled and no cursor
23    /// capture blocks it.
24    pub fn mouse_input {
25        event: MOUSE_INPUT_EVENT,
26        args: MouseInputArgs,
27        filter: |args| args.is_enabled(WIDGET.id()) && args.capture_allows(),
28    }
29
30    /// Mouse button pressed or release while the cursor is over the widget, the widget is disabled and no cursor
31    /// capture blocks it.
32    pub fn disabled_mouse_input {
33        event: MOUSE_INPUT_EVENT,
34        args: MouseInputArgs,
35        filter: |args| args.is_disabled(WIDGET.id()) && args.capture_allows(),
36    }
37
38    /// Mouse button pressed while the cursor is over the widget, the widget is enabled and cursor capture allows it.
39    pub fn mouse_down {
40        event: MOUSE_INPUT_EVENT,
41        args: MouseInputArgs,
42        filter: |args| args.is_mouse_down() && args.is_enabled(WIDGET.id()) && args.capture_allows(),
43    }
44
45    /// Mouse button released while the cursor if over the widget, the widget is enabled and cursor capture allows it.
46    pub fn mouse_up {
47        event: MOUSE_INPUT_EVENT,
48        args: MouseInputArgs,
49        filter: |args| args.is_mouse_up() && args.is_enabled(WIDGET.id()) && args.capture_allows(),
50    }
51
52    /// Mouse clicked on the widget with any button and including repeat clicks and it is enabled.
53    pub fn mouse_any_click {
54        event: MOUSE_CLICK_EVENT,
55        args: MouseClickArgs,
56        filter: |args| args.is_enabled(WIDGET.id()),
57    }
58
59    /// Mouse clicked on the disabled widget with any button, including repeat clicks.
60    pub fn disabled_mouse_any_click {
61        event: MOUSE_CLICK_EVENT,
62        args: MouseClickArgs,
63        filter: |args| args.is_disabled(WIDGET.id()),
64    }
65
66    /// Mouse clicked on the widget with any button but excluding repeat clicks and it is enabled.
67    pub fn mouse_any_single_click {
68        event: MOUSE_CLICK_EVENT,
69        args: MouseClickArgs,
70        filter: |args| args.is_single() && args.is_enabled(WIDGET.id()),
71    }
72
73    /// Mouse double clicked on the widget with any button and it is enabled.
74    pub fn mouse_any_double_click {
75        event: MOUSE_CLICK_EVENT,
76        args: MouseClickArgs,
77        filter: |args| args.is_double() && args.is_enabled(WIDGET.id()),
78    }
79
80    /// Mouse triple clicked on the widget with any button and it is enabled.
81    pub fn mouse_any_triple_click {
82        event: MOUSE_CLICK_EVENT,
83        args: MouseClickArgs,
84        filter: |args| args.is_triple() && args.is_enabled(WIDGET.id()),
85    }
86
87    /// Mouse clicked on the widget with the primary button including repeat clicks and it is enabled.
88    pub fn mouse_click {
89        event: MOUSE_CLICK_EVENT,
90        args: MouseClickArgs,
91        filter: |args| args.is_primary() && args.is_enabled(WIDGET.id()),
92    }
93
94    /// Mouse clicked on the disabled widget with the primary button, including repeat clicks.
95    pub fn disabled_mouse_click {
96        event: MOUSE_CLICK_EVENT,
97        args: MouseClickArgs,
98        filter: |args| args.is_primary() && args.is_disabled(WIDGET.id()),
99    }
100
101    /// Mouse clicked on the widget with the primary button excluding repeat clicks and it is enabled.
102    pub fn mouse_single_click {
103        event: MOUSE_CLICK_EVENT,
104        args: MouseClickArgs,
105        filter: |args| args.is_primary() && args.is_single() && args.is_enabled(WIDGET.id()),
106    }
107
108    /// Mouse double clicked on the widget with the primary button and it is enabled.
109    pub fn mouse_double_click {
110        event: MOUSE_CLICK_EVENT,
111        args: MouseClickArgs,
112        filter: |args| args.is_primary() && args.is_double() && args.is_enabled(WIDGET.id()),
113    }
114
115    /// Mouse triple clicked on the widget with the primary button and it is enabled.
116    pub fn mouse_triple_click {
117        event: MOUSE_CLICK_EVENT,
118        args: MouseClickArgs,
119        filter: |args| args.is_primary() && args.is_triple() && args.is_enabled(WIDGET.id()),
120    }
121
122    /// Mouse is now over the widget or a descendant widget, the widget is enabled and cursor capture allows it.
123    pub fn mouse_enter {
124        event: MOUSE_HOVERED_EVENT,
125        args: MouseHoverArgs,
126        filter: |args| args.is_mouse_enter_enabled(),
127    }
128
129    /// Mouse is no longer over the widget or any descendant widget, the widget is enabled and cursor capture allows it.
130    pub fn mouse_leave {
131        event: MOUSE_HOVERED_EVENT,
132        args: MouseHoverArgs,
133        filter: |args| args.is_mouse_leave_enabled(),
134    }
135
136    /// Mouse entered or left the widget and descendant widgets area, the widget is enabled and cursor capture allows it.
137    ///
138    /// You can use the [`is_mouse_enter`] and [`is_mouse_leave`] methods to determinate the state change.
139    ///
140    /// [`is_mouse_enter`]: MouseHoverArgs::is_mouse_enter
141    /// [`is_mouse_leave`]: MouseHoverArgs::is_mouse_leave
142    pub fn mouse_hovered {
143        event: MOUSE_HOVERED_EVENT,
144        args: MouseHoverArgs,
145        filter: |args| args.is_enabled(WIDGET.id()) && args.capture_allows(),
146    }
147
148    /// Mouse entered or left the widget and descendant widgets area, the widget is disabled and cursor capture allows it.
149    pub fn disabled_mouse_hovered {
150        event: MOUSE_HOVERED_EVENT,
151        args: MouseHoverArgs,
152        filter: |args| args.is_disabled(WIDGET.id()) && args.capture_allows(),
153    }
154
155    /// Mouse wheel scrolled while pointer is hovering widget and it is enabled.
156    pub fn mouse_wheel {
157        event: MOUSE_WHEEL_EVENT,
158        args: MouseWheelArgs,
159        filter: |args| args.is_enabled(WIDGET.id()),
160    }
161
162    /// Mouse wheel scrolled while pointer is hovering widget and it is disabled.
163    pub fn disabled_mouse_wheel {
164        event: MOUSE_WHEEL_EVENT,
165        args: MouseWheelArgs,
166        filter: |args| args.is_enabled(WIDGET.id()),
167    }
168
169    /// Mouse wheel scrolled while pointer is hovering the widget and the pressed keyboard modifiers allow a scroll operation and
170    /// the widget is enabled.
171    pub fn mouse_scroll {
172        event: MOUSE_WHEEL_EVENT,
173        args: MouseWheelArgs,
174        filter: |args| args.is_scroll() && args.is_enabled(WIDGET.id()),
175    }
176
177    /// Mouse wheel scrolled while pointer is hovering the widget and the pressed keyboard modifiers allow a zoom operation and
178    /// the widget is enabled.
179    pub fn mouse_zoom {
180        event: MOUSE_WHEEL_EVENT,
181        args: MouseWheelArgs,
182        filter: |args| args.is_zoom() && args.is_enabled(WIDGET.id()),
183    }
184}