zng

Module mouse

source
Expand description

Mouse service, properties, events and other types.

The example below defines a window that shows the pressed mouse buttons and prints the button state changes. The pressed buttons text follows the cursor position.

use zng::prelude::*;

Window! {
    child_align = layout::Align::TOP_LEFT;
    child = Text! {
        txt = mouse::MOUSE.buttons().map_debug();
        layout::offset = mouse::MOUSE.position().map(|p| match p {
            Some(p) => layout::Vector::from(p.position.to_vector()) - layout::Vector::new(0, 100.pct()),
            None => layout::Vector::zero(),
        });
    };
    mouse::on_mouse_input = hn!(|args: &mouse::MouseInputArgs| {
        println!("button {:?} {:?}", args.button, args.state);
    });
}

Mouse events are send to the top widget under the cursor. This module also provides mouse exclusive gestures like mouse clicks and mouse hovered, these gestures are composed with others in gesture to provide the final pointer gestures. You should prefer using gesture::on_click over on_mouse_click, unless you really want to exclusively handle mouse clicks.

§Full API

See zng_ext_input::mouse and zng_wgt_input::mouse for the full mouse API.

Modules§

  • Raw mouse hardware events, received independent of what window is under the pointer.

Structs§

Enums§

Statics§

Traits§

Functions§