pub struct TextField {
pub read_only: bool,
pub select_all_on_focus: bool,
pub password_mode: bool,
pub placeholder: String,
pub padding: f64,
pub theme: TextFieldTheme,
/* private fields */
}Expand description
Single-line editable text field.
Fields§
§read_only: bool§select_all_on_focus: bool§password_mode: boolWhen true, every character is displayed as ‘•’ (U+2022).
The actual text is stored and edited normally; only the render is masked.
placeholder: String§padding: f64§theme: TextFieldThemePer-widget colour overrides — None colours fall back to
the ambient visuals() palette. Set via [with_theme].
Implementations§
Source§impl TextField
impl TextField
Sourcepub fn with_text_cell(self, cell: Rc<RefCell<String>>) -> Self
pub fn with_text_cell(self, cell: Rc<RefCell<String>>) -> Self
Bind the field to external text state.
layout picks up external writes (e.g. a Clear button) and
on_change writes user edits back into the cell.
Source§impl TextField
impl TextField
Sourcepub fn with_char_filter(self, filter: impl Fn(char) -> bool + 'static) -> Self
pub fn with_char_filter(self, filter: impl Fn(char) -> bool + 'static) -> Self
Install a per-character allow-list. Any character for which
filter returns false is silently dropped from
insertions — both single-character typing and multi-character
paste. The text already in the field at install time is left
alone.
Common patterns:
- decimal digits:
|c| c.is_ascii_digit() - hex seed with
0xprefix:|c| c.is_ascii_hexdigit() || c == 'x' || c == 'X' - single-line:
|c| c != '\n' && c != '\r'
Source§impl TextField
impl TextField
Sourcepub fn with_focus_id(self, id: FocusId) -> Self
pub fn with_focus_id(self, id: FocusId) -> Self
Assign a stable id for the programmatic focus channel. App code can
then call crate::focus::request_focus(id)
to move keyboard focus here (and raise the on-screen keyboard) the
next frame — e.g. to auto-focus a search field when its overlay opens.
Sourcepub fn with_keyboard_mode(self, mode: KeyboardInputMode) -> Self
pub fn with_keyboard_mode(self, mode: KeyboardInputMode) -> Self
Set the preferred keyboard input mode for this field — picks
which layer the on-screen software keyboard slides up into the
next time this field gains focus. Defaults to
KeyboardInputMode::Text.
This does not install a character filter: a numeric field
still accepts whatever the user actually types (including via
a paste or the on-screen ABC mode switch). Combine with
TextField::with_char_filter when you want hard validation.
Sourcepub fn with_keyboard_mode_cell(self, cell: Rc<Cell<KeyboardInputMode>>) -> Self
pub fn with_keyboard_mode_cell(self, cell: Rc<Cell<KeyboardInputMode>>) -> Self
Bind the field’s keyboard mode to an externally-owned cell.
The caller keeps a clone and can flip the mode at any time —
the next focus event re-queries the cell, so the keyboard
re-targets without a widget rebuild. Mirrors the
TextField::with_text_cell pattern.
Sourcepub fn keyboard_mode(&self) -> KeyboardInputMode
pub fn keyboard_mode(&self) -> KeyboardInputMode
Read the current mode. Used by the Widget::text_input_mode
override and exposed publicly so app code can inspect it
without going through a dyn Widget trait dispatch.
Sourcepub fn set_keyboard_mode(&self, mode: KeyboardInputMode)
pub fn set_keyboard_mode(&self, mode: KeyboardInputMode)
Update the mode at runtime — typically called from a callback
(e.g. a radio button’s on_change). Equivalent to mutating
the cell directly via TextField::keyboard_mode_handle but
reads better at the call site.
Sourcepub fn keyboard_mode_handle(&self) -> Rc<Cell<KeyboardInputMode>>
pub fn keyboard_mode_handle(&self) -> Rc<Cell<KeyboardInputMode>>
Clone the underlying cell so a parent can drive this field’s mode from somewhere else in the tree (a radio button, a menu item, a feature-flag observer). Multiple fields can share the same handle to ride a single switch.
Source§impl TextField
impl TextField
pub fn with_margin(self, m: Insets) -> Self
pub fn with_h_anchor(self, h: HAnchor) -> Self
pub fn with_v_anchor(self, v: VAnchor) -> Self
pub fn with_min_size(self, s: Size) -> Self
pub fn with_max_size(self, s: Size) -> Self
Source§impl TextField
impl TextField
Sourcepub fn with_theme(self, theme: TextFieldTheme) -> Self
pub fn with_theme(self, theme: TextFieldTheme) -> Self
Install a TextFieldTheme of per-widget colour overrides.
Any field set to None on the theme falls back to the
ambient visuals() palette, so callers can override just
what they need (e.g. background + border for a dark-panel
field that keeps the default selection / cursor highlights).
Source§impl TextField
impl TextField
pub fn new(font: Arc<Font>) -> Self
pub fn with_font_size(self, s: f64) -> Self
pub fn with_padding(self, p: f64) -> Self
pub fn with_read_only(self, v: bool) -> Self
pub fn with_select_all_on_focus(self, v: bool) -> Self
pub fn with_password_mode(self, v: bool) -> Self
pub fn with_placeholder(self, s: impl Into<String>) -> Self
pub fn with_text(self, s: impl Into<String>) -> Self
pub fn on_change(self, cb: impl FnMut(&str) + 'static) -> Self
pub fn on_enter(self, cb: impl FnMut(&str) + 'static) -> Self
pub fn on_edit_complete(self, cb: impl FnMut(&str) + 'static) -> Self
pub fn text(&self) -> String
pub fn cursor_pos(&self) -> usize
pub fn selection(&self) -> String
pub fn set_text(&mut self, s: impl Into<String>)
Trait Implementations§
Source§impl Widget for TextField
impl Widget for TextField
Source§fn set_label_text(&mut self, text: &str)
fn set_label_text(&mut self, text: &str)
Composite parents (e.g. ColorWheelPicker) use this to push a live
value into the field without bypassing set_text’s cell sync and
cache invalidation. Skipped while the field is focused so the user
isn’t fighting the parent for cursor position mid-edit; the parent
is expected to read back via TextField::text after focus is
released to pick up any user-typed value.
Source§fn needs_draw(&self) -> bool
fn needs_draw(&self) -> bool
While focused, the cursor blinks at 500 ms half-period. The field
itself drives its own repaint cadence: [needs_draw] reports dirty
whenever wall-clock time has crossed a flip boundary since the last
paint, and [next_draw_deadline] returns the exact wall-clock
instant of the next boundary so the host can WaitUntil it.
Losing focus makes both return None / false, and the tree walk’s
visibility check drops the field entirely when its enclosing window
is closed / collapsed / tab not selected — so an invisible focused
field does NOT keep the loop awake.
Source§fn paint_overlay(&mut self, ctx: &mut dyn DrawCtx)
fn paint_overlay(&mut self, ctx: &mut dyn DrawCtx)
Cursor overlay — runs AFTER the cache blit on every frame, so
blink-phase flips don’t invalidate the backbuffer. Reads the
same edit state paint() does so cursor lands on the glyph the
cached text shows.
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Source§fn set_bounds(&mut self, b: Rect)
fn set_bounds(&mut self, b: Rect)
Source§fn children_mut(&mut self) -> &mut Vec<Box<dyn Widget>>
fn children_mut(&mut self) -> &mut Vec<Box<dyn Widget>>
Source§fn is_focusable(&self) -> bool
fn is_focusable(&self) -> bool
Source§fn focus_id(&self) -> Option<FocusId>
fn focus_id(&self) -> Option<FocusId>
crate::focus::request_focus). Read moreSource§fn accepts_text_input(&self) -> bool
fn accepts_text_input(&self) -> bool
true when this widget accepts free-form character input (typing
arbitrary letters, numbers, punctuation). Used by the on-screen
software keyboard (crate::widgets::on_screen_keyboard) to decide
whether to slide up when this widget gains focus. Read moreSource§fn text_input_value(&self) -> Option<String>
fn text_input_value(&self) -> Option<String>
., !, ?, newline) opens the keyboard with Shift
active. Read moreSource§fn text_input_mode(&self) -> KeyboardInputMode
fn text_input_mode(&self) -> KeyboardInputMode
KeyboardInputMode::Text;
numeric fields override to
Numeric
so the digit pad slides up instead of the letter row. Read moreSource§fn next_draw_deadline(&self) -> Option<Instant>
fn next_draw_deadline(&self) -> Option<Instant>
None = no scheduled wake.
The host loop turns a Some(t) into ControlFlow::WaitUntil(t) so
e.g. a cursor blink fires without continuous polling. Read moreSource§fn widget_base(&self) -> Option<&WidgetBase>
fn widget_base(&self) -> Option<&WidgetBase>
WidgetBase. Read moreSource§fn widget_base_mut(&mut self) -> Option<&mut WidgetBase>
fn widget_base_mut(&mut self) -> Option<&mut WidgetBase>
widget_base. Read moreSource§fn h_anchor(&self) -> HAnchor
fn h_anchor(&self) -> HAnchor
HAnchor::FIT (take natural content width).Source§fn v_anchor(&self) -> VAnchor
fn v_anchor(&self) -> VAnchor
VAnchor::FIT (take natural content height).Source§fn backbuffer_cache_mut(&mut self) -> Option<&mut BackbufferCache>
fn backbuffer_cache_mut(&mut self) -> Option<&mut BackbufferCache>
Source§fn backbuffer_mode(&self) -> BackbufferMode
fn backbuffer_mode(&self) -> BackbufferMode
backbuffer_cache_mut] returns Some. Default
BackbufferMode::Rgba — correct for any widget.
Opt into BackbufferMode::LcdCoverage only when the widget
paints opaque content covering its full bounds.Source§fn layout(&mut self, available: Size) -> Size
fn layout(&mut self, available: Size) -> Size
Source§fn paint(&mut self, ctx: &mut dyn DrawCtx)
fn paint(&mut self, ctx: &mut dyn DrawCtx)
ctx. Read moreSource§fn on_event(&mut self, event: &Event) -> EventResult
fn on_event(&mut self, event: &Event) -> EventResult
EventResult::Consumed to stop bubbling. Read moreSource§fn hit_test(&self, local_pos: Point) -> bool
fn hit_test(&self, local_pos: Point) -> bool
true if local_pos (in this widget’s local coordinates) falls
inside this widget’s interactive area. Default: axis-aligned rect test.Source§fn claims_pointer_exclusively(&self, _local_pos: Point) -> bool
fn claims_pointer_exclusively(&self, _local_pos: Point) -> bool
true, hit_test_subtree stops recursing into this widget’s
children and returns this widget as the hit target. Used for floating
overlays (e.g. a scrollbar painted above its content) that must claim
the pointer before children that happen to share the same pixels.
Default: false.Source§fn hit_test_global_overlay(&self, _local_pos: Point) -> bool
fn hit_test_global_overlay(&self, _local_pos: Point) -> bool
local_pos hits an app-level overlay owned by this
widget. Unlike normal hit testing, ancestors may be missed because the
overlay is painted outside their bounds.Source§fn has_active_modal(&self) -> bool
fn has_active_modal(&self) -> bool
Source§fn on_unconsumed_key(
&mut self,
_key: &Key,
_modifiers: Modifiers,
) -> EventResult
fn on_unconsumed_key( &mut self, _key: &Key, _modifiers: Modifiers, ) -> EventResult
Source§fn id(&self) -> Option<&str>
fn id(&self) -> Option<&str>
Source§fn is_visible(&self) -> bool
fn is_visible(&self) -> bool
false to suppress painting this widget and all its children.
The widget’s own paint() will not be called. Default: true.Source§fn properties(&self) -> Vec<(&'static str, String)>
fn properties(&self) -> Vec<(&'static str, String)>
Source§fn try_scroll_to_lift(&mut self, _amount: f64) -> f64
fn try_scroll_to_lift(&mut self, _amount: f64) -> f64
amount
pixels. Used by the on-screen-keyboard auto-scroll so a
focused text field doesn’t end up hidden behind the keyboard
panel: the App walks UP the focus path and asks each ancestor
to absorb some of the deficit. Read moreSource§fn set_label_color(&mut self, _color: Color)
fn set_label_color(&mut self, _color: Color)
Label), update its foreground
colour. Default is a no-op. Composite widgets call this on their
children to retint labels without rebuilding them — used by Button
when toggling between active (white text on accent) and inactive
(theme text on subtle bg) appearances.Source§fn as_reflect(&self) -> Option<&dyn Reflect>
fn as_reflect(&self) -> Option<&dyn Reflect>
Source§fn as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
fn as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
as_reflect. Used by the
inspector to write edits back into the live widget.Source§fn has_backbuffer(&self) -> bool
fn has_backbuffer(&self) -> bool
Source§fn compositing_layer(&mut self) -> Option<CompositingLayer>
fn compositing_layer(&mut self) -> Option<CompositingLayer>
Source§fn backbuffer_spec(&mut self) -> BackbufferSpec
fn backbuffer_spec(&mut self) -> BackbufferSpec
Source§fn backbuffer_state_mut(&mut self) -> Option<&mut BackbufferState>
fn backbuffer_state_mut(&mut self) -> Option<&mut BackbufferState>
BackbufferSpec other than BackbufferKind::None.Source§fn mark_dirty(&mut self)
fn mark_dirty(&mut self)
Source§fn contributes_children_to_inspector(&self) -> bool
fn contributes_children_to_inspector(&self) -> bool
Source§fn show_in_inspector(&self) -> bool
fn show_in_inspector(&self) -> bool
false to hide this widget (and its subtree) from the inspector
node snapshot entirely. Intended for zero-size utility widgets such
as layout-time watchers / tickers / invisible composers — they bloat
the inspector tree without providing user-relevant information and,
at scale, can make the inspector’s per-frame tree rebuild expensive.Source§fn lcd_preference(&self) -> Option<bool>
fn lcd_preference(&self) -> Option<bool>
Source§fn finish_paint(&mut self, _ctx: &mut dyn DrawCtx)
fn finish_paint(&mut self, _ctx: &mut dyn DrawCtx)
paint, child painting, and optional overlay painting. Read moreSource§fn paint_global_overlay(&mut self, _ctx: &mut dyn DrawCtx)
fn paint_global_overlay(&mut self, _ctx: &mut dyn DrawCtx)
Source§fn clip_children_rect(&self) -> Option<(f64, f64, f64, f64)>
fn clip_children_rect(&self) -> Option<(f64, f64, f64, f64)>
paint_subtree applies this clip before recursing into
children, then restores the previous clip state afterward. The clip does
not affect paint_overlay, which runs after the clip is removed. Read moreSource§fn inspector_child_transform(&self) -> TransAffine
fn inspector_child_transform(&self) -> TransAffine
paint() does — e.g. a widget
that pushes pan/zoom in paint() and pops it in finish_paint()
makes the framework recurse into its children with pan/zoom active,
so collect_inspector_nodes must apply the same transform when
accumulating descendant screen bounds. Without this hook the
inspector hover overlay lands at the un-transformed canvas position
when the widget sits inside a panning/zooming container. Read moreSource§fn padding(&self) -> Insets
fn padding(&self) -> Insets
Insets::ZERO. Read moreSource§fn enforce_integer_bounds(&self) -> bool
fn enforce_integer_bounds(&self) -> bool
paint_subtree should snap this widget’s incoming
translation to the physical pixel grid. Read moreSource§fn measure_min_height(&self, _available_w: f64) -> f64
fn measure_min_height(&self, _available_w: f64) -> f64
available_w for width. Read moreSource§fn take_raise_request(&mut self) -> bool
fn take_raise_request(&mut self) -> bool
crate::widgets::Stack) call this on each
child at the start of layout(). A widget that returns true is
moved to the END of its parent’s child list — painted last, i.e.
raised to the top of the z-order. take_ semantics: the call is
also expected to clear the request so the child doesn’t keep
getting raised every frame. Read moreAuto Trait Implementations§
impl !Freeze for TextField
impl !RefUnwindSafe for TextField
impl !Send for TextField
impl !Sync for TextField
impl !UnwindSafe for TextField
impl Unpin for TextField
impl UnsafeUnpin for TextField
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> 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>, which can then be
downcast into Box<dyn 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>, which 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> 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