src/ui/layout.rs (1801B)
1 use ratatui::layout::{Constraint, Direction, Layout, Rect};
2
3 #[derive(Debug, Clone)]
4 pub struct LayoutAreas {
5 pub status_bar: Rect,
6 pub tab_bar: Rect,
7 pub library: Rect,
8 pub playlist: Rect,
9 pub info_pane: Rect,
10 pub lyrics: Rect,
11 pub progress_bar: Rect,
12 }
13
14 impl LayoutAreas {
15 pub fn compute(area: Rect, pane_widths: [u16; 3], right_split: u16) -> Self {
16 let vertical = Layout::default()
17 .direction(Direction::Vertical)
18 .constraints([
19 Constraint::Length(4), // Status bar (bordered = 2 content + 2 border)
20 Constraint::Length(3), // Tab bar (bordered)
21 Constraint::Min(10), // Dashboard
22 Constraint::Length(3), // Progress bar (bordered)
23 ])
24 .split(area);
25
26 let status_bar = vertical[0];
27 let tab_bar = vertical[1];
28 let dashboard = vertical[2];
29 let progress_bar = vertical[3];
30
31 let columns = Layout::default()
32 .direction(Direction::Horizontal)
33 .constraints([
34 Constraint::Percentage(pane_widths[0]),
35 Constraint::Percentage(pane_widths[1]),
36 Constraint::Percentage(pane_widths[2]),
37 ])
38 .split(dashboard);
39
40 let right_col = Layout::default()
41 .direction(Direction::Vertical)
42 .constraints([
43 Constraint::Percentage(right_split),
44 Constraint::Percentage(100 - right_split),
45 ])
46 .split(columns[2]);
47
48 Self {
49 status_bar,
50 tab_bar,
51 library: columns[0],
52 playlist: columns[1],
53 info_pane: right_col[0],
54 lyrics: right_col[1],
55 progress_bar,
56 }
57 }
58 }