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