Skip to main content

Module filter

Module filter 

Source
Expand description

A search field with filter chips, giving the application a structured Filter.

Words typed search the images’ names and tags; typed criteria become chips when Enter is pressed: rating>=3 (or rating:3), label:red, flag:pick (reject, none), tag:beach (or #beach), date:2024-06-01..2024-06-30, from:2024-06-01, to:2024-06-30. The menu beside the field adds a rating, a label or a flag; each chip has its remove button, Backspace in the empty field removes the last one, and the clear button removes everything. Every change of the filter runs the library.filter step: a before-hook may refuse it or rewrite it; the application filters its images with what the output gives (Filter::matches does the usual matching).

use egui_pop_views::library::filter::{Candidate, SearchField, SearchState};

fn ui(ui: &mut egui::Ui, state: &mut SearchState, names: &[String], shown: &mut Vec<usize>) {
    if let Some(filter) = SearchField::new("shoot").show(ui, state).changed {
        *shown = (0..names.len())
            .filter(|&i| filter.matches(&Candidate::named(&names[i])))
            .collect();
    }
}

Structs§

AppChip
A chip the application draws in the field (SearchField::chips): a part of its own reading of the text, in words.
Candidate
An image as Filter::matches sees it.
Filter
What the application filters its images by. Empty criteria filter nothing; all criteria must hold (labels and flags: any of them; tags: all of them).
SearchField
The search field.
SearchOutput
What SearchField::show returns.
SearchState
A search field’s state between passes: the chips, the text typed, the filter last given.
Suggestion
A suggestion the application offers under the field (SearchField::suggestions).

Enums§

FilterChip
One criterion of a filter, as a chip shows it.
SearchEvent
What the application hooks did in a pass (SearchState::take_events).

Functions§

is_day
Whether text is a day, YYYY-MM-DD.
read_value
A term’s value with its quotes taken off and their escapes undone, the inverse of value_text: "New York" is New York, "say \"hi\"" is say "hi"; a bare value is kept.
split_terms
A search text cut at the spaces outside quotes, each term as typed (label:red tag:"New York" is label:red and tag:"New York"). A quote escaped inside quotes (\") does not close them; an unclosed quote runs to the end. Without quotes, the words between spaces.
value_text
A value as written after key:, read_value reading it back whole: as it is when it can be (beach), quoted when it holds a space, a quote or a parenthesis, is empty, or starts like an operator ("New York", "say \"hi\"").