Text Input
A text input editing value.
ui.text_inputBasic
ui.text_input(&mut self.name);Placeholder
ui.text_input(&mut self.project).placeholder("Project name");With an icon
ui.column().w_fill().gap(8).children(|ui| { ui.text_input(&mut self.search).placeholder("Search").icon(IconName::Search); ui.text_input(&mut self.link) .placeholder("example.com") .icon_end(IconName::ExternalLink);});Clearable
// The clear button shows while there is text.ui.text_input(&mut self.filter).placeholder("Filter").clearable();Password
ui.column().w_fill().gap(8).children(|ui| { ui.text_input(&mut self.secret).placeholder("Password").password(); // With a button that shows what was typed. ui.text_input(&mut self.secret).placeholder("Password").password().revealable();});Multiline
ui.text_input(&mut self.note).placeholder("Enter adds a line").multiline(3);Read-only
// The text can be selected and copied, not edited.ui.text_input(&mut self.fixed).read_only();Maximum length
ui.text_input(&mut self.code).placeholder("Up to 6 characters").max_length(6);Sizes
ui.column().w_fill().gap(8).children(|ui| { ui.text_input(&mut self.sized).placeholder("Small").small(); ui.text_input(&mut self.sized).placeholder("Default"); ui.text_input(&mut self.sized).placeholder("Large").large();});Fixed width
ui.text_input(&mut self.short).placeholder("160 wide").w(160);Disabled
ui.text_input(&mut self.locked).disabled(true);API reference
| Setting | Description |
|---|---|
.placeholder(text: impl Display) | Text shown while empty. |
.w(width: impl Into<Sizing>) | The width; a plain length is a fixed width. |
.w_fill() | Takes the remaining width (the default). |
.small() | The theme's small control height and note font size. |
.large() | The theme's large control height. |
.multiline(rows: u32) | Shows rows rows of wrapping text; Enter inserts a line break. |
.autofocus() | Takes the focus when first shown. |
.password() | Draws every character as a dot. |
.revealable() | Adds a button to a password input that shows what was typed, and hides it again. The input starts hidden. Ignored without password. |
.read_only() | Makes the text read-only. |
.max_length(length: usize) | Limits typing and pasting to length characters. |
.icon(icon: IconName) | An icon before the text. A multiline input ignores it. |
.icon_end(icon: IconName) | An icon after the text. A multiline input ignores it. |
.clearable() | Shows a clear button at the end while there is text. |
Settings and results every widget has
.with(f: impl FnOnce(&mut W)) | Changes the widget being declared. This is how a widget defined outside CPUI gets settings that chain like the built-in ones, through a trait on its element. |
.disabled(disabled: bool) | Disables the widget when disabled is true. |
.tooltip(text: impl Display) | Shows text in a tooltip when the pointer rests on the widget. |
.aria_label(text: impl Display) | Names the widget for assistive technology without drawing anything. |
.aria_role(role: accesskit::Role) | What assistive technology is told the widget is, for a widget drawn on a canvas or built from others. A canvas given a role, a name or a value is described as an image unless given another role. |
.aria_value(text: impl Display) | The value assistive technology reads, as text: "3 of 5 stars", "Monday 4 March". |
.aria_range(value: f64, min: f64, max: f64) | A numeric value between min and max, for sliders, meters and progress. Assistive technology steps it with the arrow keys, so handle those while focused. |
.self_start() | Aligns to the cross-axis start (top in a stack), overriding the container. |
.self_center() | Centers this widget on the cross axis (vertically in a stack). |
.self_end() | Aligns this widget to the end of the cross axis (the bottom in a stack). |
.self_stretch() | Stretches this widget on the cross axis if it has no fixed size there. |
.layout_priority(priority: f32) | Sets the priority for keeping width when a row is too narrow. |
.col_span(columns: u32) | Spans columns columns of the grid. |
.offset(x: impl crate::style::Length, y: impl crate::style::Length) | Draws this widget x right and y down of its layout position, moving nothing else. |
.justify_self_start() | In a stack, aligns to the left. |
.justify_self_center() | In a stack, centers horizontally. |
.justify_self_end() | In a stack, aligns to the right. |
.when(condition: bool, f: impl FnOnce(Self) | Applies f when condition is true. |
.when_some(value: Option<T>, f: impl FnOnce(Self, T) | Applies f to the value when there is one. |
.response() | Places the widget and returns its full interaction result. |
.clicked() | Places the widget and returns whether it was clicked this frame. |
.double_clicked() | Places the widget and returns whether it was double-clicked this frame. |
.secondary_clicked() | Places the widget and returns whether it got a secondary (right) button press this frame. |
.hovered() | Places the widget and returns whether the pointer is over it. |
.changed() | Places the widget and returns whether its value changed this frame. |
.submitted() | Places the widget and returns Response::submitted. |