Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Start the Advanced console's prompt box at three lines (#979)

Justin John8a587bc0b3ad
diff --git a/crates/ui-egui/src/chat.rs b/crates/ui-egui/src/chat.rs
index 8ee0323f..c3395bdb 100644
--- a/crates/ui-egui/src/chat.rs
+++ b/crates/ui-egui/src/chat.rs
@@ -224,7 +224,9 @@ pub fn conversation(app: &mut CraftApp, ui: &mut Ui, dense: bool) {
// The history gets exactly what the composer leaves (its height is measured last frame), so
// a panel never grows to fit us.
let comp_id = ui.id().with(("composer-h", dense));
- let comp_h = ui.data(|d| d.get_temp::<f32>(comp_id)).unwrap_or(if dense { 48.0 } else { 70.0 });
+ // Before the first measure, a guess that isn't short: anything left over on that frame grows
+ // the console's panel, and it keeps that size.
+ let comp_h = ui.data(|d| d.get_temp::<f32>(comp_id)).unwrap_or(if dense { 125.0 } else { 70.0 });
// The item spacing after the history counts too. Anything here that comes out taller than the
// space given makes the agent console's panel grow by that much every frame, until it reaches
// its maximum and the top of its tab strip is cut off.
@@ -334,7 +336,7 @@ fn composer(app: &mut CraftApp, ui: &mut Ui, width: f32, dense: bool) {
crate::prompt_box::PromptBox {
name: "Ask a question",
hint,
- rows: (1, if dense { 4 } else { 8 }),
+ rows: if dense { (3, 4) } else { (1, 8) },
attach: None,
previews: &[],
stop_button: answering.then_some("Stop"),
diff --git a/crates/ui-egui/src/workbench.rs b/crates/ui-egui/src/workbench.rs
index 79021a16..b6162b1f 100644
--- a/crates/ui-egui/src/workbench.rs
+++ b/crates/ui-egui/src/workbench.rs
@@ -111,8 +111,10 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
.frame(egui::Frame::new().fill(t.chrome).inner_margin(Margin { left: 8, right: 10, top: 10, bottom: 8 }))
.show(ui, |ui| crate::guard_ui(ui, "inspector", |ui| right(app, ui)));
let mut open = app.state.bottom_open;
- egui::Panel::bottom("wb-bottom")
- .default_size(240.0)
+ // A new id: nobody could resize the old one, so its saved sizes were never anyone's choice.
+ egui::Panel::bottom("wb-console")
+ .resizable(true)
+ .default_size(280.0)
.size_range(120.0..=600.0)
.frame(egui::Frame::new().fill(t.chrome).inner_margin(Margin { left: 8, right: 10, top: 4, bottom: 8 }))
.show_collapsible(ui, &mut open, |ui| crate::guard_ui(ui, "bottom", |ui| bottom(app, ui)));
diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rs
index 461aa339..1f490f0c 100644
--- a/crates/ui-egui/tests/smoke.rs
+++ b/crates/ui-egui/tests/smoke.rs
@@ -1042,6 +1042,83 @@ fn the_agent_console_keeps_its_size() {
assert_eq!(h.get_by_label("Agent").rect().top(), top, "the agent console grew while nothing changed");
}
+#[test]
+fn the_agent_console_prompt_box_starts_tall_and_grows_inside_the_window() {
+ // #942: it started one line tall, too short to read what was being typed.
+ let mut h = harness_sized(egui::vec2(1920.0, 1030.0), || {
+ let mut a = demo::app(demo::engine(Mode::Experienced, true));
+ demo::fill_workbench(&mut a);
+ a
+ });
+ h.run_steps(4);
+ assert!(wait(&mut h, |a| a.jobs.running().all(|j| !j.visible)), "the lists finished loading");
+ h.get_by_label("Agent").click();
+ h.run_steps(4);
+ let empty = h.get_by_label("Ask a question").rect().height();
+ assert!(empty >= 50.0, "room for three lines, got {empty}");
+ let hint = "Enter to send · Shift+Enter for a new line";
+
+ // Eight lines fit: the field isn't scrolled, so its rect is what's on screen.
+ h.state_mut().state.input = ["a line"; 8].join("\n");
+ h.run_steps(6);
+ let field = h.get_by_label("Ask a question").rect();
+ let (tabs, below) = (h.get_by_label("Agent").rect(), h.get_by_label(hint).rect());
+ assert!(field.height() > empty * 2.0, "it grows as lines are added: {} after {empty}", field.height());
+ assert!(field.top() >= tabs.bottom() && field.bottom() <= below.top(), "all eight lines show: tabs={tabs:?}, field={field:?}, hint={below:?}");
+
+ // Past what fits it scrolls, and the console settles with its tabs and send row in the window.
+ h.state_mut().state.input = ["a line"; 60].join("\n");
+ h.run_steps(6);
+ let (tabs, below) = (h.get_by_label("Agent").rect(), h.get_by_label(hint).rect());
+ h.run_steps(20);
+ assert_eq!(h.get_by_label("Agent").rect(), tabs, "the console settles");
+ assert!(tabs.top() >= 0.0 && below.bottom() <= 1030.0, "the tabs and the send row stay in the window: tabs={tabs:?}, hint={below:?}");
+}
+
+#[test]
+fn the_agent_console_leaves_room_for_the_code_in_a_small_window() {
+ let mut h = harness_sized(egui::vec2(1000.0, 500.0), || {
+ let mut a = demo::app(demo::engine(Mode::Experienced, true));
+ demo::fill_workbench(&mut a);
+ a
+ });
+ h.run_steps(4);
+ assert!(wait(&mut h, |a| a.jobs.running().all(|j| !j.visible)), "the lists finished loading");
+ h.get_by_label("Agent").click();
+ h.run_steps(4);
+ let top = h.get_by_label("Agent").rect().top();
+ assert!(top > 200.0, "the console's tabs start at {top} of 500");
+}
+
+#[test]
+fn the_agent_console_opens_at_its_default_size() {
+ // The first frame guessed the prompt box too short; the panel grew to fit and saved that size.
+ let mut h = harness_sized(egui::vec2(1920.0, 1030.0), || {
+ let mut a = demo::app(demo::engine(Mode::Experienced, true));
+ demo::fill_workbench(&mut a);
+ a
+ });
+ h.run_steps(4);
+ let top = h.get_by_label("Agent").rect().top();
+ assert!((750.0..765.0).contains(&top), "a 280-point console's tabs start just below 750, got {top}");
+
+ // Dragging its top edge resizes it, and it stays that size (#942).
+ let edge = egui::pos2(900.0, 750.0);
+ h.hover_at(edge);
+ h.step();
+ h.input_mut().events.push(egui::Event::PointerButton { pos: edge, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE });
+ h.step();
+ let up = edge - egui::vec2(0.0, 100.0);
+ h.hover_at(up);
+ h.step();
+ h.input_mut().events.push(egui::Event::PointerButton { pos: up, button: egui::PointerButton::Primary, pressed: false, modifiers: egui::Modifiers::NONE });
+ h.run_steps(10);
+ let dragged = h.get_by_label("Agent").rect().top();
+ assert!((650.0..665.0).contains(&dragged), "its edge dragged up to 650, the tabs just below it, got {dragged}");
+ h.run_steps(10);
+ assert_eq!(h.get_by_label("Agent").rect().top(), dragged, "it stays at that size");
+}
+
#[test]
fn command_palette_opens_and_lists_tools() {
let mut h = harness(|| demo::app(demo::engine(Mode::Experienced, true)));
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 56d93973..df123e79 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -759,6 +759,8 @@ Gaps found while using the app for real projects.
— claimed: sanketdofe, branch feature/r2.9-macos-menu-bar
- [ ] macOS: an Edit menu (Undo, Cut, Copy, Paste, Select All). The keys work in text boxes, but
the system's Edit items need the text box to answer them, so they'd show greyed out today
+- [x] The Advanced console's prompt box starts tall enough to read what's typed (#942)
+ — claimed: justinjohn0306, branch bugfix/942-console-input-height
### R2.10 Pinned builds
Owner: maintainers · Status: in progress
diff --git a/docs/pitfalls.md b/docs/pitfalls.md
index 16895429..ebd3b7b9 100644
--- a/docs/pitfalls.md
+++ b/docs/pitfalls.md
@@ -478,6 +478,8 @@ The agent console's panel grows to fit its content, so it grew 17 points every f
maximum, and then the top of its tabs was cut off. When a part is sized to fill what's left, count
the item spacing and use `horizontal_top` for tall rows, and test that the panel's size holds still
over several frames.
+Its first frame had no measure yet and guessed 48 points for a box of 84 or more, so the panel grew
+on that frame, and egui saved the larger size (#942). Where a panel grows to fit, guess too tall.
**A library default that blinked over a text field.** egui's scroll areas fade their edge when
there's more below; the prompt box's one measured a few points of overflow on the frame after each