use super::{Fold, Kind, Row, code, fold};
use crate::ui::theme::{self, Speaker, glyph};
pub(super) fn step(ui: &mut egui::Ui, at: usize, row: &Row, door: bool) -> bool {
if row.kind == Kind::Said {
let mut shut = false;
theme::paint::bubbled(ui, theme::Bubble::Intermediate, |ui| {
shut = bare(ui, at, row, door);
});
return shut;
}
bare(ui, at, row, door)
}
fn bare(ui: &mut egui::Ui, at: usize, row: &Row, door: bool) -> bool {
let red = theme::accent(theme::State::Error);
let ended = |ui: &mut egui::Ui| {
let (mark, ink) = if row.failed {
(glyph::FAILED, red)
} else {
(glyph::DONE, theme::INK_WEAK)
};
ui.label(egui::RichText::new(mark).color(ink));
};
let (mark, ink) = match row.kind {
Kind::Call | Kind::Answered => (glyph::CALL, theme::BRAND),
Kind::Said if row.weight == Speaker::Model => (glyph::MODEL, theme::INK_WEAK),
_ => (glyph::NOTE, theme::INK_WEAK),
};
if row.kind == Kind::Result {
ended(ui);
} else {
ui.label(egui::RichText::new(mark).color(ink));
}
let mut shut = false;
ui.vertical(|ui| {
let who = match row.kind {
_ if row.failed => red,
Kind::Said => theme::speaker(row.weight),
_ => theme::INK_WEAK,
};
ui.horizontal_wrapped(|ui| {
if door {
shut = theme::paint::tab(ui, &row.who, who).clicked();
} else {
ui.label(egui::RichText::new(&row.who).color(who));
}
if row.kind == Kind::Answered {
ended(ui);
}
});
match &row.fold {
Some(fold) => folded(ui, at, row, fold),
None if row.said.is_empty() => {}
None if row.kind == Kind::Said => code::paint(ui, at, &row.said, theme::INK),
None => {
theme::paint::prose(ui, &row.said, theme::INK_WEAK);
}
}
});
shut
}
fn folded(ui: &mut egui::Ui, at: usize, row: &Row, fold: &Fold) {
let id = ui.make_persistent_id(at);
let mut open = ui.data(|d| d.get_temp::<bool>(id)).unwrap_or(false);
if ui
.button(if open { fold::UNFOLD } else { &fold.whole })
.clicked()
{
open = !open;
ui.data_mut(|d| d.insert_temp(id, open));
}
if open {
theme::paint::prose(ui, &row.said, theme::INK);
} else {
theme::paint::prose(ui, &fold.head, theme::INK_WEAK);
}
}