Skip to main content

EventHandlersExt

Trait EventHandlersExt 

pub trait EventHandlersExt: Sized {
Show 35 methods // Required method fn get_event_handlers( &mut self, ) -> &mut HashMap<EventName, EventHandlerType, FxBuildHasher>; // Provided methods fn with_event_handlers( self, event_handlers: HashMap<EventName, EventHandlerType, FxBuildHasher>, ) -> Self { ... } fn on_mouse_down( self, on_mouse_down: impl Into<EventHandler<Event<MouseEventData>>>, ) -> Self { ... } fn on_mouse_up( self, on_mouse_up: impl Into<EventHandler<Event<MouseEventData>>>, ) -> Self { ... } fn on_mouse_move( self, on_mouse_move: impl Into<EventHandler<Event<MouseEventData>>>, ) -> Self { ... } fn on_global_pointer_press( self, on_global_pointer_press: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_global_pointer_down( self, on_global_pointer_down: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_global_pointer_move( self, on_global_pointer_move: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_capture_global_pointer_move( self, on_capture_global_pointer_move: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_capture_global_pointer_press( self, on_capture_global_pointer_press: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_key_down( self, on_key_down: impl Into<EventHandler<Event<KeyboardEventData>>>, ) -> Self { ... } fn on_key_up( self, on_key_up: impl Into<EventHandler<Event<KeyboardEventData>>>, ) -> Self { ... } fn on_global_key_down( self, on_global_key_down: impl Into<EventHandler<Event<KeyboardEventData>>>, ) -> Self { ... } fn on_global_key_up( self, on_global_key_up: impl Into<EventHandler<Event<KeyboardEventData>>>, ) -> Self { ... } fn on_wheel( self, on_wheel: impl Into<EventHandler<Event<WheelEventData>>>, ) -> Self { ... } fn on_touch_cancel( self, on_touch_cancel: impl Into<EventHandler<Event<TouchEventData>>>, ) -> Self { ... } fn on_touch_start( self, on_touch_start: impl Into<EventHandler<Event<TouchEventData>>>, ) -> Self { ... } fn on_touch_move( self, on_touch_move: impl Into<EventHandler<Event<TouchEventData>>>, ) -> Self { ... } fn on_touch_end( self, on_touch_end: impl Into<EventHandler<Event<TouchEventData>>>, ) -> Self { ... } fn on_pointer_press( self, on_pointer_press: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_pointer_down( self, on_pointer_down: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_pointer_move( self, on_pointer_move: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_pointer_enter( self, on_pointer_enter: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_pointer_leave( self, on_pointer_leave: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_pointer_over( self, on_pointer_over: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_pointer_out( self, on_pointer_out: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self { ... } fn on_file_drop( self, on_file_drop: impl Into<EventHandler<Event<FileEventData>>>, ) -> Self { ... } fn on_global_file_hover( self, on_global_file_hover: impl Into<EventHandler<Event<FileEventData>>>, ) -> Self { ... } fn on_global_file_hover_cancelled( self, on_global_file_hover_cancelled: impl Into<EventHandler<Event<FileEventData>>>, ) -> Self { ... } fn on_ime_preedit( self, on_ime_preedit: impl Into<EventHandler<Event<ImePreeditEventData>>>, ) -> Self { ... } fn on_sized( self, on_sized: impl Into<EventHandler<Event<SizedEventData>>>, ) -> Self where Self: LayoutExt { ... } fn on_press( self, on_press: impl Into<EventHandler<Event<PressEventData>>>, ) -> Self { ... } fn on_secondary_down( self, on_secondary_down: impl Into<EventHandler<Event<PressEventData>>>, ) -> Self { ... } fn on_all_press( self, on_press: impl Into<EventHandler<Event<PressEventData>>>, ) -> Self { ... } fn on_focus_press( self, on_focus_press: impl Into<EventHandler<Event<FocusPressEventData>>>, ) -> Self { ... }
}
Expand description

Methods for attaching event handlers to an element.

Many events come in three flavors: the plain one fires only while the pointer is over the element; the global_ variants fire no matter where the event happens; and the capture_ variants fire during the top-down capture phase, before the event reaches the inner element.

For high-level press handling, prefer on_press over the raw mouse/pointer events.

Required Methods§

fn get_event_handlers( &mut self, ) -> &mut HashMap<EventName, EventHandlerType, FxBuildHasher>

Returns a mutable reference to the element’s event handler map.

Provided Methods§

fn with_event_handlers( self, event_handlers: HashMap<EventName, EventHandlerType, FxBuildHasher>, ) -> Self

Replace all of this element’s event handlers with the given map.

fn on_mouse_down( self, on_mouse_down: impl Into<EventHandler<Event<MouseEventData>>>, ) -> Self

Fires when a mouse button is pressed down over the element.

fn on_mouse_up( self, on_mouse_up: impl Into<EventHandler<Event<MouseEventData>>>, ) -> Self

Fires when a mouse button is released over the element.

fn on_mouse_move( self, on_mouse_move: impl Into<EventHandler<Event<MouseEventData>>>, ) -> Self

Fires when the cursor moves over the element.

