use crate::reply::roster::WsRow;
use crate::ui::{Aim, Channel, Chunk, Model, theme};
pub mod acts;
pub mod wall;
pub use acts::REFRESH;
pub use wall::{NO_NAME_HERE, PIN, UNPIN, line};
pub const NOT_ANSWERED: &str = "waiting to hear from this channel";
pub const NO_WALLS: &str = "this engine holds no workspace";
pub const HEADING: &str = "channels";
pub fn aimable(model: &Model) -> Vec<Aim> {
let mut rows = Vec::new();
for chunk in &model.roster {
for row in ordered(&chunk.walls) {
if let Some(address) = chunk.channel.address(&row) {
rows.push(Aim {
channel: chunk.channel.name.clone(),
address,
});
}
}
}
rows
}
pub fn render(ui: &mut egui::Ui, model: &mut Model) {
if !model.covered() {
acts::render(ui, model);
}
let reveal = model.revealing(crate::ui::keys::Pane::Roster);
egui::ScrollArea::vertical()
.id_salt(HEADING)
.auto_shrink(false)
.show(ui, |ui| {
for chunk in model.roster.clone() {
section(ui, model, &chunk, reveal);
}
});
}
fn section(ui: &mut egui::Ui, model: &mut Model, chunk: &Chunk, reveal: bool) {
ui.separator();
ui.label(header(&chunk.channel));
if let crate::ui::Held::Unheld(why) = &chunk.held {
ui.colored_label(theme::NOTICE, why);
}
for note in [chunk.stale.as_ref(), chunk.growth.as_ref()]
.into_iter()
.flatten()
{
ui.colored_label(theme::tone_ink(&crate::reply::convs::Tone::Weak), note);
}
if chunk.walls.is_empty() {
match &chunk.held {
crate::ui::Held::Unheard => {
ui.label(NOT_ANSWERED);
}
crate::ui::Held::Heard => {
ui.label(NO_WALLS);
}
crate::ui::Held::Unheld(_) => {}
}
return;
}
for row in ordered(&chunk.walls) {
wall::render(ui, model, chunk, &row, reveal);
}
}
pub fn header(channel: &Channel) -> String {
let named = match &channel.named_there {
Some(there) if *there != channel.name => {
format!("{} (named {:?} on its host)", channel.name, there)
}
_ => channel.name.clone(),
};
match &channel.dials {
Some(at) => format!("{named} — {at}"),
None => named,
}
}
pub fn ordered(walls: &[WsRow]) -> Vec<WsRow> {
let mut rows = walls.to_vec();
rows.sort_by(|a, b| {
(a.pinned.unwrap_or(u64::MAX), &a.workspace)
.cmp(&(b.pinned.unwrap_or(u64::MAX), &b.workspace))
});
rows
}
#[cfg(test)]
mod tests;