use crate::ui::{Model, theme};
pub const OPEN: &str = "find text…";
pub const CLOSE: &str = "done";
pub const HEADING: &str = "find text";
pub const FIND: &str = "find";
pub const NEEDS_WORDS: &str = "type what to look for and this becomes live";
pub const NOT_ASKED: &str = "nothing has been looked for yet";
pub const NOTHING: &str = "this engine found none of it";
pub const NOT_ADDRESSABLE: &str = "a hit says where it is in the engine's own path spelling, which no gesture \
from this box can carry — so these are read here and aimed at by hand";
pub fn render(ui: &mut egui::Ui, model: &mut Model) -> bool {
if !model.finding() {
return false;
}
ui.heading(HEADING);
ui.horizontal_wrapped(|ui| {
if ui.button(CLOSE).clicked() {
model.close_lookup();
}
});
ui.separator();
asking(ui, model);
ui.separator();
let found = model.found.clone();
if found.is_empty() {
ui.label(NOT_ASKED);
return true;
}
ui.colored_label(theme::NOTICE, NOT_ADDRESSABLE);
egui::ScrollArea::vertical()
.id_salt(HEADING)
.auto_shrink(false)
.show(ui, |ui| {
for section in &found {
ui.separator();
ui.label(crate::ui::roster::header(§ion.channel));
answered(ui, §ion.found);
}
});
true
}
fn asking(ui: &mut egui::Ui, model: &mut Model) {
ui.text_edit_singleline(&mut model.needle);
let live = model.needled();
let mut fired = false;
ui.horizontal_wrapped(|ui| {
let act = ui.add_enabled(live, egui::Button::new(FIND));
crate::ui::act::tag(&act, &[crate::verbs::SEARCH.word]);
fired = act.clicked();
});
if !live {
ui.colored_label(theme::NOTICE, NEEDS_WORDS);
}
if fired {
model.post_search();
}
}
fn answered(ui: &mut egui::Ui, found: &crate::reply::search::Found) {
ui.label(looked_for(found));
for why in &found.unreadable {
ui.colored_label(theme::NOTICE, unread(why));
}
if found.rows.is_empty() {
ui.label(NOTHING);
return;
}
for row in &found.rows {
hit(ui, row);
}
}
fn hit(ui: &mut egui::Ui, row: &crate::reply::search::Hit) {
ui.label(row.subject());
ui.colored_label(
theme::tone_ink(&crate::reply::convs::Tone::Weak),
row.at_field(),
);
ui.add(egui::Label::new(row.excerpt.clone()).wrap());
}
pub fn looked_for(found: &crate::reply::search::Found) -> String {
format!("looked for {:?}", found.needle)
}
pub fn unread(why: &str) -> String {
format!("could not be read: {why}")
}
#[cfg(test)]
mod tests;