ltk::core

Enum WidgetHandlers

Source
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_press: Option<Msg>
§on_long_press: Option<Msg>
§on_drag_start: Option<Msg>
§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.

§repeating: bool
§

Toggle

Fields

§on_toggle: Option<Msg>
§value: bool
§

Checkbox

Fields

§on_toggle: Option<Msg>
§value: bool
§

Radio

Fields

§on_select: Option<Msg>
§selected: bool
§

ListItem

Fields

§on_press: Option<Msg>
§

WindowButton

Fields

§on_press: Option<Msg>
§

TextEdit

Fields

§value: String
§on_change: Option<Arc<dyn Fn(String) -> Msg>>
§on_submit: Option<Msg>
§secure: bool

true 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: bool

true 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: TextAlign

Horizontal 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: f32

Font 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: bool

true 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

Fields

§on_change: Option<Arc<dyn Fn(f32) -> Msg>>
§value: f32

Implementations§

Source§

impl<Msg: Clone> WidgetHandlers<Msg>

Source

pub fn is_text_input(&self) -> bool

Source

pub fn is_disabled(&self) -> bool

Source

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.

Source

pub fn is_slider(&self) -> bool

Source

pub fn is_navigable_list_item(&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.

Source

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.

Source

pub fn submit_msg(&self) -> Option<Msg>

Submit message (Enter on a focused TextEdit). None for every other variant.

Source

pub fn text_change_msg(&self, new_value: &str) -> Option<Msg>

Build the on_change message for a TextEdit given the new value.

Source

pub fn slider_change_msg(&self, value: f32) -> Option<Msg>

Build the on_change message for a Slider given a value in [0,1].

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Msg: Clone> Drop for WidgetHandlers<Msg>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more