use crate::ui::{
Model, board, chat, clients, commands, composer, config, convs, enroll, find, keys, login,
queue, records, roster, theme, trail, tuning, unmake,
};
pub mod policy;
pub use policy::{CHAT_FLOOR, Column, SIDE_FLOOR, Shape, shape, widths};
pub fn render(ctx: &egui::Context, model: &mut Model) {
ctx.set_visuals(theme::visuals());
keys::handle(ctx, model);
notice(ctx, model);
let (shown, broad) = match shape(ctx.screen_rect().width()) {
Shape::Broad { roster, convs } => {
lists(ctx, model, roster, convs);
(Column::Conversation, true)
}
Shape::Narrow => {
bar(ctx, model);
(model.column, false)
}
};
if !model.covered() && shown == Column::Conversation {
egui::TopBottomPanel::bottom("composer").show(ctx, |ui| composer::render(ui, model));
}
egui::CentralPanel::default().show(ctx, |ui| central(ui, model, shown, broad));
}
fn lists(ctx: &egui::Context, model: &mut Model, roster_width: f32, convs_width: f32) {
egui::SidePanel::left("roster")
.default_width(policy::ROSTER)
.max_width(roster_width)
.show(ctx, |ui| {
ui.heading(keys::heading(
roster::HEADING,
model.focus == keys::Pane::Roster,
));
roster::render(ui, model);
});
egui::SidePanel::left("conversations")
.default_width(policy::CONVS)
.max_width(convs_width)
.show(ctx, |ui| {
ui.heading(keys::heading(
convs::HEADING,
model.focus == keys::Pane::Conversations,
));
convs::render(ui, model);
});
}
fn bar(ctx: &egui::Context, model: &mut Model) {
if model.covered() {
return;
}
egui::TopBottomPanel::top("columns").show(ctx, |ui| {
ui.horizontal_wrapped(|ui| {
for column in Column::all() {
if ui
.selectable_label(model.column == column, column.word())
.clicked()
{
model.column = column;
}
}
});
});
}
fn central(ui: &mut egui::Ui, model: &mut Model, shown: Column, broad: bool) {
if enroll::render(ui, model)
|| tuning::render(ui, model)
|| records::render(ui, model)
|| queue::render(ui, model)
|| trail::render(ui, model)
|| board::render(ui, model)
|| commands::render(ui, model)
|| find::render(ui, model)
|| login::render(ui, model)
|| clients::render(ui, model)
|| config::render(ui, model)
|| unmake::render(ui, model)
{
return;
}
match shown {
Column::Channels => roster::render(ui, model),
Column::Conversations => convs::render(ui, model),
Column::Conversation => {
if broad {
ui.heading(chat::HEADING);
}
chat::render(ui, model);
}
}
}
fn notice(ctx: &egui::Context, model: &mut Model) {
let Some(notice) = model.notice.clone() else {
return;
};
egui::TopBottomPanel::top("notice").show(ctx, |ui| {
ui.horizontal_top(|ui| {
if ui.button(DISMISS).clicked() {
model.dismiss();
}
ui.add(
egui::Label::new(egui::RichText::new(notice.line()).color(theme::NOTICE)).wrap(),
);
});
});
}
pub const DISMISS: &str = "×";
#[cfg(test)]
mod tests;