pub struct RemovableChip<'a> { /* private fields */ }Expand description
A bordered inline text input with an × close button, bound to a single
String.
let mut suffix = String::from("run-1");
let resp = RemovableChip::new(&mut suffix)
.prefix("_")
.placeholder("run-1")
.show(ui);
if resp.removed {
// caller drops the field
}The chip auto-sizes its editor to fit the current text, clamped to
auto_size. The removed flag in the returned
RemovableChipResponse is set when the user clicks × or presses
Escape on an empty input; the caller decides whether to actually clear
or drop the binding.
Implementations§
Source§impl<'a> RemovableChip<'a>
impl<'a> RemovableChip<'a>
Sourcepub fn new(text: &'a mut String) -> Self
pub fn new(text: &'a mut String) -> Self
Create a chip bound to text. The chip’s value mirrors this String.
Sourcepub fn prefix(self, text: impl Into<WidgetText>) -> Self
pub fn prefix(self, text: impl Into<WidgetText>) -> Self
Show non-editable text inside the chip, before the input. Useful for
leading separators (e.g. "_" for a path-suffix chip) or for fixed
labels that read as part of the value but aren’t part of the binding.
Sourcepub fn placeholder(self, text: &'a str) -> Self
pub fn placeholder(self, text: &'a str) -> Self
Placeholder text shown when the input is empty.
Sourcepub fn accent(self, accent: Accent) -> Self
pub fn accent(self, accent: Accent) -> Self
Border / focus accent colour. Default: Accent::Sky.
Sourcepub fn enabled(self, enabled: bool) -> Self
pub fn enabled(self, enabled: bool) -> Self
Disable the chip. Disabled chips ignore typing and clicks on ×.
Default: enabled.
Sourcepub fn auto_size(self, range: RangeInclusive<f32>) -> Self
pub fn auto_size(self, range: RangeInclusive<f32>) -> Self
Minimum and maximum width (points) for the editor portion. The chip
measures the current text and sizes the editor within this range.
Default: 50.0..=240.0.
Sourcepub fn id_salt(self, id: impl Hash) -> Self
pub fn id_salt(self, id: impl Hash) -> Self
Stable id salt. Useful when several chips share a layout, or when you need to address the chip’s state across frames.
Sourcepub fn show(self, ui: &mut Ui) -> RemovableChipResponse
pub fn show(self, ui: &mut Ui) -> RemovableChipResponse
Render the chip and return its response.