SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Agent chat composer: one margin, input box fills its area; hint stays on one line (#7268)
bherbruck15f74b7981da
diff --git a/crates/ui-egui/src/agent_chat/panel.rs b/crates/ui-egui/src/agent_chat/panel.rsindex 88c0fcaf3c..e9ce079ab9 100644--- a/crates/ui-egui/src/agent_chat/panel.rs+++ b/crates/ui-egui/src/agent_chat/panel.rs@@ -847,8 +847,8 @@ fn desktop_body(app: &mut SolveApp, ui: &mut egui::Ui) {let frame = Container::new(ui.ctx(), Surface::Viewport).edge_frame(egui::Color32::TRANSPARENT);let composer = Container::new(ui.ctx(), Surface::Viewport).edge(Id::new("sc_agent_chat_composer"), Edge::Bottom);composer.resizable(false).show_separator_line(false).frame(frame).show(ui, |ui| {- ui_kit::assistant_composer_footer(ui, |ui| {- ui_kit::assistant_composer(ui, focused, |ui| {+ let footer = ui_kit::assistant_composer_footer(ui, |ui| {+ let boxed = ui_kit::assistant_composer(ui, focused, |ui| {// What Pick context chose for this message, each item with an ×.if !app.agent_chat.picked_context.is_empty() {let tray = app.agent_chat.picked_context.clone();@@ -987,7 +987,9 @@ fn desktop_body(app: &mut SolveApp, ui: &mut egui::Ui) {},);});+ crate::scenario::publish_rect("agent_chat:composer_box", boxed.response.rect);});+ crate::scenario::publish_rect("agent_chat:composer_footer", footer.response.rect);});if let Some(at) = remove_picked_at {remove_picked(app, at);diff --git a/crates/ui-egui/src/agent_chat/tests.rs b/crates/ui-egui/src/agent_chat/tests.rsindex 56828778ec..4eabbd4d87 100644--- a/crates/ui-egui/src/agent_chat/tests.rs+++ b/crates/ui-egui/src/agent_chat/tests.rs@@ -2844,3 +2844,61 @@ fn a_screenshot_card_hides_the_path_until_details() {h.frames(3);assert!(h.widget("Result").is_some() && h.widget(path).is_some(), "Details holds the full path");}++/// The composer's input box fills its parent composer area on all four sides, in every layout:+/// the only inset left is the text's own padding inside the box (no second margin around it).+#[test]+fn the_composer_box_fills_its_parent_in_every_layout() {+ use crate::scenario::rect_of;+ for (layout, popped) in [("floating", false), ("docked", false), ("floating", true), ("docked", true)] {+ let mut h = narrow_chat();+ h.call("ui.resize", json!({"width": 1600, "height": 1000}));+ h.call("ui.set", json!({"layout": layout}));+ h.app.preferences.agent_chat_popped = popped;+ h.app.agent_chat.state = Some(State::Ready);+ h.frames(4);+ let footer = rect_of("agent_chat:composer_footer").unwrap_or_else(|| panic!("{layout} popped={popped}: the composer area"));+ let boxed = rect_of("agent_chat:composer_box").expect("the input box");+ let (l, r, t, b) =+ (boxed.left() - footer.left(), footer.right() - boxed.right(), boxed.top() - footer.top(), footer.bottom() - boxed.bottom());+ for (edge, gap) in [("left", l), ("right", r), ("top", t), ("bottom", b)] {+ assert!(gap.abs() <= 1.0, "{layout} popped={popped}: box {edge} edge is {gap} from its parent ({boxed:?} in {footer:?})");+ }+ let input = rect_of("agent_chat:input").expect("the text");+ assert!(input.left() > boxed.left() + 2.0, "{layout} popped={popped}: the text keeps its own padding");+ let send = rect_of("agent_chat:send").expect("Send");+ assert!(boxed.contains_rect(send), "{layout} popped={popped}: Send stays inside the box");+ }+}++/// The composer hint (idle and busy, in every language) stays on one row, even at the narrowest+/// panel, and is cut with an ellipsis instead of wrapping.+#[test]+fn the_composer_hint_stays_on_one_row_at_the_narrowest_width() {+ let mut h = narrow_chat();+ h.app.agent_chat.state = Some(State::Ready);+ h.frames(4);+ let width = crate::scenario::rect_of("agent_chat:input").expect("the text box").width();+ let ctx = crate::fonts::test_context();+ let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../assets/locales");+ let mut checked = 0;+ for entry in std::fs::read_dir(dir).unwrap().filter_map(Result::ok) {+ let path = entry.path();+ if path.extension().is_none_or(|x| x != "json") {+ continue;+ }+ let language = path.file_stem().unwrap().to_string_lossy().into_owned();+ let _scope = crate::i18n::scope(&language);+ for key in ["ui.agent_chat_placeholder", "ui.agent_chat_placeholder_busy"] {+ let hint = crate::i18n::tr(key).to_owned();+ let mut rows = 0;+ let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {+ rows = crate::ui_kit::assistant_hint_galley(ui, &hint, width - 2.0 * crate::theme::Tokens::get().form_inset).rows.len();+ });+ output.textures_delta.clear();+ assert_eq!(rows, 1, "{language} {key} at {width} wide: {hint}");+ checked += 1;+ }+ }+ assert!(checked >= 20, "every language was checked");+}diff --git a/crates/ui-egui/src/ui_kit/assistant.rs b/crates/ui-egui/src/ui_kit/assistant.rsindex e20a333c01..8a9f28d89d 100644--- a/crates/ui-egui/src/ui_kit/assistant.rs+++ b/crates/ui-egui/src/ui_kit/assistant.rs@@ -232,21 +232,37 @@ pub(crate) fn assistant_approval<R>(ui: &mut Ui, title: &str, body: impl FnOnce(#[cfg(any(not(target_arch = "wasm32"), test))]pub(crate) fn assistant_input(ui: &mut Ui, id: egui::Id, value: &mut String, hint: &str) -> Response {let t = Tokens::get();+ // The hint is painted here, not by the TextEdit: a multiline edit wraps its hint onto+ // several rows, and the hint must stay on one row, ending in an ellipsis when it does not fit.let mut response = ui.add(super::fields::text_input(egui::TextEdit::multiline(value)).id(id).frame(egui::Frame::NONE).background_color(egui::Color32::TRANSPARENT)- .hint_text(hint).desired_rows(2).desired_width(f32::INFINITY).min_size(vec2(0.0, t.control_height + t.space_8)).font(egui::FontId::proportional(t.font_label)),);super::text_menu::menu(ui, &mut response, value, super::text_menu::Field::LINES);+ if value.is_empty() {+ let width = (response.rect.width() - 2.0 * t.form_inset).max(0.0);+ let galley = assistant_hint_galley(ui, hint, width);+ let pos = egui::pos2(response.rect.left() + t.form_inset, response.rect.center().y - galley.size().y / 2.0);+ ui.painter().galley(pos, galley, ui.visuals().weak_text_color());+ }response}+/// The composer hint laid out on one row of at most `width`, cut with an ellipsis.+#[cfg(any(not(target_arch = "wasm32"), test))]+pub(crate) fn assistant_hint_galley(ui: &Ui, hint: &str, width: f32) -> std::sync::Arc<egui::Galley> {+ let t = Tokens::get();+ let mut job = egui::text::LayoutJob::simple_singleline(hint.to_owned(), egui::FontId::proportional(t.font_label), ui.visuals().weak_text_color());+ job.wrap = egui::text::TextWrapping { max_width: width, max_rows: 1, break_anywhere: true, overflow_character: Some('\u{2026}') };+ ui.fonts_mut(|f| f.layout_job(job))+}+/// Compact right-aligned approval actions; wrapping grows by control rows, not the remaining card height.#[cfg(any(not(target_arch = "wasm32"), test))]pub(crate) fn assistant_actions<R>(ui: &mut Ui, add: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {@@ -258,6 +274,13 @@ pub(crate) fn assistant_actions<R>(ui: &mut Ui, add: impl FnOnce(&mut Ui) -> R))}+/// Bottom corners follow the window; the top meets the footer rule square.+#[cfg(any(not(target_arch = "wasm32"), test))]+fn composer_corners(t: &Tokens) -> egui::CornerRadius {+ let r = t.radius_xl.saturating_sub(1);+ egui::CornerRadius { nw: 0, ne: 0, sw: r, se: r }+}+/// Composer's rounded field surface with an accent border only while focused.#[cfg(any(not(target_arch = "wasm32"), test))]pub(crate) fn assistant_composer<R>(ui: &mut Ui, focused: bool, add: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {@@ -265,7 +288,7 @@ pub(crate) fn assistant_composer<R>(ui: &mut Ui, focused: bool, add: impl FnOnceegui::Frame::NONE.fill(t.control_fill).stroke(if focused { egui::Stroke::new(1.0, t.form_primary) } else { t.control_border_stroke(t.control_border) })- .corner_radius(t.radius_xl)+ .corner_radius(composer_corners(&t)).inner_margin(egui::Margin::symmetric(t.space_10 as i8, t.space_8 as i8)).show(ui, |ui| {ui.set_min_width(ui.available_width().max(0.0));@@ -303,8 +326,10 @@ pub(crate) fn assistant_composer_footer<R>(ui: &mut Ui, add: impl FnOnce(&mut Uilet t = Tokens::get();let output = egui::Frame::NONE.fill(t.dialog_footer)- .corner_radius(egui::CornerRadius { nw: 0, ne: 0, sw: t.radius_xl.saturating_sub(1), se: t.radius_xl.saturating_sub(1) })- .inner_margin(t.space_10)+ .corner_radius(composer_corners(&t))+ // No margin: the composer box inside fills this footer edge to edge. The text padding+ // lives on the box itself, so there is one inset, not two.+ .inner_margin(0).show(ui, add);t.secondary_hline(ui.painter(), output.response.rect.x_range(), output.response.rect.top(), t.dialog_rule);output