#[non_exhaustive]pub enum Event<'a> {
Show 20 variants
Command(Command, Option<PhysicalKey>),
Key(&'a KeyEvent, bool),
ImePreedit(&'a str, Option<(usize, usize)>),
ImeCommit(&'a str),
Scroll(ScrollDelta),
Pan(Affine),
CursorMove {
press: Press,
},
PressStart(PressStart),
PressMove {
press: Press,
delta: Vec2,
},
PressEnd {
press: Press,
success: bool,
},
Timer(TimerHandle),
NavFocus(FocusSource),
LostNavFocus,
SelFocus(FocusSource),
LostSelFocus,
KeyFocus,
LostKeyFocus,
ImeFocus,
LostImeFocus,
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 EventState::depress_with_key
.
If a widget has keyboard input focus (see
EventState::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 character focus (see
EventState::request_key_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.
ImePreedit(&'a str, Option<(usize, usize)>)
Input Method Editor: composed text changed
Parameters are text, cursor
.
This is only received after
requesting key focus with some ime
purpose.
ImeCommit(&'a str)
Input Method Editor: composed text committed
Parameters are text
.
This is only received after
requesting key focus with some ime
purpose.
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
.
CursorMove
Movement of mouse cursor 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 cursor.
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::Layout::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::Layout::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 EventState::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
EventState::request_sel_focus
or EventState::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
EventState::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
ImeFocus
Notification that a widget has gained IME focus
The widget should call EventState::set_ime_cursor_area
immediately
and each time the area changes (relative to the widget’s coordinate
space), until Event::LostImeFocus
is received. Failure to do so will
result in the widget’s entire rect
being used as the IME cursor area.
LostImeFocus
Notification that a widget has lost IME 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::PressStart
is grabbed usingGrabMode::Click
Event::Command
with a key will causeid
to be depressed until that key is released (seeEventState::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
Timer
are 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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more