oxicode_vtui/design/layout/
mod.rs1pub mod agent;
17pub mod config;
18pub mod shortcuts_bar;
19pub mod welcome;
20
21pub use agent::{
26 AUTO_COMPACT_MAX_ROWS, ActivePane, AgentViewLayout, LayoutInput, PaneAreas,
27 SHORT_TERMINAL_ROWS, effective_compact,
28};
29pub use config::{LayoutConfig, ScrollbarConfig};
30pub use shortcuts_bar::{
31 CompactConfig, HintItem, PendingHint, ShortcutBarStyling, ShortcutsBar, compute_effective_hints,
32};
33
34pub use welcome::{HERO_BOX_MIN_WIDTH, PROMPT_HEIGHT, WelcomeLayout, WelcomePromptFocus};
35
36use ratatui::layout::Rect;
41
42use crate::design::constants::{COMPACT_MAX_COLS, COMPACT_MAX_ROWS, WIDE_MIN_COLS, WIDE_MIN_ROWS};
43
44#[derive(Clone, Copy, Debug, PartialEq, Eq)]
49pub enum LayoutMode {
50 Compact,
52 Standard,
54 Wide,
56}
57
58impl LayoutMode {
59 pub(crate) fn from_area(area: Rect) -> Self {
61 if area.width <= COMPACT_MAX_COLS || area.height <= COMPACT_MAX_ROWS {
62 LayoutMode::Compact
63 } else if area.width >= WIDE_MIN_COLS && area.height >= WIDE_MIN_ROWS {
64 LayoutMode::Wide
65 } else {
66 LayoutMode::Standard
67 }
68 }
69
70 pub(crate) fn show_borders(self) -> bool {
72 !matches!(self, LayoutMode::Compact)
73 }
74
75 pub(crate) fn show_titles(self) -> bool {
77 !matches!(self, LayoutMode::Compact)
78 }
79
80 pub(crate) fn allow_sidebar(self) -> bool {
82 matches!(self, LayoutMode::Wide)
83 }
84
85 pub(crate) fn show_logs_panel(self) -> bool {
87 !matches!(self, LayoutMode::Compact)
88 }
89
90 pub(crate) fn footer_height(self) -> u16 {
92 0
93 }
94
95 pub(crate) fn show_footer(self) -> bool {
97 false
98 }
99
100 pub(crate) fn max_header_percent(self) -> f32 {
102 match self {
103 LayoutMode::Compact => 0.2,
104 _ => 0.3,
105 }
106 }
107
108 pub(crate) fn sidebar_width_percent(self) -> u16 {
110 match self {
111 LayoutMode::Wide => 25,
112 _ => 0,
113 }
114 }
115}
116
117#[cfg(test)]
118mod tests {
119 use super::*;
120
121 #[test]
122 fn compact_mode_for_small_terminals() {
123 assert_eq!(
124 LayoutMode::from_area(Rect::new(0, 0, 60, 20)),
125 LayoutMode::Compact
126 );
127 assert_eq!(
128 LayoutMode::from_area(Rect::new(0, 0, 80, 15)),
129 LayoutMode::Compact
130 );
131 }
132
133 #[test]
134 fn standard_mode_for_normal_terminals() {
135 assert_eq!(
136 LayoutMode::from_area(Rect::new(0, 0, 100, 22)),
137 LayoutMode::Standard
138 );
139 }
140
141 #[test]
142 fn wide_mode_for_large_terminals() {
143 assert_eq!(
144 LayoutMode::from_area(Rect::new(0, 0, 140, 30)),
145 LayoutMode::Wide
146 );
147 }
148}