Skip to main content

Input

Struct Input 

Source
pub struct Input { /* private fields */ }
Expand description

A text input widget with cursor, selection, clipboard, and undo/redo support

All cursor positions are character-based (not byte-based) to properly handle UTF-8 multi-byte characters like emoji and CJK characters.

Implementations§

Source§

impl Input

Source

pub fn clear(&mut self)

Clear the input (also clears undo history)

Source

pub fn set_value(&mut self, value: impl Into<String>)

Set value programmatically (also clears undo history)

Source§

impl Input

Source

pub fn handle_key_event(&mut self, event: &KeyEvent) -> bool

Handle key event with modifiers, returns true if needs redraw

Source

pub fn handle_key(&mut self, key: &Key) -> bool

Handle key input (without modifiers), returns true if value changed

Source§

impl Input

Source

pub fn selection(&self) -> Option<(usize, usize)>

Get selection range (start, end) if there is a selection

Source

pub fn selected_text(&self) -> Option<&str>

Get selected text

Source

pub fn has_selection(&self) -> bool

Check if there’s an active selection

Source

pub fn start_selection(&mut self)

Start selection at current cursor position

Source

pub fn clear_selection(&mut self)

Clear selection

Source

pub fn select_all(&mut self)

Select all text

Source

pub fn copy(&mut self)

Copy selection to clipboard

Source

pub fn cut(&mut self) -> bool

Cut selection to clipboard

Source

pub fn paste(&mut self) -> bool

Paste from clipboard (O(n) using insert_str)

Source§

impl Input

Source

pub fn undo(&mut self) -> bool

Undo the last operation

Source

pub fn redo(&mut self) -> bool

Redo the last undone operation

Source

pub fn can_undo(&self) -> bool

Check if undo is available

Source

pub fn can_redo(&self) -> bool

Check if redo is available

Source

pub fn clear_history(&mut self)

Clear undo/redo history

Source§

impl Input

Source

pub fn new() -> Self

Create a new input widget

Source

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

Set initial value

Source

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

Set placeholder text

Source

pub fn fg(self, color: Color) -> Self

Set foreground color

Source

pub fn bg(self, color: Color) -> Self

Set background color

Source

pub fn cursor_style(self, fg: Color, bg: Color) -> Self

Set cursor colors

Source

pub fn selection_bg(self, color: Color) -> Self

Set selection background color

Source

pub fn focused(self, focused: bool) -> Self

Set focused state

Source

pub fn text(&self) -> &str

Get current text content

Source

pub fn cursor(&self) -> usize

Get cursor position

Source§

impl Input

Source

pub fn element_id(self, id: impl Into<String>) -> Self

Set element ID for CSS selector (#id)

Source

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

Add a CSS class

Source

pub fn classes<I, S>(self, classes: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add multiple CSS classes

Trait Implementations§

Source§

impl Clone for Input

Source§

fn clone(&self) -> Input

Returns a duplicate 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 Debug for Input

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Input

Source§

fn default() -> Self

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

impl StyledView for Input

Source§

fn set_id(&mut self, id: impl Into<String>)

Set element ID
Source§

fn add_class(&mut self, class: impl Into<String>)

Add a CSS class
Source§

fn remove_class(&mut self, class: &str)

Remove a CSS class
Source§

fn toggle_class(&mut self, class: &str)

Toggle a CSS class
Source§

fn has_class(&self, class: &str) -> bool

Check if has class
Source§

impl View for Input

Source§

fn render(&self, ctx: &mut RenderContext<'_>)

Render the view
Source§

fn id(&self) -> Option<&str>

Get element ID (for CSS #id selectors)
Source§

fn classes(&self) -> &[String]

Get CSS classes (for CSS .class selectors)
Source§

fn meta(&self) -> WidgetMeta

Get widget metadata for DOM
Source§

fn widget_type(&self) -> &'static str

Get widget type name (for CSS type selectors)
Source§

fn children(&self) -> &[Box<dyn View>]

Get child views (for container widgets) Read more

Auto Trait Implementations§

§

impl Freeze for Input

§

impl RefUnwindSafe for Input

§

impl Send for Input

§

impl Sync for Input

§

impl Unpin for Input

§

impl UnwindSafe for Input

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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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