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.
78use 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::*;
1314event_property! {
15/// Mouse cursor moved over the widget and cursor capture allows it.
16pub fn mouse_move {
17 event: MOUSE_MOVE_EVENT,
18 args: MouseMoveArgs,
19 filter: |args| args.capture_allows(),
20 }
2122/// Mouse button pressed or released while the cursor is over the widget, the widget is enabled and no cursor
23 /// capture blocks it.
24pub fn mouse_input {
25 event: MOUSE_INPUT_EVENT,
26 args: MouseInputArgs,
27 filter: |args| args.is_enabled(WIDGET.id()) && args.capture_allows(),
28 }
2930/// Mouse button pressed or release while the cursor is over the widget, the widget is disabled and no cursor
31 /// capture blocks it.
32pub fn disabled_mouse_input {
33 event: MOUSE_INPUT_EVENT,
34 args: MouseInputArgs,
35 filter: |args| args.is_disabled(WIDGET.id()) && args.capture_allows(),
36 }
3738/// Mouse button pressed while the cursor is over the widget, the widget is enabled and cursor capture allows it.
39pub 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 }
4445/// Mouse button released while the cursor if over the widget, the widget is enabled and cursor capture allows it.
46pub 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 }
5152/// Mouse clicked on the widget with any button and including repeat clicks and it is enabled.
53pub fn mouse_any_click {
54 event: MOUSE_CLICK_EVENT,
55 args: MouseClickArgs,
56 filter: |args| args.is_enabled(WIDGET.id()),
57 }
5859/// Mouse clicked on the disabled widget with any button, including repeat clicks.
60pub fn disabled_mouse_any_click {
61 event: MOUSE_CLICK_EVENT,
62 args: MouseClickArgs,
63 filter: |args| args.is_disabled(WIDGET.id()),
64 }
6566/// Mouse clicked on the widget with any button but excluding repeat clicks and it is enabled.
67pub 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 }
7273/// Mouse double clicked on the widget with any button and it is enabled.
74pub 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 }
7980/// Mouse triple clicked on the widget with any button and it is enabled.
81pub 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 }
8687/// Mouse clicked on the widget with the primary button including repeat clicks and it is enabled.
88pub fn mouse_click {
89 event: MOUSE_CLICK_EVENT,
90 args: MouseClickArgs,
91 filter: |args| args.is_primary() && args.is_enabled(WIDGET.id()),
92 }
9394/// Mouse clicked on the disabled widget with the primary button, including repeat clicks.
95pub fn disabled_mouse_click {
96 event: MOUSE_CLICK_EVENT,
97 args: MouseClickArgs,
98 filter: |args| args.is_primary() && args.is_disabled(WIDGET.id()),
99 }
100101/// Mouse clicked on the widget with the primary button excluding repeat clicks and it is enabled.
102pub 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 }
107108/// Mouse double clicked on the widget with the primary button and it is enabled.
109pub 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 }
114115/// Mouse triple clicked on the widget with the primary button and it is enabled.
116pub 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 }
121122/// Mouse is now over the widget or a descendant widget, the widget is enabled and cursor capture allows it.
123pub fn mouse_enter {
124 event: MOUSE_HOVERED_EVENT,
125 args: MouseHoverArgs,
126 filter: |args| args.is_mouse_enter_enabled(),
127 }
128129/// Mouse is no longer over the widget or any descendant widget, the widget is enabled and cursor capture allows it.
130pub fn mouse_leave {
131 event: MOUSE_HOVERED_EVENT,
132 args: MouseHoverArgs,
133 filter: |args| args.is_mouse_leave_enabled(),
134 }
135136/// 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
142pub fn mouse_hovered {
143 event: MOUSE_HOVERED_EVENT,
144 args: MouseHoverArgs,
145 filter: |args| args.is_enabled(WIDGET.id()) && args.capture_allows(),
146 }
147148/// Mouse entered or left the widget and descendant widgets area, the widget is disabled and cursor capture allows it.
149pub fn disabled_mouse_hovered {
150 event: MOUSE_HOVERED_EVENT,
151 args: MouseHoverArgs,
152 filter: |args| args.is_disabled(WIDGET.id()) && args.capture_allows(),
153 }
154155/// Mouse wheel scrolled while pointer is hovering widget and it is enabled.
156pub fn mouse_wheel {
157 event: MOUSE_WHEEL_EVENT,
158 args: MouseWheelArgs,
159 filter: |args| args.is_enabled(WIDGET.id()),
160 }
161162/// Mouse wheel scrolled while pointer is hovering widget and it is disabled.
163pub fn disabled_mouse_wheel {
164 event: MOUSE_WHEEL_EVENT,
165 args: MouseWheelArgs,
166 filter: |args| args.is_enabled(WIDGET.id()),
167 }
168169/// Mouse wheel scrolled while pointer is hovering the widget and the pressed keyboard modifiers allow a scroll operation and
170 /// the widget is enabled.
171pub fn mouse_scroll {
172 event: MOUSE_WHEEL_EVENT,
173 args: MouseWheelArgs,
174 filter: |args| args.is_scroll() && args.is_enabled(WIDGET.id()),
175 }
176177/// Mouse wheel scrolled while pointer is hovering the widget and the pressed keyboard modifiers allow a zoom operation and
178 /// the widget is enabled.
179pub fn mouse_zoom {
180 event: MOUSE_WHEEL_EVENT,
181 args: MouseWheelArgs,
182 filter: |args| args.is_zoom() && args.is_enabled(WIDGET.id()),
183 }
184}