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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//! # Layout System
//!
//! A sophisticated layout management system that provides the foundational building blocks
//! for creating responsive and flexible terminal user interfaces. This module defines the
//! core layout primitives including directional constraints, size calculations, and
//! rectangular area management that power MinUI's container-based widget positioning.
//!
//! ## Features
//!
//! - **Flexible constraints**: Fixed, percentage, minimum, and fill-based sizing
//! - **Directional layouts**: Horizontal and vertical arrangement strategies
//! - **Responsive design**: Automatic adaptation to terminal size changes
//! - **Precise positioning**: Character-accurate rectangular area calculations
//! - **Nested layouts**: Support for complex hierarchical layout structures
//! - **Space optimization**: Intelligent distribution of available space
//! - **Container integration**: Seamless integration with MinUI's widget system
//!
//! ## Layout Philosophy
//!
//! The layout system follows a CSS Flexbox-inspired model adapted for terminal interfaces.
//! Instead of pixels, all calculations use character units, providing precise control
//! over text-based layouts while maintaining the flexibility needed for responsive design.
//!
//! ## Visual Layout Model
//!
//! ```text
//! Horizontal Layout (Direction::Horizontal):
//! ┌─────────┬─────────────────┬──────────┐
//! │ Fixed │ Fill │ Fixed │
//! │ (20) │ (remaining) │ (15) │
//! └─────────┴─────────────────┴──────────┘
//!
//! Vertical Layout (Direction::Vertical):
//! ┌─────────────────────────────────────────┐
//! │ Fixed (5) │
//! ├─────────────────────────────────────────┤
//! │ │
//! │ Fill (remaining) │
//! │ │
//! ├─────────────────────────────────────────┤
//! │ Percentage (30%) │
//! └─────────────────────────────────────────┘
//! ```
//!
//! ## Basic Usage
//!
//! ```rust
//! use minui::widgets::layout::{Direction, Constraint, Rect};
//!
//! // Define a three-panel horizontal layout
//! let constraints = [
//! Constraint::Fixed(20), // Left sidebar: 20 characters wide
//! Constraint::Fill, // Main content: takes remaining space
//! Constraint::Fixed(15), // Right panel: 15 characters wide
//! ];
//!
//! let terminal_area = Rect::new(0, 0, 80, 24);
//! let layout = Layout::default()
//! .direction(Direction::Horizontal)
//! .constraints(constraints)
//! .split(terminal_area);
//!
//! // Result: Three rectangles representing the layout areas
//! // layout[0]: Rect { x: 0, y: 0, width: 20, height: 24 } (sidebar)
//! // layout[1]: Rect { x: 20, y: 0, width: 45, height: 24 } (main)
//! // layout[2]: Rect { x: 65, y: 0, width: 15, height: 24 } (right panel)
//! ```
//!
//! ## Advanced Layout Strategies
//!
//! ```rust
//! use minui::widgets::layout::{Constraint, Direction, Layout};
//!
//! // Responsive dashboard layout
//! let main_layout = Layout::default()
//! .direction(Direction::Vertical)
//! .constraints([
//! Constraint::Fixed(3), // Header bar
//! Constraint::Fill, // Content area
//! Constraint::Fixed(1), // Status bar
//! ]);
//!
//! // Content area sub-layout
//! let content_layout = Layout::default()
//! .direction(Direction::Horizontal)
//! .constraints([
//! Constraint::Percentage(0.25), // 25% for navigation
//! Constraint::Fill, // Remaining space for main content
//! Constraint::Min(20), // At least 20 characters for sidebar
//! ]);
//! ```
//!
//! ## Complex Nested Layouts
//!
//! ```rust
//! use minui::widgets::layout::{Layout, Direction, Constraint, Rect};
//!
//! // Create a sophisticated application layout
//! fn create_app_layout(terminal_size: Rect) -> Vec<Rect> {
//! let main_areas = Layout::default()
//! .direction(Direction::Vertical)
//! .margin(1)
//! .constraints([
//! Constraint::Fixed(3), // Title bar
//! Constraint::Fill, // Main content
//! Constraint::Fixed(3), // Button area
//! ])
//! .split(terminal_size);
//!
//! let content_areas = Layout::default()
//! .direction(Direction::Horizontal)
//! .constraints([
//! Constraint::Percentage(0.3), // Left panel
//! Constraint::Fill, // Center content
//! Constraint::Percentage(0.2), // Right info panel
//! ])
//! .split(main_areas[1]);
//!
//! // Combine all areas for final layout
//! vec![main_areas[0], content_areas[0], content_areas[1],
//! content_areas[2], main_areas[2]]
//! }
//! ```
//!
//! ## Constraint Types
//!
//! The layout system provides four primary constraint types for flexible sizing:
//!
//! - **Fixed(u16)**: Exact size in characters - never changes
//! - **Percentage(f32)**: Proportional to available space (0.0 to 1.0)
//! - **Min(u16)**: Minimum size that can grow if space is available
//! - **Fill**: Consumes all remaining space after other constraints
//!
//! The layout system integrates seamlessly with MinUI's container widgets, providing
//! the mathematical foundation for responsive terminal user interface design.
//! ];
//! ```
//!
//! ## Future Layout Widgets
//!
//! This module will eventually support layout widgets like:
//!
//! ```rust,ignore
//! use minui::widgets::layout::{HBox, VBox, Grid};
//!
//! // Horizontal layout
//! let hbox = HBox::new()
//! .add_child(sidebar, Constraint::Fixed(20))
//! .add_child(main_content, Constraint::Fill)
//! .add_child(info_panel, Constraint::Fixed(15));
//!
//! // Vertical layout
//! let vbox = VBox::new()
//! .add_child(header, Constraint::Fixed(3))
//! .add_child(body, Constraint::Fill)
//! .add_child(footer, Constraint::Fixed(1));
//!
//! // Grid layout
//! let grid = Grid::new(3, 3)
//! .add_widget(widget, 0, 0, 2, 1); // span 2 columns, 1 row
//! ```
// use super::Widget;
// use crate::{Result, Window};