Skip to main content

TextInput

Struct TextInput 

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

Implementations§

Source§

impl TextInput

Source

pub fn new() -> Self

Source

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

Source

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.

Source

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.

Source

pub fn value(self, v: impl Into<String>) -> Self

Source

pub fn placeholder(self, p: impl Into<String>) -> Self

Source

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.

Source

pub fn obscure(self) -> Self

Source

pub fn width(self, w: f32) -> Self

Source

pub fn height(self, h: f32) -> Self

Source

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

Source

pub fn border(self, c: Color) -> Self

Unfocused border color.

Source

pub fn focus_color(self, c: Color) -> Self

Focused border color (also thickens slightly, unchanged).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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 Default for TextInput

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Widget for TextInput

Source§

fn layout(&self, ctx: &LayoutCtx<'_>) -> Size

Measure under ctx.constraints and return a size within them. Read more
Source§

fn paint(&self, ctx: &mut PaintCtx<'_>)

Record draw commands for ctx.rect. Read more
Source§

fn children(&self) -> Children<'_>

Declare this widget’s children. Drives every default below.
Source§

fn flex_factor(&self) -> f32

Flex weight inside Row/Column. Wrappers are transparent by default.
Source§

fn into_element(self) -> Element
where Self: Sized + 'static,

Wrap this widget in an Element so it can be returned from Component::build().

Auto Trait Implementations§

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<W> FocusApi for W
where W: Widget + Send + Sync + 'static,

Source§

fn focus_node(self, node: FocusNode) -> WithFocus<Self>

Attach a focus node. This enables focus-ring rendering and explicit neighbor wiring.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<W> HeroApi for W
where W: Widget + Send + Sync + 'static,

Source§

fn hero_tag(self, tag: impl Into<String>) -> Hero<Self>

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<W> OverlayApi for W
where W: Widget + Send + Sync + 'static,

Source§

fn dropdown( self, open: Atom<bool>, content: impl Fn() -> BoxedWidget + Send + Sync + 'static, ) -> WithOverlay<Self>

Source§

fn sheet( self, open: Atom<bool>, content: impl Fn() -> BoxedWidget + Send + Sync + 'static, ) -> WithOverlay<Self>

Source§

fn dialog( self, open: Atom<bool>, content: impl Fn() -> BoxedWidget + Send + Sync + 'static, ) -> WithOverlay<Self>

Source§

fn rich_tooltip( self, content: impl Fn() -> BoxedWidget + Send + Sync + 'static, ) -> WithOverlay<Self>

Source§

fn toast( self, open: Atom<bool>, content: impl Fn() -> BoxedWidget + Send + Sync + 'static, ) -> WithOverlay<Self>

Source§

impl<W> PressApi for W
where W: Widget + Send + Sync + 'static,

Source§

fn on_press(self, f: impl Fn() + Send + Sync + 'static) -> Pressable<Self>

Source§

fn on_long_press( self, f: impl Fn() + Send + Sync + 'static, ) -> LongPressable<Self>

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.
Source§

impl<W> WidgetExt for W
where W: Widget + 'static,

Source§

fn tooltip(self, label: impl Into<String>) -> Tooltip

Show label while the pointer hovers this widget.