MCPcopy Create free account
hub / github.com/Autoparallel/learner / create_dialog_box

Function create_dialog_box

crates/learnerd/src/tui/ui.rs:630–652  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

628/// Calculates the size based on content and positions the dialog
629/// in the center of the screen.
630fn 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///

Callers 1

draw_dialogMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected