pub struct TextFilter { /* private fields */ }Expand description
Helper to parse and apply text filters
This struct provides text filtering functionality similar to many search interfaces. It supports include/exclude patterns and can be used to filter lists of items.
§Examples
// Create a filter with default empty pattern
let mut filter = TextFilter::new("Search".to_string());
// Create a filter with initial pattern
let mut filter_with_pattern = TextFilter::new_with_filter(
"Advanced Search".to_string(),
"include,-exclude".to_string()
);Implementations§
Source§impl TextFilter
impl TextFilter
Sourcepub fn new(label: impl Into<String>) -> Self
pub fn new(label: impl Into<String>) -> Self
Creates a new TextFilter with an empty filter.
This is equivalent to new_with_filter with filter set to "".
§Arguments
label- The label to display for the filter input
§Examples
let filter = TextFilter::new("Search");Sourcepub fn build(&mut self)
pub fn build(&mut self)
Builds the TextFilter with its current filter pattern.
You can use pass_filter after calling this method.
If you want to control the filter with an InputText, use draw instead.
§Examples
let mut filter = TextFilter::new_with_filter(
"Search".to_string(),
"test".to_string()
);
filter.build();
if filter.pass_filter("test string") {
println!("Text matches filter!");
}Sourcepub fn draw(&mut self, ui: &Ui) -> bool
pub fn draw(&mut self, ui: &Ui) -> bool
Draws an InputText widget to control the filter.
This is equivalent to draw_with_size with size set to 0.0.
Returns true if the filter was modified.
§Examples
let mut filter = TextFilter::new("Search");
if filter.draw(&ui) {
println!("Filter was modified!");
}Sourcepub fn draw_with_size(&mut self, ui: &Ui, width: f32) -> bool
pub fn draw_with_size(&mut self, ui: &Ui, width: f32) -> bool
Draws an InputText widget to control the filter with a specific width.
§Arguments
width- The width of the input text widget (0.0 for default width)
Returns true if the filter was modified.
§Examples
let mut filter = TextFilter::new("Search");
if filter.draw_with_size(&ui, 200.0) {
println!("Filter was modified!");
}Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Returns true if the filter is not empty.
An empty filter (no pattern specified) will match all text.
§Examples
let empty_filter = TextFilter::new("Search");
assert!(!empty_filter.is_active());
let active_filter = TextFilter::new_with_filter(
"Search",
"test"
);
assert!(active_filter.is_active());Sourcepub fn pass_filter(&self, text: &str) -> bool
pub fn pass_filter(&self, text: &str) -> bool
Returns true if the text matches the filter.
draw or build must be called before this function.
§Arguments
text- The text to test against the filter
§Examples
let mut filter = TextFilter::new_with_filter(
"Search",
"test"
);
filter.build();
assert!(filter.pass_filter("test string"));
assert!(!filter.pass_filter("example string"));Sourcepub fn pass_filter_range(&self, text: &str, range: Range<usize>) -> bool
pub fn pass_filter_range(&self, text: &str, range: Range<usize>) -> bool
Returns true if a substring range matches the filter.
This is the safe Rust equivalent of PassFilter(text, text_end) in Dear ImGui,
where text_end points somewhere inside the same buffer as text.
range is in bytes and must lie on UTF-8 char boundaries.