zng/
pointer_capture.rs

1//! Pointer capture service, properties, events and other types.
2//!
3//! Pointer events target to the topmost widget under the pointer by default, the [`POINTER_CAPTURE`] service
4//! can be used to *capture* the pointer for a widget so that it remains the target for pointer events. The
5//! [`capture_pointer`](fn@capture_pointer) property can be used to automatically capture the pointer when pressed.
6//!
7//! ```
8//! use zng::prelude::*;
9//! # let _scope = APP.defaults();
10//!
11//! # let _ =
12//! Wgt! {
13//!     zng::pointer_capture::capture_pointer = true;
14//!
15//!     zng::pointer_capture::on_got_pointer_capture = hn!(|_| {
16//!         println!("got capture");
17//!     });
18//!     zng::pointer_capture::on_lost_pointer_capture = hn!(|_| {
19//!         println!("lost capture");
20//!     });
21//!
22//!     when *#gesture::is_cap_hovered {
23//!         widget::background_color = colors::GREEN;
24//!     }
25//!     widget::background_color = colors::RED;
26//!     layout::size = 80;
27//! }
28//! # ;
29//! ```
30//!
31//! The example above declares a widget is green when hovered or is holding the pointer capture, the widget also logs
32//! when it gets and loses the capture. Note that the [`gesture::is_cap_hovered`] state is not the same as [`gesture::is_hovered`],
33//! if changed to the second the example will not be green when not hovering, even though the widget still holds the capture, pointer
34//! capture changes the target of pointer events, but it does not mask the fact that the pointer is not actually over the widget.
35//!
36//! [`gesture::is_cap_hovered`]: fn@crate::gesture::is_cap_hovered
37//! [`gesture::is_hovered`]: fn@crate::gesture::is_hovered
38//!
39//! # Full API
40//!
41//! See [`zng_ext_input::pointer_capture`] and [`zng_wgt_input::pointer_capture`] for the full pointer capture API.
42
43pub use zng_ext_input::pointer_capture::{CaptureInfo, CaptureMode, POINTER_CAPTURE, POINTER_CAPTURE_EVENT, PointerCaptureArgs};
44
45pub use zng_wgt_input::pointer_capture::{
46    capture_pointer, capture_pointer_on_init, on_got_pointer_capture, on_lost_pointer_capture, on_pointer_capture_changed,
47    on_pre_got_pointer_capture, on_pre_lost_pointer_capture, on_pre_pointer_capture_changed,
48};