zng/
mouse.rs

1//! Mouse service, properties, events and other types.
2//!
3//! The example below defines a window that shows the pressed mouse buttons and prints the button state changes. The
4//! pressed buttons text follows the cursor 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 = mouse::MOUSE.buttons().map_debug();
15//!         layout::offset = mouse::MOUSE.position().map(|p| match p {
16//!             Some(p) => layout::Vector::from(p.position.to_vector()) - layout::Vector::new(0, 100.pct()),
17//!             None => layout::Vector::zero(),
18//!         });
19//!     };
20//!     mouse::on_mouse_input = hn!(|args: &mouse::MouseInputArgs| {
21//!         println!("button {:?} {:?}", args.button, args.state);
22//!     });
23//! }
24//! # ;
25//! ```
26//!
27//! Mouse events are send to the top widget under the cursor. This module also provides mouse exclusive gestures like mouse clicks
28//! and mouse hovered, these gestures are composed with others in [`gesture`] to provide the final pointer gestures. You should
29//! prefer using [`gesture::on_click`] over [`on_mouse_click`], unless you really want to exclusively handle mouse clicks.
30//!
31//! [`gesture`]: crate::gesture
32//! [`gesture::on_click`]: fn@crate::gesture::on_click
33//! [`on_mouse_click`]: fn@on_mouse_click
34//!
35//! # Full API
36//!
37//! See [`zng_ext_input::mouse`] and [`zng_wgt_input::mouse`] for the full mouse API.
38
39pub use zng_ext_input::mouse::{
40    ButtonRepeatConfig, ButtonState, ClickMode, ClickTrigger, MOUSE, MOUSE_CLICK_EVENT, MOUSE_HOVERED_EVENT, MOUSE_INPUT_EVENT,
41    MOUSE_MOVE_EVENT, MOUSE_WHEEL_EVENT, MouseButton, MouseClickArgs, MouseHoverArgs, MouseInputArgs, MouseMoveArgs, MousePosition,
42    MouseScrollDelta, MouseWheelArgs, MultiClickConfig, WidgetInfoBuilderMouseExt, WidgetInfoMouseExt,
43};
44
45pub use zng_wgt_input::mouse::{
46    on_disabled_mouse_any_click, on_disabled_mouse_click, on_disabled_mouse_hovered, on_disabled_mouse_input, on_disabled_mouse_wheel,
47    on_mouse_any_click, on_mouse_any_double_click, on_mouse_any_single_click, on_mouse_any_triple_click, on_mouse_click,
48    on_mouse_double_click, on_mouse_down, on_mouse_enter, on_mouse_hovered, on_mouse_input, on_mouse_leave, on_mouse_move, on_mouse_scroll,
49    on_mouse_single_click, on_mouse_triple_click, on_mouse_up, on_mouse_wheel, on_mouse_zoom, on_pre_disabled_mouse_any_click,
50    on_pre_disabled_mouse_click, on_pre_disabled_mouse_hovered, on_pre_disabled_mouse_input, on_pre_disabled_mouse_wheel,
51    on_pre_mouse_any_click, on_pre_mouse_any_double_click, on_pre_mouse_any_single_click, on_pre_mouse_any_triple_click,
52    on_pre_mouse_click, on_pre_mouse_double_click, on_pre_mouse_down, on_pre_mouse_enter, on_pre_mouse_hovered, on_pre_mouse_input,
53    on_pre_mouse_leave, on_pre_mouse_move, on_pre_mouse_scroll, on_pre_mouse_single_click, on_pre_mouse_triple_click, on_pre_mouse_up,
54    on_pre_mouse_wheel, on_pre_mouse_zoom,
55};
56
57pub use zng_wgt_input::{CursorIcon, CursorImg, CursorSource, click_mode, cursor, is_cap_mouse_pressed, is_mouse_pressed};
58
59/// Raw mouse hardware events, received independent of what window is under the pointer.
60///
61/// You must enable device events in the app to receive this events.
62pub mod raw_device_events {
63    pub use zng_app::view_process::raw_device_events::{
64        BUTTON_EVENT, ButtonArgs, MOUSE_MOTION_EVENT, MOUSE_WHEEL_EVENT, MouseMotionArgs, MouseWheelArgs,
65    };
66}