Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Render: the Cancel button keeps its full label during a render (#11222) (#11241)

HiroKenEzb227924be928
diff --git a/crates/ui-egui/src/render_ui/mod.rs b/crates/ui-egui/src/render_ui/mod.rs
index c9ffadd321..df191da9de 100644
--- a/crates/ui-egui/src/render_ui/mod.rs
+++ b/crates/ui-egui/src/render_ui/mod.rs
@@ -188,7 +188,11 @@ pub(crate) fn overlays(app: &mut SolveApp, ui: &mut egui::Ui) {
}
if crate::render_workspace::job_busy(app) {
let pill = Container::navigation_card(ui.ctx(), egui::Id::new("sc_render_progress"), free.center_top(), egui::Align2::CENTER_TOP, |ui| {
- crate::render_workspace::progress_pill(app, ui);
+ // Bound the row by the canvas, not by the card's size last frame: a longer status or
+ // name would otherwise squeeze Cancel or cut a name that has room (#11222).
+ let t = Tokens::get();
+ ui.set_max_width((free.width() - t.space_24).min(t.form_card_width * 2.0).max(0.0));
+ crate::render_workspace::progress_pill(app, ui, "render:progress");
});
crate::shell::register_panel(app, "render:progress-pill", Some(pill.response.rect), None);
crate::scenario::publish_rect("render:progress-pill", pill.response.rect);
diff --git a/crates/ui-egui/src/render_workspace.rs b/crates/ui-egui/src/render_workspace.rs
index fe123f38c9..63d52e5df0 100644
--- a/crates/ui-egui/src/render_workspace.rs
+++ b/crates/ui-egui/src/render_workspace.rs
@@ -2351,7 +2351,8 @@ pub(crate) fn apply_command(app: &mut SolveApp, id: &str, reply: &serde_json::Va
Ok(())
}
-pub(crate) fn progress_pill(app: &mut SolveApp, ui: &mut egui::Ui) -> bool {
+/// `key` names the row's scenario handles (`ui_kit::progress_action`).
+pub(crate) fn progress_pill(app: &mut SolveApp, ui: &mut egui::Ui, key: &str) -> bool {
if !ribbon::busy(app) {
return false;
}
@@ -2366,8 +2367,8 @@ pub(crate) fn progress_pill(app: &mut SolveApp, ui: &mut egui::Ui) -> bool {
let fraction = (done as f64 / total as f64).clamp(0.0, 1.0) as f32;
let phase_key = format!("render.image_{phase}");
let name = app.render_workspace.view.job_shot.as_ref().unwrap_or(&app.render_workspace.view.name).clone();
- let cancel =
- crate::ui_kit::progress_action(ui, &format!("{name} · {} · {:.0}%", app.tr(&phase_key), fraction * 100.0), fraction, app.tr_label("Cancel"));
+ let status = format!("· {} · {:.0}%", app.tr(&phase_key), fraction * 100.0);
+ let cancel = crate::ui_kit::progress_action(ui, key, &name, &status, fraction, app.tr_label("Cancel"));
crate::scenario::publish_target("render:progress-cancel", cancel.rect);
if cancel.clicked() {
app.start("render.cancel");
diff --git a/crates/ui-egui/src/render_workspace_output.rs b/crates/ui-egui/src/render_workspace_output.rs
index 8c8c834330..899e35f654 100644
--- a/crates/ui-egui/src/render_workspace_output.rs
+++ b/crates/ui-egui/src/render_workspace_output.rs
@@ -584,7 +584,7 @@ fn render_controls(app: &mut SolveApp, ui: &mut egui::Ui) {
);
ui_kit::completion_text(ui, &text, app.render_workspace.view.completed.is_some());
if super::ribbon::busy(app) {
- super::progress_pill(app, ui);
+ super::progress_pill(app, ui, "render:output-progress");
return;
}
ui.horizontal_wrapped(|ui| {
diff --git a/crates/ui-egui/src/render_workspace_tests.rs b/crates/ui-egui/src/render_workspace_tests.rs
index f777cbc5a3..c45f4fe440 100644
--- a/crates/ui-egui/src/render_workspace_tests.rs
+++ b/crates/ui-egui/src/render_workspace_tests.rs
@@ -5924,6 +5924,60 @@ fn output_viewer_copy_uses_retained_final_pixels_and_refuses_missing_or_oversize
assert_eq!(undo, h.app.session.undo.len());
}
+/// #11222: during a render, Cancel keeps its whole label below and from 10 %. A name that fits
+/// is shown whole as the percentage grows; a long one is cut instead, and the row stays in the canvas.
+/// In a window too narrow for the row, Cancel still shows whole.
+#[test]
+fn progress_pill_cancel_keeps_its_label_and_a_long_name_gives_way() {
+ let mut h = output_viewer_fixture();
+ h.app.render_workspace.view.draft.width = 512;
+ h.app.render_workspace.view.draft.height = 512;
+ h.app.render_workspace.view.name = "A".into();
+ ribbon::perform_job(&mut h.app, "render.start").unwrap();
+ let job = h.app.render_workspace.view.job.unwrap();
+ h.frames(3);
+ let whole = crate::scenario::rect_of("render:progress:cancel").unwrap().width();
+ let fraction = |h: &mut Harness| {
+ let status = h.app.session.execute("render.status", &json!({"job":job})).unwrap();
+ status["progress"]["done"].as_f64().unwrap() / status["progress"]["total"].as_f64().unwrap().max(1.0)
+ };
+ assert!(fraction(&mut h) < 0.1);
+ let long = "A very long shot name that will not fit beside the progress meter ".repeat(4);
+ let host = h.app.session.render_job_host().unwrap().clone();
+ for below in [true, false] {
+ if !below {
+ for _ in 0..100_000 {
+ if fraction(&mut h) >= 0.1 {
+ break;
+ }
+ host.pump(64).unwrap();
+ }
+ let reached = fraction(&mut h);
+ assert!((0.1..1.0).contains(&reached), "{reached}");
+ }
+ for name in ["Bracket front view", long.as_str()] {
+ h.app.render_workspace.view.job_shot = Some(name.into());
+ h.frames(3);
+ let cancel = crate::scenario::rect_of("render:progress:cancel").unwrap();
+ let pill = crate::scenario::rect_of("render:progress-pill").unwrap();
+ let shown = crate::scenario::rect_of("render:progress:name").unwrap();
+ let case = format!("below 10 %: {below}, {} characters", name.len());
+ assert!((cancel.width() - whole).abs() < 0.5, "{case}: Cancel {} wide, whole {whole}", cancel.width());
+ assert!(pill.contains_rect(cancel), "{case}: {cancel:?} outside {pill:?}");
+ assert!(shown.right() < cancel.left(), "{case}");
+ let cut = crate::scenario::count_of("render:progress:name:cut");
+ assert_eq!(cut, Some(if name == long { 1.0 } else { 0.0 }), "{case}");
+ assert!(h.app.viewport.rect.unwrap().contains_rect(pill), "{case}: {pill:?}");
+ }
+ }
+ // A window too narrow for the whole row: the name is cut and Cancel still shows whole.
+ h.call("ui.resize", json!({"width": 480, "height": 600}));
+ h.frames(3);
+ let cancel = crate::scenario::rect_of("render:progress:cancel").unwrap();
+ assert!((cancel.width() - whole).abs() < 0.5, "narrow window: Cancel {} wide, whole {whole}", cancel.width());
+ assert_eq!(crate::scenario::count_of("render:progress:name:cut"), Some(1.0));
+}
+
#[test]
fn output_viewer_progress_keeps_stage_tools_and_cancel_cancels_without_closing_viewer() {
let mut h = output_viewer_fixture();
diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rs
index b638d0f412..65ce3d0abb 100644
--- a/crates/ui-egui/src/ui_kit/gallery.rs
+++ b/crates/ui-egui/src/ui_kit/gallery.rs
@@ -242,7 +242,7 @@ const ELEMENTS: &[Element] = &[
number_pair(ui, "Size", [&mut w, &mut h], 1..=16384, 1.0, "");
}),
element!("progress_action", |ui, _| {
- progress_action(ui, "Rendering · 62%", 0.62, "Cancel");
+ progress_action(ui, "gallery:progress", "Rendering", "· 62%", 0.62, "Cancel");
}),
element!("settings_choice_row", |ui, _| {
settings_choice_row(
diff --git a/crates/ui-egui/src/ui_kit/status.rs b/crates/ui-egui/src/ui_kit/status.rs
index 3785eb88c5..1878a4c667 100644
--- a/crates/ui-egui/src/ui_kit/status.rs
+++ b/crates/ui-egui/src/ui_kit/status.rs
@@ -214,15 +214,41 @@ pub(crate) fn check_status_line(ui: &mut egui::Ui, key: &str, label: &str, statu
response
}
-/// Single-row render status for a shared Navigation card. The caller dispatches Cancel.
-pub(crate) fn progress_action(ui: &mut egui::Ui, caption: &str, fraction: f32, cancel: &str) -> egui::Response {
+/// Single-row render status for a shared Navigation card: name, status, meter and Cancel, within
+/// the width the caller's `ui` offers. Cancel and the status always show in full; a long name
+/// gives way first (cut with an ellipsis, its full text on hover), then the meter narrows
+/// (#11222). Publishes `dialog:progress:KEY`, `KEY:name` with `KEY:name:cut`, and `KEY:cancel`.
+/// The caller dispatches Cancel. Tokens: `font_label, form_ink, space_24, control_height`.
+pub(crate) fn progress_action(ui: &mut egui::Ui, key: &str, name: &str, status: &str, fraction: f32, cancel: &str) -> egui::Response {
let t = Tokens::get();
ui.horizontal(|ui| {
- super::text(ui, caption, super::Text::Inline);
- ui.allocate_ui_with_layout(vec2(t.space_24 * 6.0, t.control_height), egui::Layout::left_to_right(egui::Align::Center), |ui| {
- progress(ui, "render-pill", fraction);
- });
- super::button(ui, cancel, super::Button::Normal)
+ let font = egui::FontId::proportional(t.font_label);
+ let measure = |ui: &egui::Ui, text: &str| ui.painter().layout_no_wrap(text.to_owned(), font.clone(), t.form_ink).size().x.ceil();
+ let gap = ui.spacing().item_spacing.x;
+ let status_width = measure(ui, status);
+ let cancel_width = measure(ui, cancel) + 2.0 * ui.spacing().button_padding.x;
+ let (meter_full, meter_min, name_min) = (t.space_24 * 6.0, t.space_24 * 2.0, t.space_24);
+ // What the name and the meter share once the status, Cancel and the gaps have their room.
+ let shared = (ui.available_width() - status_width - cancel_width - 3.0 * gap).max(0.0);
+ let name_natural = measure(ui, name);
+ // The name keeps its length while the full meter still fits beside it; past that it is
+ // cut, down to `name_min`, and only then does the meter narrow, down to `meter_min`.
+ let name_width = name_natural.min((shared - meter_full).max(name_min));
+ let meter = (shared - name_width).min(meter_full).max(meter_min);
+ let fixed = |ui: &mut egui::Ui, width: f32, add: &dyn Fn(&mut egui::Ui) -> egui::Response| {
+ ui.allocate_ui_with_layout(vec2(width, t.control_height), egui::Layout::left_to_right(egui::Align::Center), add).inner
+ };
+ let shown = fixed(ui, name_width, &|ui| super::text(ui, name, super::Text::Inline));
+ let cut = name_natural > name_width + 0.5;
+ crate::scenario::publish_rect(&format!("{key}:name"), shown.rect);
+ crate::scenario::publish_count(&format!("{key}:name:cut"), f64::from(u8::from(cut)));
+ fixed(ui, status_width, &|ui| super::text(ui, status, super::Text::Inline));
+ fixed(ui, meter, &|ui| progress(ui, key, fraction));
+ // Cancel keeps its whole label whatever room the row has left.
+ ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
+ let response = super::button(ui, cancel, super::Button::Normal);
+ crate::scenario::publish_rect(&format!("{key}:cancel"), response.rect);
+ response
})
.inner
}
diff --git a/docs/ui-kit.md b/docs/ui-kit.md
index 7422f22f8d..e3ccb5562b 100644
--- a/docs/ui-kit.md
+++ b/docs/ui-kit.md
@@ -867,8 +867,9 @@ shared token paint and hit targets. All are exercised in the kit gallery.
The compact `settings_choice_row` variant reuses the shared settings radio-card painter
for preset lists: 40 pt rows, right-aligned summaries and the active workspace accent.
-`progress_action` keeps a status caption, bounded progress track and Cancel action on
-one row inside a Navigation card. `Container::below_navigation_row` reserves that card
+`progress_action` keeps a name, a status, a bounded progress track and a Cancel action on
+one row inside a Navigation card. Cancel and the status always show whole; a long name is
+cut first (ellipsis, full name on hover), then the track narrows. `Container::below_navigation_row` reserves that card
and its shared gap above an inline result toolbar.
`number_pair` extends the shared value-pair row to bounded numeric fields (such as