MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / draw_form

Function draw_form

crates/openshell-tui/src/ui/create_sandbox.rs:29–239  ·  view source on GitHub ↗
(frame: &mut Frame<'_>, app: &App, area: Rect)

Source from the content-addressed store, hash-verified

27// ---------------------------------------------------------------------------
28
29fn draw_form(frame: &mut Frame<'_>, app: &App, area: Rect) {
30 let t = &app.theme;
31 let Some(form) = &app.create_form else {
32 return;
33 };
34
35 let modal_width = 72u16.min(area.width.saturating_sub(4));
36
37 #[allow(clippy::cast_possible_truncation)]
38 let provider_rows = form.providers.len().clamp(1, 8) as u16;
39 // chrome = borders (2) + vertical padding (2) = 4 rows
40 let content_height = 3 + 3 + 3 + 1 + 1 + provider_rows + 1 + 1 + 1 + 1 + 1 + 1 + 1;
41 let modal_height = (content_height + 4).min(area.height.saturating_sub(2));
42 let popup_area = centered_rect(modal_width, modal_height, area);
43
44 frame.render_widget(Clear, popup_area);
45
46 let block = Block::default()
47 .title(Span::styled(" Create Sandbox ", t.heading))
48 .borders(Borders::ALL)
49 .border_style(t.accent)
50 .padding(Padding::new(2, 2, 1, 1));
51
52 let inner = block.inner(popup_area);
53 frame.render_widget(block, popup_area);
54
55 let constraints = [
56 Constraint::Length(3), // [0] Name
57 Constraint::Length(3), // [1] Image
58 Constraint::Length(3), // [2] Command
59 Constraint::Length(1), // [3] Spacer
60 Constraint::Length(1), // [4] Providers label
61 Constraint::Length(provider_rows), // [5] Provider list
62 Constraint::Length(1), // [6] Spacer
63 Constraint::Length(1), // [7] Ports (single line: label + input)
64 Constraint::Length(1), // [8] Spacer
65 Constraint::Length(1), // [9] Submit button
66 Constraint::Length(1), // [10] Status message
67 Constraint::Length(1), // [11] Spacer
68 Constraint::Length(1), // [12] Nav hint
69 Constraint::Min(0),
70 ];
71
72 let chunks = Layout::default()
73 .direction(Direction::Vertical)
74 .constraints(constraints)
75 .split(inner);
76
77 // --- Name ---
78 super::draw_text_field(
79 frame,
80 "Name",
81 &form.name,
82 "optional — auto-generated if empty",
83 form.focused_field == CreateFormField::Name,
84 chunks[0],
85 t,
86 "█",

Callers 1

drawFunction · 0.85

Calls 4

centered_rectFunction · 0.85
draw_text_fieldFunction · 0.85
lenMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected