stynx_code_tui/layout/
main_layout.rs1use ratatui::layout::{Constraint, Layout, Rect};
2
3pub struct LayoutResult {
4 pub sidebar: Option<Rect>,
5 pub messages: Rect,
6 pub thinking: Option<Rect>,
7 pub delegate: Option<Rect>,
8 pub input: Rect,
9 pub footer: Rect,
10}
11
12pub struct MainLayout;
13
14impl MainLayout {
15 pub const SIDEBAR_WIDTH: u16 = 42;
16
17 pub fn split(
18 area: Rect,
19 sidebar_visible: bool,
20 input_lines: usize,
21 thinking_lines: usize,
22 delegate_lines: usize,
23 ) -> LayoutResult {
24 let (sidebar, main) = if sidebar_visible && area.width > Self::SIDEBAR_WIDTH + 20 {
25 let chunks = Layout::horizontal([
26 Constraint::Length(Self::SIDEBAR_WIDTH),
27 Constraint::Min(1),
28 ])
29 .split(area);
30 (Some(chunks[0]), chunks[1])
31 } else {
32 (None, area)
33 };
34
35 let content = input_lines.clamp(1, 8) as u16;
36 let input_h = (content + 2).min(main.height.saturating_sub(4));
37 let thinking_h: u16 = if thinking_lines == 0 {
38 0
39 } else {
40 (1 + thinking_lines.min(4)) as u16
41 };
42 let delegate_h: u16 = delegate_lines.min(4) as u16;
43
44 let mut constraints: Vec<Constraint> = vec![Constraint::Min(1)];
45 if thinking_h > 0 { constraints.push(Constraint::Length(thinking_h)); }
46 if delegate_h > 0 { constraints.push(Constraint::Length(delegate_h)); }
47 constraints.push(Constraint::Length(input_h));
48 constraints.push(Constraint::Length(1));
49
50 let rows = Layout::vertical(constraints).split(main);
51 let mut idx = 0;
52 let messages = rows[idx]; idx += 1;
53 let thinking = if thinking_h > 0 { let r = Some(rows[idx]); idx += 1; r } else { None };
54 let delegate = if delegate_h > 0 { let r = Some(rows[idx]); idx += 1; r } else { None };
55 let input = rows[idx]; idx += 1;
56 let footer = rows[idx];
57
58 LayoutResult { sidebar, messages, thinking, delegate, input, footer }
59 }
60}