#[non_exhaustive]pub enum Event<'a> {
Show 17 variants
Command(Command, Option<PhysicalKey>),
Key(&'a KeyEvent, bool),
Ime(Ime<'a>),
Scroll(ScrollDelta),
Pan(Affine),
PointerMove {
press: Press,
},
PressStart(PressStart),
PressMove {
press: Press,
delta: Vec2,
},
PressEnd {
press: Press,
success: bool,
},
Timer(TimerHandle),
NavFocus(FocusSource),
LostNavFocus,
SelFocus(FocusSource),
LostSelFocus,
KeyFocus,
LostKeyFocus,
MouseOver(bool),
}Expand description
Events addressed to a widget
Note that a few events are received by disabled widgets; see
Event::pass_when_disabled.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Command(Command, Option<PhysicalKey>)
Command input
A generic “command”. The source is often but not always a key press. In many cases (but not all) the target widget has navigation focus.
A PhysicalKey is attached when the command is caused by a key press.
The recipient may use this to call EventCx::depress_with_key.
If a widget has keyboard input focus (see
EventCx::request_key_focus) it will instead receive
Event::Key for key presses (but may still receive Event::Command
from other sources).
Key(&'a KeyEvent, bool)
Keyboard input: event, is_synthetic
This is only received by a widget with keyboard focus.
On some platforms, synthetic key events are generated when a window
gains or loses focus with a key held (see documentation of
winit::event::WindowEvent::KeyboardInput). This is indicated by the
second parameter, is_synthetic. Unless you need to track key states
it is advised only to match Event::Key(event, false).
Some key presses can be mapped to a Command. To do this (normally
only when event.state == ElementState::Pressed && !is_synthetic), use
cx.config().shortcuts(|s| s.try_match(cx.modifiers(), &event.logical_key)
or (omitting shortcut matching) Command::new(event.logical_key).
Note that if the handler returns Unused the widget might
then receive Event::Command for the same key press, but this is not
guaranteed (behaviour may change in future versions).
For standard text input, simply consume event.text when
event.state == ElementState::Pressed && !is_synthetic.
NOTE: unlike Winit, we force text = None for control chars and when
Ctrl, Alt or Super modifier keys are
pressed. This is subject to change.
Ime(Ime<'a>)
An Input Method Editor event
IME events are only received with IME focus.
On Ime::Enabled,
the widget should call EventState::set_ime_cursor_area immediately
and each time the area changes (relative to the widget’s coordinate
space), until Ime::Disabled is received. Failure to do so will
result in the widget’s entire rect being used as the IME cursor area.
Scroll(ScrollDelta)
A mouse or touchpad scroll event
Pan(Affine)
A mouse or touch-screen move/zoom/rotate event
This event is sent for certain types of grab (PressStart::grab),
enabling two-finger scale/rotate gestures as well as translation.
Mouse-grabs generate translation (delta component) only. Touch grabs
optionally also generate rotation and scaling components, depending on
the GrabMode.
PointerMove
Movement of mouse pointer without press
This event is only sent one case: when the mouse is moved while a
Popup is open and there is not an active PressStart::grab on the
mouse pointer.
This event may be sent 10+ times per frame, thus it is important that
the handler be fast. It may be useful to schedule a pre-draw update
with EventState::request_frame_timer to handle any post-move
updates.
PressStart(PressStart)
A mouse button was pressed or touch event started
Call PressStart::grab in order to “grab” corresponding motion
and release events.
This event is sent to the widget under the mouse or touch position. If no such widget is found, this event is not sent.
PressMove
Movement of mouse or a touch press
This event is only sent when a (PressStart::grab) is active.
Motion events for the grabbed mouse pointer or touched finger are sent.
If cur_id is None, no widget was found at the coordinate (either
outside the window or crate::Tile::try_probe failed).
This event may be sent 10+ times per frame, thus it is important that
the handler be fast. It may be useful to schedule a pre-draw update
with EventState::request_frame_timer to handle any post-move
updates.
PressEnd
End of a click/touch press
If success, this is a button-release or touch finish; otherwise this
is a cancelled/interrupted grab. “Activation events” (e.g. clicking of a
button or menu item) should only happen on success. “Movement events”
such as panning, moving a slider or opening a menu should not be undone
when cancelling: the panned item or slider should be released as is, or
the menu should remain open.
This event is only sent when a (PressStart::grab) is active.
Release/cancel events for the same mouse button or touched finger are
sent.
If cur_id is None, no widget was found at the coordinate (either
outside the window or crate::Tile::try_probe failed).
Timer(TimerHandle)
Update from a timer
This event must be requested by EventState::request_timer.
Notification that a widget has gained navigation focus
Navigation focus implies that the widget is highlighted and will be the
primary target of Event::Command, and is thus able to receive basic
keyboard input (e.g. arrow keys). To receive full keyboard input
(Event::Key), call EventCx::request_key_focus.
With FocusSource::Pointer the widget should already have received
Event::PressStart.
With FocusSource::Key, EventCx::set_scroll is
called automatically (to ensure that the widget is visible) and the
response will be forced to Used.
Notification that a widget has lost navigation focus
SelFocus(FocusSource)
Notification that a widget has gained selection focus
This focus must be requested by calling
EventCx::request_sel_focus or EventCx::request_key_focus.
LostSelFocus
Notification that a widget has lost selection focus
In the case the widget also had character focus, Event::LostKeyFocus is
received first.
KeyFocus
Notification that a widget has gained keyboard input focus
This focus must be requested by calling
EventCx::request_key_focus.
This is always preceeded by Event::SelFocus and is received prior to
Event::Key events.
LostKeyFocus
Notification that a widget has lost keyboard input focus
MouseOver(bool)
Notification that the mouse moves over or leaves a widget
The state is true on mouse over, false when the mouse leaves.
Implementations§
Source§impl<'a> Event<'a>
impl<'a> Event<'a>
Sourcepub fn on_click<F: FnOnce(&mut EventCx<'_>)>(
self,
cx: &mut EventCx<'_>,
id: Id,
f: F,
) -> IsUsed
pub fn on_click<F: FnOnce(&mut EventCx<'_>)>( self, cx: &mut EventCx<'_>, id: Id, f: F, ) -> IsUsed
Call f on “click” or any “activation” event
This is a convenience method which calls f on any of the following:
- Mouse click and release on the same widget
- Touchscreen press and release on the same widget
Event::Command(cmd, _)wherecmd.is_activate()
This method has some side effects:
Event::PressStartis grabbed usingGrabMode::ClickEvent::Commandwith a key will causeidto be depressed until that key is released (seeEventCx::depress_with_key).
Sourcepub fn pass_when_disabled(&self) -> bool
pub fn pass_when_disabled(&self) -> bool
Pass to disabled widgets?
When a widget is disabled:
- New input events (
Command,PressStart,Scroll) are not passed - Continuing input actions (
PressMove,PressEnd) are passed (or the input sequence may be terminated). - New focus notifications are not passed
- Focus-loss notifications are passed
- Requested events like
Timerare passed
Sourcepub fn is_reusable(&self) -> bool
pub fn is_reusable(&self) -> bool
Can the event be received by Events::handle_event during unwinding?
Some events are sent to the widget with navigation focus (e.g.
Event::Command). Others are sent to the widget under the mouse (e.g.
Event::PressStart). All these events may be “reused” by an ancestor
widget if not Used by the original target.
Other events are sent to a specific widget as a result of a request
(e.g. Event::Key, Event::PressEnd), or as a notification of
focus change (e.g. Event::LostKeyFocus). These events may never be
“reused”.
Note: this could alternatively be seen as a property of the addressing
mechanism, currently just an Id.
Trait Implementations§
Source§impl<'a> AddAssign<Offset> for Event<'a>
impl<'a> AddAssign<Offset> for Event<'a>
Source§fn add_assign(&mut self, offset: Offset)
fn add_assign(&mut self, offset: Offset)
+= operation. Read moreimpl<'a> StructuralPartialEq for Event<'a>
Auto Trait Implementations§
impl<'a> Freeze for Event<'a>
impl<'a> RefUnwindSafe for Event<'a>
impl<'a> !Send for Event<'a>
impl<'a> !Sync for Event<'a>
impl<'a> Unpin for Event<'a>
impl<'a> UnwindSafe for Event<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.