pub struct TagInput<'a> { /* private fields */ }Expand description
A pill-list text input bound to a Vec<String>.
let mut tags: Vec<String> = vec!["rust".into(), "egui".into()];
TagInput::new("tags", &mut tags)
.label("Tags")
.placeholder("Add a tag…")
.show(ui);§Email-style validator
Pass a validator closure to reject malformed
commits. The widget keeps the offending text in the buffer, switches
the border to the danger colour, and renders an inline error line
below.
let mut to: Vec<String> = Vec::new();
TagInput::new("recipients", &mut to)
.label("Recipients")
.placeholder("Add an email…")
.commit_on_space(true)
.validator(|v| {
if v.contains('@') && v.contains('.') {
Ok(())
} else {
Err(format!("\"{v}\" isn't a valid email."))
}
})
.show(ui);Implementations§
Source§impl<'a> TagInput<'a>
impl<'a> TagInput<'a>
Sourcepub fn new(id_salt: impl Hash, tags: &'a mut Vec<String>) -> Self
pub fn new(id_salt: impl Hash, tags: &'a mut Vec<String>) -> Self
Create a tag input bound to tags. The id_salt keys the buffer,
armed flag, and last-error in egui memory. Use a unique salt per
instance.
Sourcepub fn label(self, text: impl Into<WidgetText>) -> Self
pub fn label(self, text: impl Into<WidgetText>) -> Self
Show a label above the input.
Sourcepub fn placeholder(self, text: impl Into<String>) -> Self
pub fn placeholder(self, text: impl Into<String>) -> Self
Placeholder shown inside the field when empty.
Sourcepub fn accent(self, accent: Accent) -> Self
pub fn accent(self, accent: Accent) -> Self
Pill accent colour. Default: Accent::Sky.
Sourcepub fn enabled(self, enabled: bool) -> Self
pub fn enabled(self, enabled: bool) -> Self
Disable the input. Disabled inputs ignore clicks, keystrokes, and
the × buttons. Default: enabled.
Sourcepub fn commit_on_space(self, on: bool) -> Self
pub fn commit_on_space(self, on: bool) -> Self
Treat whitespace as a commit key, in addition to Enter and comma.
Useful for email recipient fields where users frequently type
addresses separated by spaces. Default: false.
Sourcepub fn desired_width(self, width: f32) -> Self
pub fn desired_width(self, width: f32) -> Self
Desired width (points) of the framed input. Default: full available width.
Sourcepub fn validator(self, f: impl Fn(&str) -> Result<(), String> + 'a) -> Self
pub fn validator(self, f: impl Fn(&str) -> Result<(), String> + 'a) -> Self
Reject a candidate tag with an inline error. The closure returns
Ok(()) for accepted values or Err(msg) to display msg
underneath the input. Rejected text stays in the buffer so the
user can fix and retry.
Sourcepub fn show(self, ui: &mut Ui) -> TagInputResponse
pub fn show(self, ui: &mut Ui) -> TagInputResponse
Render the input.