fn on_global_pointer_press( self, on_global_pointer_press: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Fires when a pointer (mouse or touch) is pressed anywhere, even outside the element.

fn on_global_pointer_down( self, on_global_pointer_down: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Fires when a pointer (mouse or touch) goes down anywhere, even outside the element.

fn on_global_pointer_move( self, on_global_pointer_move: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Fires when a pointer (mouse or touch) moves anywhere, even outside the element.

fn on_capture_global_pointer_move( self, on_capture_global_pointer_move: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Like on_global_pointer_move, but fires during the top-down capture phase.

fn on_capture_global_pointer_press( self, on_capture_global_pointer_press: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Like on_global_pointer_press, but fires during the top-down capture phase.

fn on_key_down( self, on_key_down: impl Into<EventHandler<Event<KeyboardEventData>>>, ) -> Self

Fires when a key is pressed down while the element is focused.

fn on_key_up( self, on_key_up: impl Into<EventHandler<Event<KeyboardEventData>>>, ) -> Self

Fires when a key is released while the element is focused.

fn on_global_key_down( self, on_global_key_down: impl Into<EventHandler<Event<KeyboardEventData>>>, ) -> Self

Fires when a key is pressed down, regardless of which element is focused.

fn on_global_key_up( self, on_global_key_up: impl Into<EventHandler<Event<KeyboardEventData>>>, ) -> Self

Fires when a key is released, regardless of which element is focused.

fn on_wheel( self, on_wheel: impl Into<EventHandler<Event<WheelEventData>>>, ) -> Self

Fires when the scroll wheel is used over the element.

fn on_touch_cancel( self, on_touch_cancel: impl Into<EventHandler<Event<TouchEventData>>>, ) -> Self

Fires when an ongoing touch is cancelled by the system.

fn on_touch_start( self, on_touch_start: impl Into<EventHandler<Event<TouchEventData>>>, ) -> Self

Fires when a touch point is placed on the element.

fn on_touch_move( self, on_touch_move: impl Into<EventHandler<Event<TouchEventData>>>, ) -> Self

Fires when a touch point moves across the element.

fn on_touch_end( self, on_touch_end: impl Into<EventHandler<Event<TouchEventData>>>, ) -> Self

Fires when a touch point is lifted from the element.

fn on_pointer_press( self, on_pointer_press: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Fires when the element is pressed and released by a pointer (mouse or touch).

fn on_pointer_down( self, on_pointer_down: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Fires when a pointer (mouse or touch) goes down over the element.

fn on_pointer_move( self, on_pointer_move: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Fires when a pointer (mouse or touch) moves over the element.

fn on_pointer_enter( self, on_pointer_enter: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Fires when a pointer enters the element.

fn on_pointer_leave( self, on_pointer_leave: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Fires when a pointer leaves the element.

fn on_pointer_over( self, on_pointer_over: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Fires when a pointer is over the element, including over its children.

fn on_pointer_out( self, on_pointer_out: impl Into<EventHandler<Event<PointerEventData>>>, ) -> Self

Fires when a pointer leaves the element or one of its children.

fn on_file_drop( self, on_file_drop: impl Into<EventHandler<Event<FileEventData>>>, ) -> Self

Fires when a file is dropped onto the element.

fn on_global_file_hover( self, on_global_file_hover: impl Into<EventHandler<Event<FileEventData>>>, ) -> Self

Fires when a dragged file hovers anywhere over the window.

fn on_global_file_hover_cancelled( self, on_global_file_hover_cancelled: impl Into<EventHandler<Event<FileEventData>>>, ) -> Self

Fires when a dragged file stops hovering over the window.

fn on_ime_preedit( self, on_ime_preedit: impl Into<EventHandler<Event<ImePreeditEventData>>>, ) -> Self

Fires while text is being composed through an input method editor (IME).

fn on_sized( self, on_sized: impl Into<EventHandler<Event<SizedEventData>>>, ) -> Self
where Self: LayoutExt,

Fires when the element’s measured size or position changes.

fn on_press( self, on_press: impl Into<EventHandler<Event<PressEventData>>>, ) -> Self

This is generally the best event in which to run “press” logic, this might be called onClick, onActivate, or onConnect in other platforms.

Gets triggered when:

  • Click: There is a MouseUp event (Left button) with the in the same element that there had been a MouseDown just before
  • Touched: There is a TouchEnd event in the same element that there had been a TouchStart just before
  • Activated: The element is focused and there is a keydown event pressing the OS activation key (e.g Space, Enter)

fn on_secondary_down( self, on_secondary_down: impl Into<EventHandler<Event<PressEventData>>>, ) -> Self

Also called the context menu click in other platforms. Gets triggered when:

  • Click: There is a MouseDown (Right button) event

fn on_all_press( self, on_press: impl Into<EventHandler<Event<PressEventData>>>, ) -> Self

Gets triggered when:

  • Click: There is a MouseUp event (Any button) with the in the same element that there had been a MouseDown just before
  • Touched: There is a TouchEnd event in the same element that there had been a TouchStart just before
  • Activated: The element is focused and there is a keydown event pressing the OS activation key (e.g Space, Enter)

fn on_focus_press( self, on_focus_press: impl Into<EventHandler<Event<FocusPressEventData>>>, ) -> Self

Gets triggered when:

  • Started clicking: There is a MouseDown event (Left button)
  • Touched: There is a TouchEnd event in the same element that there had been a TouchStart just before

This event is intended to focus elements such as text inputs following each platform style.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§