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: String) -> Self
pub fn new(label: 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".to_string());Sourcepub fn new_with_filter(label: String, filter: String) -> Self
pub fn new_with_filter(label: String, filter: String) -> Self
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) -> bool
pub fn draw(&mut self) -> 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".to_string());
if filter.draw() {
println!("Filter was modified!");
}Sourcepub fn draw_with_size(&mut self, width: f32) -> bool
pub fn draw_with_size(&mut self, 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".to_string());
if filter.draw_with_size(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".to_string());
assert!(!empty_filter.is_active());
let active_filter = TextFilter::new_with_filter(
"Search".to_string(),
"test".to_string()
);
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".to_string(),
"test".to_string()
);
filter.build();
assert!(filter.pass_filter("test string"));
assert!(!filter.pass_filter("example string"));Sourcepub fn pass_filter_with_end(&self, start: &str, end: &str) -> bool
pub fn pass_filter_with_end(&self, start: &str, end: &str) -> bool
Returns true if the text range matches the filter.
This version allows you to specify both start and end pointers for the text.
§Arguments
start- The start of the text to testend- The end of the text to test
§Examples
let mut filter = TextFilter::new_with_filter(
"Search".to_string(),
"test".to_string()
);
filter.build();
assert!(filter.pass_filter_with_end("test", " string"));