Module zng::touch

source ·
Expand description

Touch service, properties, events and other types.

The example below defines a window that shows the active touches and prints the touch state changes. The touch’s text follows the first touch position.

use zng::prelude::*;

Window! {
    child_align = layout::Align::TOP_LEFT;
    child = Text! {
        txt = touch::TOUCH.positions().map(|p| {
            let mut t = Txt::from("[\n");
            for p in p {
                use std::fmt::Write as _;
                writeln!(&mut t, "   ({:?}, {:?})", p.touch, p.position).unwrap();
            }
            t.push(']');
            t.end_mut();
            t
        });
        font_size = 1.4.em();
        layout::offset = touch::TOUCH.positions().map(|p| match p.first() {
            Some(p) => layout::Vector::from(p.position.to_vector()) - layout::Vector::new(0, 100.pct()),
            None => layout::Vector::zero(),
        });
    };
    touch::on_touch_input = hn!(|args: &touch::TouchInputArgs| {
        println!("touch {:?} {:?}", args.touch, args.phase);
    });
}

Touch events are send to the top widget under the touch point. This module also provides touch exclusive gestures like tap, touch enter/leave and on_touch_transform. Note some touch gestures are composed with others in gesture to provide the final pointer gestures. You should prefer using gesture::on_click over on_touch_tap, unless you really want to exclusively touch clicks.

§Full API

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

Structs§

Enums§

Statics§

Functions§