pub enum WidgetHandlers<Msg: Clone> {
None,
Button {
on_press: Option<Msg>,
on_long_press: Option<Msg>,
on_drag_start: Option<Msg>,
on_escape: Option<Msg>,
repeating: bool,
},
Toggle {
on_toggle: Option<Msg>,
value: bool,
},
Checkbox {
on_toggle: Option<Msg>,
value: bool,
},
Radio {
on_select: Option<Msg>,
selected: bool,
},
ListItem {
on_press: Option<Msg>,
},
WindowButton {
on_press: Option<Msg>,
},
TextEdit {
value: String,
on_change: Option<Arc<dyn Fn(String) -> Msg>>,
on_submit: Option<Msg>,
secure: bool,
multiline: bool,
align: TextAlign,
font_size: f32,
select_on_focus: bool,
password_toggle_msg: Option<Msg>,
},
Slider {
on_change: Option<Arc<dyn Fn(f32) -> Msg>>,
axis: SliderAxis,
value: f32,
},
}Expand description
Per-leaf interaction snapshot captured during layout. One variant per
interactive widget kind; the layout pass clones the relevant callbacks /
values from the Element tree into here so input handlers can dispatch
in O(1) without re-walking the tree.
None is used for focusable widgets that emit no message (e.g. a disabled
button or a focusable container) — the entry still appears in
widget_rects for hit testing and focus traversal.
Variants§
None
Button
Fields
on_escape: Option<Msg>Keyboard Escape-key message — the runtime scans every laid-out
Button snapshot in reverse and fires the first non-None
on_escape it finds before the default ESC fallthrough chain.
Currently sourced from
crate::widget::pressable::Pressable::on_escape; native
crate::widget::button::Button always sets this to None.
Toggle
Checkbox
Radio
ListItem
WindowButton
TextEdit
Fields
secure: booltrue when the source TextEdit was built with
.secure( true ). Propagates the wipe-on-drop behaviour to
every per-frame handler snapshot so credential text does not
linger across multiple cloned WidgetHandlers allocations.
multiline: booltrue when the source TextEdit was built with
.multiline( true ). The keyboard dispatch reads this so
pressing Enter inserts a \n instead of firing
Self::submit_msg. Mutually exclusive with secure.
align: TextAlignHorizontal alignment snapshot — needed by the runtime’s hit-testing path so a click on a centred / right-aligned field lands on the correct glyph.
font_size: f32Font size snapshot — needed by the hit-testing path so
the runtime measures glyphs at the same size the renderer
drew them. Always the default theme::FONT_SIZE for
fields that do not call .font_size( … ).
select_on_focus: booltrue when the source field opted into select-all-on-
focus. The runtime reads this in set_focus to decide
whether the new selection should anchor at 0 (replace
on next keystroke) or at the cursor (insert).
password_toggle_msg: Option<Msg>Snapshot of the
crate::widget::text_edit::TextEdit::password_toggle
callback. When Some, pointer / touch dispatch checks
the eye-icon hit zone (via
crate::widget::text_edit::password_toggle_hit_zone)
before falling through to cursor placement and fires
this message instead.
Slider
Implementations§
Source§impl<Msg: Clone> WidgetHandlers<Msg>
impl<Msg: Clone> WidgetHandlers<Msg>
pub fn is_text_input(&self) -> bool
pub fn is_disabled(&self) -> bool
Sourcepub fn is_multiline_text_input(&self) -> bool
pub fn is_multiline_text_input(&self) -> bool
true when this is a WidgetHandlers::TextEdit whose source
widget was built with .multiline( true ). The keyboard
dispatch reads this so pressing Enter inserts a \n instead of
submitting.
pub fn is_slider(&self) -> bool
true when this widget is a row inside a scrollable list that
keyboard arrow navigation should treat as a stepping point.
Currently restricted to ListItem; buttons,
toggles, sliders, etc. are not stepped over by Arrow Up/Down so
they do not interfere with the row-by-row navigation pattern in
combo popups, settings menus and similar lists.
Sourcepub fn press_msg(&self) -> Option<Msg>
pub fn press_msg(&self) -> Option<Msg>
Convenience: extract the press / activation message for the variants
that have one (Button, Toggle, Checkbox, Radio, ListItem). Returns
None for sliders / text edits / None / disabled widgets.
Sourcepub fn submit_msg(&self) -> Option<Msg>
pub fn submit_msg(&self) -> Option<Msg>
Submit message (Enter on a focused TextEdit). None for every other
variant.
Sourcepub fn text_change_msg(&self, new_value: &str) -> Option<Msg>
pub fn text_change_msg(&self, new_value: &str) -> Option<Msg>
Build the on_change message for a TextEdit given the new value.
Sourcepub fn slider_change_msg(&self, value: f32) -> Option<Msg>
pub fn slider_change_msg(&self, value: f32) -> Option<Msg>
Build the on_change message for a Slider given a value in [0,1].
Sourcepub fn slider_value_from_pos(&self, rect: Rect, pos: Point) -> f32
pub fn slider_value_from_pos(&self, rect: Rect, pos: Point) -> f32
Compute the [0.0, 1.0] value for the slider this handler belongs to,
given a pointer position inside its layout rect. Dispatches on the
stored slider::SliderAxis so the same call site in input.rs drives
both horizontal Slider and vertical
VSlider.
Returns 0.0 for non-slider variants — callers combine this with
Self::slider_change_msg, which also gates on the variant, so the
zero is never consumed in practice.
Sourcepub fn is_repeating(&self) -> bool
pub fn is_repeating(&self) -> bool
true when this is a WidgetHandlers::Button whose source
widget opted into press-and-hold repeat. The runtime reads
this on press to decide whether to fire press_msg
immediately + arm a calloop repeat timer, and on release to
suppress the regular tap-on-release fire.
Sourcepub fn long_press_msg(&self) -> Option<Msg>
pub fn long_press_msg(&self) -> Option<Msg>
Long-press / right-click message for this widget, or None if
none configured. Currently only WidgetHandlers::Button
carries one. Firing this does not by itself put the press into
drag mode — see Self::drag_start_msg for that.
Sourcepub fn drag_start_msg(&self) -> Option<Msg>
pub fn drag_start_msg(&self) -> Option<Msg>
Drag-arm message for this widget, or None if none configured.
Fired by the touch hold-timer alongside long_press_msg, and
by mouse left-button motion past the drag-promotion threshold
(without firing the menu). Promotes the gesture into drag mode.
Sourcepub fn escape_msg(&self) -> Option<Msg>
pub fn escape_msg(&self) -> Option<Msg>
Keyboard Escape message for this widget, or None if none
configured. Used by the keyboard ESC handler to scan
widget_rects for a crate::widget::dialog::Dialog (or other
Pressable::on_escape-bearing wrapper) and fire its cancel
message before the default ESC fallthrough chain.
Sourcepub fn current_value(&self) -> Option<&str>
pub fn current_value(&self) -> Option<&str>
Current text-edit value (for cursor placement on focus, backspace
rebuild, etc.). None for non-text-edit variants.
Trait Implementations§
Source§impl<Msg: Clone> Clone for WidgetHandlers<Msg>
impl<Msg: Clone> Clone for WidgetHandlers<Msg>
Source§impl<Msg: Clone> Drop for WidgetHandlers<Msg>
impl<Msg: Clone> Drop for WidgetHandlers<Msg>
Source§fn drop(&mut self)
fn drop(&mut self)
Mirror the wipe-on-drop behaviour of super::text_edit::TextEdit for the
per-frame handler snapshots the runtime keeps. When the snapshot
was built from a secure text edit we scrub the value bytes here so
the heap allocation that backs the cloned String is overwritten
before it is returned to the allocator. Non-secure variants run an
inert path; the field-level drops that fire after this fn handle
the rest of the data.
Auto Trait Implementations§
impl<Msg> Freeze for WidgetHandlers<Msg>where
Msg: Freeze,
impl<Msg> !RefUnwindSafe for WidgetHandlers<Msg>
impl<Msg> !Send for WidgetHandlers<Msg>
impl<Msg> !Sync for WidgetHandlers<Msg>
impl<Msg> Unpin for WidgetHandlers<Msg>where
Msg: Unpin,
impl<Msg> !UnwindSafe for WidgetHandlers<Msg>
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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