Module pointer_capture

Module pointer_capture 

Source
Expand description

Pointer capture service, properties, events and other types.

Pointer events target to the topmost widget under the pointer by default, the POINTER_CAPTURE service can be used to capture the pointer for a widget so that it remains the target for pointer events. The capture_pointer property can be used to automatically capture the pointer when pressed.

use zng::prelude::*;

Wgt! {
    zng::pointer_capture::capture_pointer = true;

    zng::pointer_capture::on_got_pointer_capture = hn!(|_| {
        println!("got capture");
    });
    zng::pointer_capture::on_lost_pointer_capture = hn!(|_| {
        println!("lost capture");
    });

    when *#gesture::is_cap_hovered {
        widget::background_color = colors::GREEN;
    }
    widget::background_color = colors::RED;
    layout::size = 80;
}

The example above declares a widget is green when hovered or is holding the pointer capture, the widget also logs when it gets and loses the capture. Note that the gesture::is_cap_hovered state is not the same as gesture::is_hovered, if changed to the second the example will not be green when not hovering, even though the widget still holds the capture, pointer capture changes the target of pointer events, but it does not mask the fact that the pointer is not actually over the widget.

§Full API

See zng_ext_input::pointer_capture and zng_wgt_input::pointer_capture for the full pointer capture API.

Structs§

CaptureInfo
Information about mouse and touch capture in a mouse or touch event argument.
POINTER_CAPTURE
Mouse and touch capture service.
PointerCaptureArgs
POINTER_CAPTURE_EVENT arguments.

Enums§

CaptureMode
Mouse and touch capture mode.

Statics§

POINTER_CAPTURE_EVENT
Mouse and touch capture changed event.

Functions§

capture_pointer
P Capture mouse and touch for the widget on press.
capture_pointer_on_init
P Capture mouse and touch for the widget on init.
on_got_pointer_capture
P Widget acquired mouse and touch capture.
on_lost_pointer_capture
P Widget lost mouse and touch capture.
on_pointer_capture_changed
P Widget acquired or lost mouse and touch capture.
on_pre_got_pointer_capture
P Preview on_got_pointer_capture event.
on_pre_lost_pointer_capture
P Preview on_lost_pointer_capture event.
on_pre_pointer_capture_changed
P Preview on_pointer_capture_changed event.