use super::widgets::Widget;
#[derive(Debug, Clone)]
pub struct TuiLayout {
pub min_width: u16,
pub min_height: u16,
pub rec_width: u16,
pub rec_height: u16,
pub sections: Vec<Section>,
pub refresh_rate_ms: u64,
pub sparkline_points: usize,
}
impl Default for TuiLayout {
fn default() -> Self {
Self {
min_width: 80,
min_height: 24,
rec_width: 160,
rec_height: 48,
sections: vec![
Section::new("compute", "COMPUTE", 0.25),
Section::new("memory", "MEMORY", 0.20),
Section::new("dataflow", "DATA FLOW", 0.20),
Section::new("kernels", "KERNELS", 0.20),
],
refresh_rate_ms: 100,
sparkline_points: 60,
}
}
}
impl TuiLayout {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_refresh_rate(mut self, ms: u64) -> Self {
self.refresh_rate_ms = ms;
self
}
#[must_use]
pub fn check_size(&self, width: u16, height: u16) -> SizeCheck {
if width >= self.rec_width && height >= self.rec_height {
SizeCheck::Recommended
} else if width >= self.min_width && height >= self.min_height {
SizeCheck::Minimum
} else {
SizeCheck::TooSmall
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SizeCheck {
Recommended,
Minimum,
TooSmall,
}
#[derive(Debug, Clone)]
pub struct Section {
pub id: String,
pub title: String,
pub height_pct: f32,
pub widgets: Vec<Widget>,
pub collapsed: bool,
pub focused: bool,
}
impl Section {
#[must_use]
pub fn new(id: impl Into<String>, title: impl Into<String>, height_pct: f32) -> Self {
Self {
id: id.into(),
title: title.into(),
height_pct,
widgets: Vec::new(),
collapsed: false,
focused: false,
}
}
pub fn add_widget(&mut self, widget: Widget) {
self.widgets.push(widget);
}
pub fn toggle_collapsed(&mut self) {
self.collapsed = !self.collapsed;
}
}