Creates a centered dialog box with appropriate dimensions. Calculates the size based on content and positions the dialog in the center of the screen.
(title: &str, content: &[Line], r: Rect)
| 628 | /// Calculates the size based on content and positions the dialog |
| 629 | /// in the center of the screen. |
| 630 | fn create_dialog_box(title: &str, content: &[Line], r: Rect) -> Rect { |
| 631 | let content_width = content.iter().map(|line| line.width()).max().unwrap_or(0); |
| 632 | let width = title.len().max(content_width).max(40) as u16 + 4; |
| 633 | let height = (content.len() as u16) + 2; |
| 634 | |
| 635 | let popup_layout = Layout::default() |
| 636 | .direction(Direction::Vertical) |
| 637 | .constraints([ |
| 638 | Constraint::Length((r.height - height) / 2), |
| 639 | Constraint::Length(height), |
| 640 | Constraint::Length((r.height - height) / 2), |
| 641 | ]) |
| 642 | .split(r); |
| 643 | |
| 644 | Layout::default() |
| 645 | .direction(Direction::Horizontal) |
| 646 | .constraints([ |
| 647 | Constraint::Length((r.width - width) / 2), |
| 648 | Constraint::Length(width), |
| 649 | Constraint::Length((r.width - width) / 2), |
| 650 | ]) |
| 651 | .split(popup_layout[1])[1] |
| 652 | } |
| 653 | |
| 654 | /// Normalizes whitespace in text for consistent display. |
| 655 | /// |