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::matchessees 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).
- Search
Field - The search field.
- Search
Output - What
SearchField::showreturns. - Search
State - 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§
- Filter
Chip - One criterion of a filter, as a chip shows it.
- Search
Event - What the application hooks did in a pass
(
SearchState::take_events).
Functions§
- is_day
- Whether
textis 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"isNew York,"say \"hi\""issay "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"islabel:redandtag:"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_valuereading 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\"").