use egui::Ui;
use super::splitter::{Splitter, SplitterSide};
use crate::SPACING;
pub struct Workbench<'ui> {
ui: &'ui mut Ui,
}
impl<'ui> Workbench<'ui> {
pub fn begin(ui: &'ui mut Ui) -> Self {
Self { ui }
}
pub fn top(self, body: impl FnOnce(&mut Ui)) -> Self {
let palette = crate::palette_of(self.ui.ctx());
egui::Panel::top("sauge_workbench_top")
.resizable(false)
.frame(
egui::Frame::default()
.fill(palette.bg_surface_alt)
.stroke(egui::Stroke::new(1.0, palette.border_subtle))
.inner_margin(egui::Margin::symmetric(
SPACING.s2 as i8,
(SPACING.s2 - 1.0) as i8,
)),
)
.show_inside(self.ui, |ui| {
ui.set_height(36.0);
ui.horizontal_centered(body);
});
self
}
pub fn status(self, body: impl FnOnce(&mut Ui)) -> Self {
let palette = crate::palette_of(self.ui.ctx());
egui::Panel::bottom("sauge_workbench_status")
.resizable(false)
.frame(egui::Frame::default().fill(palette.bg_surface_alt))
.show_inside(self.ui, body);
self
}
pub fn left_activity(self, body: impl FnOnce(&mut Ui)) -> Self {
let palette = crate::palette_of(self.ui.ctx());
egui::Panel::left("sauge_workbench_left_activity")
.resizable(false)
.min_size(44.0)
.max_size(44.0)
.frame(
egui::Frame::default()
.fill(palette.bg_surface_alt)
.stroke(egui::Stroke::new(1.0, palette.border_subtle))
.inner_margin(egui::Margin::ZERO),
)
.show_inside(self.ui, body);
self
}
pub fn right_activity(self, body: impl FnOnce(&mut Ui)) -> Self {
let palette = crate::palette_of(self.ui.ctx());
egui::Panel::right("sauge_workbench_right_activity")
.resizable(false)
.min_size(44.0)
.max_size(44.0)
.frame(
egui::Frame::default()
.fill(palette.bg_surface_alt)
.stroke(egui::Stroke::new(1.0, palette.border_subtle))
.inner_margin(egui::Margin::ZERO),
)
.show_inside(self.ui, body);
self
}
pub fn left(self, title: &str, open: bool, body: impl FnOnce(&mut Ui)) -> Self {
if open {
Splitter::new("sauge_workbench_left", SplitterSide::Left)
.title(title)
.default_size(240.0)
.show(self.ui, body);
}
self
}
pub fn right(self, title: &str, open: bool, body: impl FnOnce(&mut Ui)) -> Self {
if open {
Splitter::new("sauge_workbench_right", SplitterSide::Right)
.title(title)
.default_size(240.0)
.show(self.ui, body);
}
self
}
pub fn bottom(self, title: &str, open: bool, body: impl FnOnce(&mut Ui)) -> Self {
if open {
Splitter::new("sauge_workbench_bottom", SplitterSide::Bottom)
.title(title)
.default_size(200.0)
.show(self.ui, body);
}
self
}
pub fn central(self, body: impl FnOnce(&mut Ui)) {
let palette = crate::palette_of(self.ui.ctx());
egui::Frame::default()
.fill(palette.bg_app)
.show(self.ui, body);
}
}