use crate::ui::{Model, Rail, bar, overlay, theme};
pub const FLOOR: f32 = 180.0;
pub const COLUMN: f32 = 400.0 - crate::settings::BAR_SHUT;
pub(crate) const fn clip(rail: Rail) -> &'static str {
match rail {
Rail::Branch => "the branch rail's box",
Rail::Context => "the context rail's box",
}
}
fn bar_width(ctx: &egui::Context, model: &Model) -> f32 {
let window = ctx.screen_rect().width();
let (shut, wide) = bar::drag::shown(&model.settings, window, bar::drag::floor(ctx));
if model.bar.pinned { wide } else { shut }
}
pub fn allowance(window: f32, bar: f32) -> f32 {
bar::drag::ceiling(window).min(window - bar - COLUMN)
}
pub fn room(ctx: &egui::Context, model: &Model) -> bool {
allowance(ctx.screen_rect().width(), bar_width(ctx, model)) >= 2.0 * FLOOR
}
pub fn render(ctx: &egui::Context, model: &mut Model) {
let laid: Vec<Rail> = Rail::ALL
.into_iter()
.filter(|rail| model.railed(*rail))
.collect();
let Some(last) = laid.last().copied() else {
return;
};
let allowance = allowance(ctx.screen_rect().width(), bar_width(ctx, model));
let share = allowance / 2.0;
let mut left = allowance;
for rail in laid {
let ceiling = if rail == last { left } else { left - FLOOR };
let panel = egui::SidePanel::right(rail.name())
.resizable(true)
.default_width(share)
.width_range(FLOOR..=ceiling.max(FLOOR))
.frame(
egui::Frame::none()
.fill(theme::GROUND)
.inner_margin(egui::Margin::symmetric(theme::space::S, theme::space::XS)),
)
.show(ctx, |ui| body(ui, model, rail));
left -= panel.response.rect.width();
}
}
fn body(ui: &mut egui::Ui, model: &mut Model, rail: Rail) {
ui.data_mut(|d| d.insert_temp(egui::Id::new(clip(rail)), ui.max_rect()));
egui::ScrollArea::vertical()
.id_salt(rail.name())
.auto_shrink(false)
.show(ui, |ui| match rail {
Rail::Branch => {
let _ = crate::ui::trail::render(ui, model) || crate::ui::clear::render(ui, model);
}
Rail::Context => {
if !crate::ui::records::render(ui, model) {
overlay::name(ui, crate::ui::config::WORD);
crate::ui::config::render(ui, model);
}
}
});
}
#[cfg(test)]
mod tests;