TextFilter

Struct TextFilter 

Source
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

Source

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());
Source

pub fn new_with_filter(label: String, filter: String) -> Self

Creates a new TextFilter with a custom filter pattern.

§Arguments
  • label - The label to display for the filter input
  • filter - The initial filter pattern
§Examples
let filter = TextFilter::new_with_filter(
    "Search".to_string(),
    "include,-exclude".to_string()
);
Source

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!");
}
Source

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!");
}
Source

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!");
}
Source

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());
Source

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"));
Source

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 test
  • end - 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"));
Source

pub fn clear(&mut self)

Clears the filter pattern.

This sets the filter to an empty state, which will match all text.

§Examples
let mut filter = TextFilter::new_with_filter(
    "Search".to_string(),
    "test".to_string()
);

assert!(filter.is_active());
filter.clear();
assert!(!filter.is_active());

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more