pub struct TextField { /* private fields */ }Expand description
A single-line text input bound to a String.
Supports typing, deleting, moving by character, word and line, selecting with Shift, the mouse (drag, double-click) or Cmd/Ctrl+A, copy, cut and paste, and Enter (submit). Passwords can be pasted but not copied.
use ravenrs_reactive::State;
use ravenrs_widgets::{IconName, TextField, Ui};
let query = State::new(String::new());
let field = TextField::new(query.binding()).placeholder("Search").icon(IconName::Search).clearable();
let mut ui = Ui::new(field, ravenrs_style::Theme::raven_dark());
ui.update();Implementations§
Source§impl TextField
impl TextField
Sourcepub fn placeholder(self, text: impl Into<String>) -> Self
pub fn placeholder(self, text: impl Into<String>) -> Self
Muted text shown while the value is empty.
Sourcepub fn width(self, width: f32) -> Self
pub fn width(self, width: f32) -> Self
Fixed width in logical pixels; by default the field stretches.
Sourcepub fn compact(self) -> Self
pub fn compact(self) -> Self
A shorter field with smaller text, for toolbars, filter rows and cells: the same
as Self::size with ButtonSize::Small.
Sourcepub fn size(self, size: ButtonSize) -> Self
pub fn size(self, size: ButtonSize) -> Self
Sets the height and text size to line up with a Button of the
same size (Medium by default). The smaller ones have no minimum width.
Sourcepub fn prefix(self, view: impl View + 'static) -> Self
pub fn prefix(self, view: impl View + 'static) -> Self
Any view inside the field, before the text, such as a currency or a unit.
Sourcepub fn suffix(self, view: impl View + 'static) -> Self
pub fn suffix(self, view: impl View + 'static) -> Self
Any view inside the field, after the text, such as a unit or a button.
Sourcepub fn clearable(self) -> Self
pub fn clearable(self) -> Self
A button inside the field that empties it, shown while there is text to clear. The keyboard comes back to the field afterwards.
Sourcepub fn flat(self) -> Self
pub fn flat(self) -> Self
No box of its own until it is pointed at or focused, filling what it is in, for fields that line up with what is around them, as under the columns of a grid.
Sourcepub fn end_aligned(self) -> Self
pub fn end_aligned(self) -> Self
Puts the text at the end of the field, as under a column of numbers.
Sourcepub fn select_on_open(self) -> Self
pub fn select_on_open(self) -> Self
Starts with all of its text selected, so that typing replaces it.
Sourcepub fn on_cancel(self, handler: impl Fn() + 'static) -> Self
pub fn on_cancel(self, handler: impl Fn() + 'static) -> Self
Called when Escape is pressed while the field is focused.
Sourcepub fn intercept_keys(self, handler: KeyHandler) -> Self
pub fn intercept_keys(self, handler: KeyHandler) -> Self
Sees keys before the field edits; return true to consume them (lists navigated from a search field use it for arrows and Enter).
Sourcepub fn on_submit(self, handler: impl Fn(String) + 'static) -> Self
pub fn on_submit(self, handler: impl Fn(String) + 'static) -> Self
Called with the current text when Enter is pressed.
Sourcepub fn on_leave(self, handler: impl Fn() + 'static) -> Self
pub fn on_leave(self, handler: impl Fn() + 'static) -> Self
Called when the keyboard goes elsewhere after being here.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TextField
impl !Send for TextField
impl !Sync for TextField
impl !UnwindSafe for TextField
impl Freeze 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
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
None keeps the content size.