use crate::ui::{Aim, Chunk, Model, theme};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Step {
Engine(String),
Wall(Aim),
}
impl Step {
pub fn holding(&self, model: &Model) -> bool {
match self {
Self::Engine(name) => model.standing.as_deref() == Some(name.as_str()),
Self::Wall(aim) => model.standing.is_none() && model.aim.as_ref() == Some(aim),
}
}
}
pub fn track(model: &Model) -> Vec<Step> {
let open = model.engine_open();
let mut rows = Vec::new();
for chunk in model.engine_rows() {
let name = chunk.channel.name.clone();
rows.push(Step::Engine(name.clone()));
if open.as_deref() != Some(name.as_str()) {
continue;
}
for wall in super::ordered(&chunk.walls) {
if let Some(address) = chunk.channel.address(&wall) {
rows.push(Step::Wall(Aim {
channel: name.clone(),
address,
}));
}
}
}
rows
}
pub fn render(ui: &mut egui::Ui, model: &mut Model, chunk: &Chunk, open: bool, reveal: bool) {
let name = chunk.channel.name.clone();
let standing = model.standing.as_deref() == Some(name.as_str());
let seat = theme::paint::row(
ui,
&super::header(&chunk.channel),
theme::INK,
standing.then_some(theme::BRAND),
open,
0.0,
);
if standing && reveal {
seat.scroll_to_me(None);
}
if seat.gained_focus() {
model.focus = crate::ui::keys::Pane::Roster;
model.standing = Some(name.clone());
}
if seat.clicked() {
model.open_engine(&name);
}
}