Skip to main content

TagInput

Struct TagInput 

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

Source

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.

Source

pub fn label(self, text: impl Into<WidgetText>) -> Self

Show a label above the input.

Source

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

Placeholder shown inside the field when empty.

Source

pub fn accent(self, accent: Accent) -> Self

Pill accent colour. Default: Accent::Sky.

Source

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

Disable the input. Disabled inputs ignore clicks, keystrokes, and the × buttons. Default: enabled.

Source

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.

Source

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

Desired width (points) of the framed input. Default: full available width.

Source

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.

Source

pub fn show(self, ui: &mut Ui) -> TagInputResponse

Render the input.

Trait Implementations§

Source§

impl<'a> Debug for TagInput<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for TagInput<'a>

§

impl<'a> !RefUnwindSafe for TagInput<'a>

§

impl<'a> !Send for TagInput<'a>

§

impl<'a> !Sync for TagInput<'a>

§

impl<'a> Unpin for TagInput<'a>

§

impl<'a> UnsafeUnpin for TagInput<'a>

§

impl<'a> !UnwindSafe for TagInput<'a>

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> 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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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.