trueno_gpu/monitor/tui_layout/
config.rs1use super::widgets::Widget;
4
5#[derive(Debug, Clone)]
11pub struct TuiLayout {
12 pub min_width: u16,
14 pub min_height: u16,
16 pub rec_width: u16,
18 pub rec_height: u16,
20 pub sections: Vec<Section>,
22 pub refresh_rate_ms: u64,
24 pub sparkline_points: usize,
26}
27
28impl Default for TuiLayout {
29 fn default() -> Self {
30 Self {
31 min_width: 80,
32 min_height: 24,
33 rec_width: 160,
34 rec_height: 48,
35 sections: vec![
36 Section::new("compute", "COMPUTE", 0.25),
37 Section::new("memory", "MEMORY", 0.20),
38 Section::new("dataflow", "DATA FLOW", 0.20),
39 Section::new("kernels", "KERNELS", 0.20),
40 ],
41 refresh_rate_ms: 100,
42 sparkline_points: 60,
43 }
44 }
45}
46
47impl TuiLayout {
48 #[must_use]
50 pub fn new() -> Self {
51 Self::default()
52 }
53
54 #[must_use]
56 pub fn with_refresh_rate(mut self, ms: u64) -> Self {
57 self.refresh_rate_ms = ms;
58 self
59 }
60
61 #[must_use]
63 pub fn check_size(&self, width: u16, height: u16) -> SizeCheck {
64 if width >= self.rec_width && height >= self.rec_height {
65 SizeCheck::Recommended
66 } else if width >= self.min_width && height >= self.min_height {
67 SizeCheck::Minimum
68 } else {
69 SizeCheck::TooSmall
70 }
71 }
72}
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq)]
76pub enum SizeCheck {
77 Recommended,
79 Minimum,
81 TooSmall,
83}
84
85#[derive(Debug, Clone)]
91pub struct Section {
92 pub id: String,
94 pub title: String,
96 pub height_pct: f32,
98 pub widgets: Vec<Widget>,
100 pub collapsed: bool,
102 pub focused: bool,
104}
105
106impl Section {
107 #[must_use]
109 pub fn new(id: impl Into<String>, title: impl Into<String>, height_pct: f32) -> Self {
110 Self {
111 id: id.into(),
112 title: title.into(),
113 height_pct,
114 widgets: Vec::new(),
115 collapsed: false,
116 focused: false,
117 }
118 }
119
120 pub fn add_widget(&mut self, widget: Widget) {
122 self.widgets.push(widget);
123 }
124
125 pub fn toggle_collapsed(&mut self) {
127 self.collapsed = !self.collapsed;
128 }
129}