Skip to main content

egui_table_kit/filter/
mod.rs

1//! Combined table filters.
2
3pub mod highlight;
4pub mod search;
5
6/// Composable filter containing text matching query criteria and row highlight restrictions.
7#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
8pub struct Filter {
9    pub search: search::Search,
10    pub highlight: Option<Option<u8>>,
11}
12
13impl Filter {
14    /// Evaluates if the specific row values satisfy active filtering criteria.
15    #[must_use]
16    pub fn matches(&self, text: &str, row_highlight: Option<u8>) -> bool {
17        if let Some(req_highlight) = self.highlight
18            && row_highlight != req_highlight
19        {
20            return false;
21        }
22        self.search.is_match(text)
23    }
24
25    /// Returns whether this filter contains no active criteria.
26    #[must_use]
27    pub const fn is_empty(&self) -> bool {
28        !self.search.is_active() && self.highlight.is_none()
29    }
30}