Module touch

Module 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| {
        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§

TOUCH
Touch service.
TouchConfig
System settings needed to implementing touch gestures.
TouchId
Identifier for a continuous touch contact.
TouchInputArgs
Arguments for TOUCH_INPUT_EVENT.
TouchLongPressArgs
Arguments for TOUCH_LONG_PRESS_EVENT.
TouchMove
Identify the moves of one touch contact in TouchMoveArgs.
TouchMoveArgs
Arguments for TOUCH_MOVE_EVENT.
TouchPosition
Active touch positions.
TouchTapArgs
Arguments for TOUCH_TAP_EVENT.
TouchTransformArgs
Arguments for TOUCH_TRANSFORM_EVENT.
TouchTransformInfo
Info useful for touch gestures computed from two touch points.
TouchTransformMode
Defines the different transforms that a touch transform can do to keep two touch points in a widget aligned with the touch contacts.
TouchUpdate
Identify a new touch contact or a contact update.
TouchedArgs
Arguments for TOUCHED_EVENT.

Enums§

TouchForce
Describes the force of a touch event.
TouchPhase
Describes touch-screen input state.

Statics§

TOUCHED_EVENT
Touch made first contact or lost contact with a widget.
TOUCH_INPUT_EVENT
Touch contact started or ended.
TOUCH_LONG_PRESS_EVENT
Touch contact pressed without moving for more then the tap_max_time.
TOUCH_MOVE_EVENT
Touch contact moved.
TOUCH_TAP_EVENT
Touch tap.
TOUCH_TRANSFORM_EVENT
Two point touch transform.

Functions§

is_cap_touched
P If a touch contact point is over the widget, or is over a descendant, or is captured by it.
is_touch_active
P If an unhandled touch tap has happened on the widget within a time duration defined by contextual touch_active_config.
is_touched
P If a touch contact point is over the widget or a descendant and the it is enabled.
is_touched_from_start
P If a touch contact that started over the widget is over it and it is enabled.
on_disabled_touch_input
P Touch contact started or ended over the widget, it is disabled and cursor capture allows it.
on_disabled_touch_long_press
P Single touch contact was made and held in place for a duration of time (default 500ms) on the widget and the widget is disabled.
on_disabled_touch_tap
P Touch tap on the widget and it is disabled.
on_pre_disabled_touch_input
P Preview on_disabled_touch_input event.
on_pre_disabled_touch_long_press
P Preview on_disabled_touch_long_press event.
on_pre_disabled_touch_tap
P Preview on_disabled_touch_tap event.
on_pre_touch_cancel
P Preview on_touch_cancel event.
on_pre_touch_end
P Preview on_touch_end event.
on_pre_touch_enter
P Preview on_touch_enter event.
on_pre_touch_input
P Preview on_touch_input event.
on_pre_touch_leave
P Preview on_touch_leave event.
on_pre_touch_long_press
P Preview on_touch_long_press event.
on_pre_touch_move
P Preview on_touch_move event.
on_pre_touch_start
P Preview on_touch_start event.
on_pre_touch_tap
P Preview on_touch_tap event.
on_pre_touch_transform
P Preview on_touch_transform event.
on_pre_touched
P Preview on_touched event.
on_touch_cancel
P Touch contact canceled over the widget, it is enabled and cursor capture allows it.
on_touch_end
P Touch contact ended over the widget, it is enabled and cursor capture allows it.
on_touch_enter
P Touch contact is now over the widget or a descendant and it is enabled.
on_touch_input
P Touch contact started or ended over the widget, it is enabled and cursor capture allows it.
on_touch_leave
P Touch contact is no longer over the widget or any descendant and it is enabled.
on_touch_long_press
P Single touch contact was made and held in place for a duration of time (default 500ms) on the widget and the widget is enabled.
on_touch_move
P Touch contact moved over the widget and cursor capture allows it.
on_touch_start
P Touch contact started over the widget, it is enabled and cursor capture allows it.
on_touch_tap
P Touch tap on the widget and it is enabled.
on_touch_transform
P Touch gesture to translate, scale or rotate happened over this widget.
on_touched
P Touch contact entered or left the widget and descendants area and it is enabled.
touch_active_config
P Contextual configuration for is_touch_active.
touch_transform
P Applies transforms from touch gestures on the widget.