1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use ratatui::layout::{Constraint, Direction, Layout, Rect};
#[allow(dead_code)]
pub struct AppLayout {
pub outer: Rect,
pub header: Rect,
pub middle: Rect,
pub artwork: Option<Rect>,
pub visualizer: Rect,
pub player_controls: Rect,
pub pet: Option<Rect>,
pub status: Rect,
}
impl AppLayout {
pub fn calculate(area: Rect, show_artwork: bool, show_pet: bool) -> Self {
if area.width < 10 || area.height < 8 {
return Self {
outer: area,
header: area,
middle: area,
artwork: None,
visualizer: area,
player_controls: area,
pet: None,
status: area,
};
}
// The bottom deck grows with the terminal so artwork and the pet get a
// usable box. The visualizer keeps at least 6 rows at every tier.
let deck_height = match area.height {
h if h >= 42 => 13,
h if h >= 36 => 12,
h if h >= 30 => 11,
h if h >= 26 => 9,
_ => 8,
};
// Vertical split: Header (3 rows), Full-width Visualizer (min 6 rows), Bottom Deck (8-13 rows), Status (3 rows)
let vert_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(3), // Header / Nav
Constraint::Min(6), // Full-width Visualizer
Constraint::Length(deck_height), // Bottom Deck (Artwork + Controls + Pet)
Constraint::Length(3), // Status Bar
])
.split(area);
let header = vert_chunks[0];
let visualizer = vert_chunks[1];
let middle = visualizer;
let deck_area = vert_chunks[2];
let status = vert_chunks[3];
// Bottom Deck horizontal split: Artwork on left, Controls in middle, Pet on right
let inner_h = deck_area.height.saturating_sub(2);
// Side boxes are twice as wide as they are tall so their contents come
// out roughly square on a terminal cell grid.
let square_width = inner_h * 2 + 2;
let box_width = square_width.min(deck_area.width / 3);
// With both side boxes on screen they have to leave the controls 35
// columns, so they may need to be narrower than a lone box would be.
let paired_width = box_width.min(deck_area.width.saturating_sub(35) / 2);
// Terminal width below 55 collapses both side boxes to prioritize player controls
let (has_art, has_pet) = if deck_area.width < 55 {
(false, false)
} else {
match (show_artwork, show_pet) {
(true, true) => {
if paired_width >= 10 {
(true, true)
} else {
(true, false)
}
}
(true, false) => (true, false),
(false, true) => (false, true),
(false, false) => (false, false),
}
};
let (artwork, player_controls, pet) = match (has_art, has_pet) {
(true, true) => {
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(paired_width),
Constraint::Min(30),
Constraint::Length(paired_width),
])
.split(deck_area);
(Some(chunks[0]), chunks[1], Some(chunks[2]))
}
(true, false) => {
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(box_width),
Constraint::Min(30),
])
.split(deck_area);
(Some(chunks[0]), chunks[1], None)
}
(false, true) => {
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Min(30),
Constraint::Length(box_width),
])
.split(deck_area);
(None, chunks[0], Some(chunks[1]))
}
(false, false) => (None, deck_area, None),
};
Self {
outer: area,
header,
middle,
artwork,
visualizer,
player_controls,
pet,
status,
}
}
}