pub struct TextInput {
pub value: String,
pub placeholder: String,
pub focused: bool,
pub obscure: bool,
pub width: Option<f32>,
pub height: f32,
pub font_size: Option<f32>,
pub radius: f32,
/* private fields */
}Expand description
A single-line text input field.
Real keyboard editing (D112/Phase 28 Step 1): click to focus, type,
arrow-key navigation, Shift+arrow selection, Home/End, Cmd/Ctrl+A
select-all, Cmd/Ctrl+C/X/V clipboard — all dispatched by the engine
against this widget’s persistent render-tree node
(PaintCtx::register_editable/text_edit), not by this paint(&self)
call itself (which can’t mutate anything). This widget stays a
CONTROLLED component, the same convention Slider/Switch/Checkbox
already use: the app owns the true String (typically a ctx.state
atom), passes it in via .value(), and gets edits back via
.on_change(). What this widget’s own render-tree node persists is
only the ephemeral editing chrome (caret position, selection).
Fields§
§value: String§placeholder: String§focused: bool§obscure: bool§width: Option<f32>§height: f32§font_size: Option<f32>None = read from the active theme’s typography.body_medium
(D127 “environment” track — see Checkbox::resolved_font_size’s doc
for the reasoning).
radius: f32Implementations§
Source§impl TextInput
impl TextInput
pub fn new() -> Self
Sourcepub fn leading(self, w: impl Widget + 'static) -> Self
pub fn leading(self, w: impl Widget + 'static) -> Self
An adornment INSIDE the field, at the left (a search/prefix icon, $, …).
Rendered inside the box; the text insets past it. This is what makes a
SearchBar just a TextInput — .leading(Icon::new(Search)).
Sourcepub fn trailing(self, w: impl Widget + 'static) -> Self
pub fn trailing(self, w: impl Widget + 'static) -> Self
An adornment INSIDE the field, at the right (clear ×, password eye,
validation status, unit suffix…). Make it tappable with .on_trailing.
Sourcepub fn on_trailing(self, f: impl Fn() + Send + Sync + 'static) -> Self
pub fn on_trailing(self, f: impl Fn() + Send + Sync + 'static) -> Self
Tap handler for the trailing adornment (e.g. clear the field, toggle password visibility). The trailing zone owns its own hit region.
pub fn value(self, v: impl Into<String>) -> Self
pub fn placeholder(self, p: impl Into<String>) -> Self
Sourcepub fn focused(self) -> Self
pub fn focused(self) -> Self
Seed this input as focused on its FIRST paint only (a one-shot
request, not a per-frame re-request — see PaintCtx::focus_node_seeded).
Real, persistent focus state now lives on this widget’s own
rosace_a11y::FocusNode (auto-created, zero wiring required),
driven by click/Tab from then on.
pub fn obscure(self) -> Self
pub fn width(self, w: f32) -> Self
pub fn height(self, h: f32) -> Self
Sourcepub fn background(self, c: Color) -> Self
pub fn background(self, c: Color) -> Self
Box fill color (a fixed dark tone if unset — kept as the long-standing default rather than switched to a theme token, since that would visibly shift every existing app using this widget).
Sourcepub fn focus_color(self, c: Color) -> Self
pub fn focus_color(self, c: Color) -> Self
Focused border color (also thickens slightly, unchanged).
Sourcepub fn on_change(self, f: impl Fn(String) + Send + Sync + 'static) -> Self
pub fn on_change(self, f: impl Fn(String) + Send + Sync + 'static) -> Self
Report edits — called by the engine’s key/click dispatch whenever
this input’s value actually changes (typing, paste, cut). Without
this, the input still accepts keystrokes/selection/caret movement
(all real, all repainted) but the displayed value never advances,
same “controlled with no listener does nothing” behavior as
Slider/Switch today.
Sourcepub fn controller(self, c: EditController) -> Self
pub fn controller(self, c: EditController) -> Self
Attach a programmatic EditController (D116) — app-constructed
and passed in (the FocusNode precedent), reachable from OUTSIDE
the widget tree entirely (a toolbar button’s on_press has no
access to this field’s render-tree node otherwise). Optional: most
fields never need one.
Sourcepub fn spans(
self,
f: impl Fn(&str, Option<(usize, usize)>) -> Vec<Span> + Send + Sync + 'static,
) -> Self
pub fn spans( self, f: impl Fn(&str, Option<(usize, usize)>) -> Vec<Span> + Send + Sync + 'static, ) -> Self
The markdown/syntax-highlighting seam (D116 Step 5): a tokenizer
that inspects the current value (and, when available, the char
range that changed since the last call — None on the first call)
and returns styled super::text_edit::Spans. Never applied to
an obscured (password) field. This crate never learns what
markdown is — the app brings the tokenizer.
Sourcepub fn cursor_style(self, s: CursorStyle) -> Self
pub fn cursor_style(self, s: CursorStyle) -> Self
Per-field caret override — width/color/corner radius/blink rate/
shape (Bar/Block/Underline/Custom). Falls back to the
theme’s CursorStyle extension (ThemeData::ext/with_ext, D105)
if set, then to CursorStyle::default.
Sourcepub fn keyboard_type(self, kt: KeyboardType) -> Self
pub fn keyboard_type(self, kt: KeyboardType) -> Self
Which OS soft-keyboard layout a mobile host should show while this
field is focused (D116 Step 6) — Email/Numeric/Url/Phone.
Pure data on desktop (no hardware keyboard has “layouts” to pick);
real effect is a mobile-host FFI concern (rosace_core::keyboard_type(),
polled the same way camera permission is).
Sourcepub fn field(self, f: FormField) -> Self
pub fn field(self, f: FormField) -> Self
Bind this field to a rosace_forms::FormField (D116 Phase 28
Step 8) — the primary way to wire form validation. Sets the
widget’s initial value from f.get() and installs an on_change
that writes back into the field (f.set(v)) AND immediately
re-validates (f.validate()), so an inline error caption below
the field and a submit button’s .disabled_if(!form.is_valid())
both update live as the user types — not just on submit. Calling
.on_change() again AFTER .field() overrides this binding;
call .field() last if you need both.
Sourcepub fn filters(self, filters: Vec<InputFilter>) -> Self
pub fn filters(self, filters: Vec<InputFilter>) -> Self
Input filters (D116 Step 8) — applied to every edit (typed chars,
paste, IME commit, controller ops) before it reaches on_change.
See super::text_edit::InputFilter.
Trait Implementations§
Source§impl Widget for TextInput
impl Widget for TextInput
Source§fn layout(&self, ctx: &LayoutCtx<'_>) -> Size
fn layout(&self, ctx: &LayoutCtx<'_>) -> Size
ctx.constraints and return a size within them. Read more