use crate::reply::roster::WsRow;
use crate::ui::{Aim, Model, convs, theme};
pub const NO_NAME_HERE: &str =
"this box has no connection set up for it, so nothing here can reach it";
pub const PIN: &str = "pin";
pub const UNPIN: &str = "unpin";
pub const NEW: &str = "+ new";
pub const AIM_HELP: &str =
"aims the window at this workspace: its conversations, its settings, its providers";
pub const NEW_HELP: &str =
"begins a conversation on this workspace; the box takes its first message";
pub const NO_NAME_HELP: &str =
"a workspace this box has no name for, so nothing here can aim at it";
pub fn render(ui: &mut egui::Ui, model: &mut Model, aim: Option<Aim>, row: &WsRow, reveal: bool) {
let Some(aim) = aim else {
theme::paint::row(
ui,
&format!("{} — {NO_NAME_HERE}", line(row)),
theme::INK_FAINT,
None,
false,
0.0,
NO_NAME_HELP,
);
return;
};
let aimed = model.aim.as_ref() == Some(&aim);
let state = if row.attention > 0 {
Some(theme::accent(theme::State::Attention))
} else if row.running {
Some(theme::accent(theme::State::Working))
} else {
None
};
let seat = theme::paint::row(ui, &line(row), theme::INK, state, aimed, 0.0, AIM_HELP);
let offer = |ui: &mut egui::Ui, model: &mut Model| begin(ui, model, &aim, reveal);
crate::ui::act::tag(&seat, &[crate::verbs::CONVERSATIONS.word]);
if aimed && reveal {
seat.scroll_to_me(None);
}
if seat.clicked() {
model.aim_at(&aim.channel, &aim.address);
}
if !aimed {
offer(ui, model);
return;
}
convs::under(ui, model, &aim, reveal);
offer(ui, model);
}
fn begin(ui: &mut egui::Ui, model: &mut Model, aim: &crate::ui::Aim, reveal: bool) {
if model.covered() && !model.switching {
return;
}
let stand = crate::ui::Stand::Begin(aim.clone());
if standing_row(ui, model, (NEW, NEW_HELP), stand, convs::STEP, reveal) {
model.begin_at(aim);
model.chose();
}
}
pub(super) fn standing_row(
ui: &mut egui::Ui,
model: &mut Model,
(text, help): (&str, &str),
stand: crate::ui::Stand,
indent: f32,
reveal: bool,
) -> bool {
let standing = model.standing.as_ref() == Some(&stand);
let rule = standing.then_some(theme::BRAND);
let seat = theme::paint::row(ui, text, theme::INK_WEAK, rule, false, indent, help);
if standing && reveal {
seat.scroll_to_me(None);
}
if seat.gained_focus() {
model.standing = Some(stand);
}
seat.clicked()
}
pub fn line(row: &WsRow) -> String {
let mut said = vec![row.workspace.clone()];
if row.attention > 0 {
said.push(format!("{} waiting", row.attention));
}
if row.running {
said.push("running".to_owned());
}
if let Some(cost) = &row.spend {
said.push(cost.said());
}
said.push(crate::render::counted(row.agents, "conversation"));
said.push(format!("({})", row.kind.label()));
said.join(" ")
}
#[cfg(test)]
mod tests;