Skip to content

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

Viewport: integrate Section status with current UI changes (#8548) (#8557)

Nathan Danef504c82216b7
diff --git a/assets/locales/pending/viewport-section-status.json b/assets/locales/pending/viewport-section-status.json
new file mode 100644
index 0000000000..17b71c32b0
--- /dev/null
+++ b/assets/locales/pending/viewport-section-status.json
@@ -0,0 +1,58 @@
+{
+ "en": {
+ "prefs.viewport_section_status": "Show viewport section status",
+ "prefs.viewport_section_status_help": "Show the section setting in the viewport. Escape and the active ribbon button turn it off. Disable to keep the previous section controls.",
+ "ui.viewport_status_section_hatch": "{setting} · hatch",
+ "ui.viewport_status_section_plane": "Current plane",
+ "ui.viewport_status_section_tilted": "tilted · {offset}"
+ },
+ "ar": {
+ "prefs.viewport_section_status": "إظهار حالة المقطع في منفذ العرض",
+ "prefs.viewport_section_status_help": "عرض إعداد المقطع في منفذ العرض. يُوقف Escape وزر الشريط النشط المقطع. عطّل الخيار للاحتفاظ بأدوات المقطع السابقة.",
+ "ui.viewport_status_section_hatch": "{setting} · تهشير",
+ "ui.viewport_status_section_plane": "المستوى الحالي",
+ "ui.viewport_status_section_tilted": "مائل · {offset}"
+ },
+ "de": {
+ "prefs.viewport_section_status": "Schnittstatus im Ansichtsfenster anzeigen",
+ "prefs.viewport_section_status_help": "Die Schnitteinstellung im Ansichtsfenster anzeigen. Escape und die aktive Schaltfläche schalten den Schnitt aus. Deaktivieren, um die bisherigen Schnittbedienelemente zu behalten.",
+ "ui.viewport_status_section_hatch": "{setting} · Schraffur",
+ "ui.viewport_status_section_plane": "Aktuelle Ebene",
+ "ui.viewport_status_section_tilted": "geneigt · {offset}"
+ },
+ "he": {
+ "prefs.viewport_section_status": "הצגת מצב חתך בחלון התצוגה",
+ "prefs.viewport_section_status_help": "הצגת הגדרת החתך בחלון התצוגה. Escape ולחצן הסרט הפעיל מכבים את החתך. כיבוי האפשרות שומר על בקרי החתך הקודמים.",
+ "ui.viewport_status_section_hatch": "{setting} · קווקוו",
+ "ui.viewport_status_section_plane": "המישור הנוכחי",
+ "ui.viewport_status_section_tilted": "נטוי · {offset}"
+ },
+ "ja": {
+ "prefs.viewport_section_status": "ビューポートの断面状態を表示",
+ "prefs.viewport_section_status_help": "ビューポートに断面設定を表示します。Escape または有効なリボンボタンで断面を解除します。無効にすると従来の断面操作を維持します。",
+ "ui.viewport_status_section_hatch": "{setting} · ハッチング",
+ "ui.viewport_status_section_plane": "現在の平面",
+ "ui.viewport_status_section_tilted": "傾斜 · {offset}"
+ },
+ "ko": {
+ "prefs.viewport_section_status": "뷰포트 단면 상태 표시",
+ "prefs.viewport_section_status_help": "뷰포트에 단면 설정을 표시합니다. Escape 키와 활성 리본 버튼으로 단면을 끕니다. 비활성화하면 이전 단면 조작을 유지합니다.",
+ "ui.viewport_status_section_hatch": "{setting} · 해칭",
+ "ui.viewport_status_section_plane": "현재 평면",
+ "ui.viewport_status_section_tilted": "기울어짐 · {offset}"
+ },
+ "vi": {
+ "prefs.viewport_section_status": "Hiện trạng thái mặt cắt trong khung nhìn",
+ "prefs.viewport_section_status_help": "Hiện thiết lập mặt cắt trong khung nhìn. Escape và nút dải công cụ đang bật sẽ tắt mặt cắt. Tắt tùy chọn để giữ cách điều khiển mặt cắt trước đây.",
+ "ui.viewport_status_section_hatch": "{setting} · gạch mặt cắt",
+ "ui.viewport_status_section_plane": "Mặt phẳng hiện tại",
+ "ui.viewport_status_section_tilted": "nghiêng · {offset}"
+ },
+ "zh": {
+ "prefs.viewport_section_status": "显示视口剖面状态",
+ "prefs.viewport_section_status_help": "在视口中显示剖面设置。按 Escape 或单击活动的功能区按钮可关闭剖面。禁用以保留原有剖面控件。",
+ "ui.viewport_status_section_hatch": "{setting} · 填充线",
+ "ui.viewport_status_section_plane": "当前平面",
+ "ui.viewport_status_section_tilted": "倾斜 · {offset}"
+ }
+}
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 8523770edf..ce6383278e 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -2566,6 +2566,9 @@ fn input_rows(d: &mut Dialog, ui: &mut egui::Ui, s: &Session, names: crate::pref
/// Saved vectors/axes are real inputs even when they have no origin-axis selection chip.
fn feature_pattern_reference_key(d: &Dialog, index: usize) -> Option<&'static str> {
+ if matches!(d.kind, Kind::Section { .. }) && index == 0 {
+ return Some("plane");
+ }
if !d.inputs.first().is_some_and(|i| i.accept == selection::FEATURES) {
return None;
}
@@ -2603,7 +2606,9 @@ pub(crate) fn input_rows_range(d: &mut Dialog, ui: &mut egui::Ui, s: &Session, n
let custom_axis = i == 1 && inp.items.is_empty() && stored_revolve_axis(&d.kind).is_some();
let filled = !inp.items.is_empty() || custom_axis || stored_reference.is_some();
let text = if filled {
- RichText::new(if custom_axis || stored_reference.is_some() {
+ RichText::new(if stored_reference.is_some() && matches!(d.kind, Kind::Section { .. }) {
+ crate::i18n::tr("ui.viewport_status_section_plane").into()
+ } else if custom_axis || stored_reference.is_some() {
crate::i18n::tr("dialog.custom_axis").into()
} else if !inp.multi {
inp.items.first().map(|item| selection_label(s, names, d, inp, item)).unwrap_or_default()
@@ -3054,7 +3059,7 @@ pub(crate) fn corner_confirms(d: &Dialog) -> bool {
/// Sketch Palette keeps the right there, and the dialog takes the left so both stay on screen.
/// With Dialogs › In the left column it holds the left column instead (`dialog_column`).
pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
- let escape_routed_here = !app.preferences.viewport_analysis_status || app.escape_owner.is_none_or(|owner| owner == crate::EscapeOwner::Dialog);
+ let escape_routed_here = !crate::viewport_status::enabled(app) || app.escape_owner.is_none_or(|owner| owner == crate::EscapeOwner::Dialog);
// A click in the view's corner is for the dialog open this frame, or for none.
let corner = app.viewport.corner.take();
app.viewport.corner_ok = false;
@@ -3955,18 +3960,42 @@ pub(crate) fn run_dialog(app: &mut SolveApp, d: &Dialog) -> Result<(), String> {
if let Kind::Section { offset, flip, hatch } = &d.kind
&& let Some(cut) = app.session.section
{
- app.tree.section_dialog = Some(SectionDraft { offset: offset.clone(), flip: *flip, hatch: *hatch, plane: sels(d, 0).to_vec(), cut });
+ app.tree.section_dialog = if d.extra.contains_key("plane") && sels(d, 0).is_empty() {
+ None // Programmatic geometry is reconstructed from the actual session, never cached.
+ } else {
+ Some(SectionDraft { offset: offset.clone(), flip: *flip, hatch: *hatch, plane: sels(d, 0).to_vec(), cut })
+ };
}
Ok(())
}
/// Edit Section Analysis: its dialog, where the dialog that made the section shown (or hidden)
-/// now left it, so the cut moves on from there. A section made some other way opens it afresh,
-/// as the toolbar always does (a new section, in place of the old).
+/// now left it. Programmatic cuts use their actual geometry in the same existing form.
pub fn edit_section(app: &mut SolveApp) {
- app.start("inspect.section");
+ app.start_section_edit();
let cut = app.session.section.or(app.tree.hidden_section);
- let Some(last) = app.tree.section_dialog.clone().filter(|last| cut.is_some_and(|c| same_cut(c, last.cut))) else { return };
+ let last = app.tree.section_dialog.clone().filter(|last| cut.is_some_and(|c| same_cut(c, last.cut)));
+ if app.preferences.viewport_section_status {
+ if let Some((origin, normal)) = cut {
+ let o = [origin.x, origin.y, origin.z];
+ let n = [normal.x, normal.y, normal.z];
+ if let Some((_, distance, canonical)) = crate::viewport_status::section_coordinates(o, n) {
+ let flip = n.iter().zip(canonical).map(|(a, b)| a * b).sum::<f64>() < 0.0;
+ let offset = format!("{distance} mm");
+ let hatch = app.session.section_hatch;
+ if let Some(d) = app.dialog.as_mut().filter(|d| matches!(d.kind, Kind::Section { .. })) {
+ d.kind = Kind::Section { offset, flip, hatch };
+ if let Some(input) = d.inputs.first_mut() {
+ input.items.clear();
+ }
+ let base = o.into_iter().zip(canonical).map(|(o, n)| o - n * distance).collect::<Vec<_>>();
+ d.extra.insert("plane".into(), json!({"origin":base,"normal":canonical}));
+ }
+ }
+ }
+ return;
+ }
+ let Some(last) = last else { return };
if let Some(d) = app.dialog.as_mut().filter(|d| matches!(d.kind, Kind::Section { .. })) {
d.kind = Kind::Section { offset: last.offset, flip: last.flip, hatch: last.hatch };
if let Some(plane) = d.inputs.first_mut() {
@@ -4669,11 +4698,14 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
("material.assign", json!({"bodies": sels(d, 0).body_names(), "material": name}))
}
Kind::Section { offset, flip, hatch } => {
- if section_turns_off(s, &d.inputs) {
+ if section_turns_off(s, &d.inputs) && !d.extra.contains_key("plane") {
return Ok(vec![("inspect.section".into(), json!({"clear": true}))]);
}
- need(0, "a plane or planar face")?;
+ if !d.extra.contains_key("plane") {
+ need(0, "a plane or planar face")?;
+ }
let plane = match sels(d, 0).first() {
+ None if d.extra.contains_key("plane") => d.extra.get("plane").cloned().ok_or("select a plane first")?,
Some(Sel::Plane { name }) if matches!(name.as_str(), "XY" | "XZ" | "YZ") => json!(name),
Some(Sel::Face { body, index, point }) => {
let (_, n) = planar_face(s, body, *index).ok_or("the face must be planar")?;
diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs
index 5235e73809..035c407308 100644
--- a/crates/ui-egui/src/dialogs_dense.rs
+++ b/crates/ui-egui/src/dialogs_dense.rs
@@ -891,7 +891,7 @@ fn additional_rows(app: &mut SolveApp, d: &mut Dialog, ui: &mut egui::Ui) -> boo
Kind::Section { offset, flip, hatch } => {
enter |= expr_row(ui, "Distance", offset);
ui_kit::options(ui, "feature_options", &mut [("Flip", flip), ("Hatch", hatch)]);
- if section_turns_off(&app.session, &d.inputs) {
+ if section_turns_off(&app.session, &d.inputs) && !d.extra.contains_key("plane") {
ui_kit::text(ui, tr("section.off_hint"), ui_kit::Text::Hint("section_off"));
}
}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 38564ac8a3..492c0c7369 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1458,16 +1458,21 @@ impl SolveApp {
/// Start an interactive command with its menu anchored below the invoking button.
pub(crate) fn start_at(&mut self, id: &str, opener: Option<egui::Rect>) {
- self.start_with_variant_memory(id, true, opener);
+ self.start_with_variant_memory(id, true, opener, false);
}
/// A dedicated toolbar button starts its exact tool without replacing the sketch family's
/// main button. Choosing a variant from a menu still uses `start` and remembers that choice.
pub(crate) fn start_pinned(&mut self, id: &str, opener: Option<egui::Rect>) {
- self.start_with_variant_memory(id, false, opener);
+ self.start_with_variant_memory(id, false, opener, false);
}
- fn start_with_variant_memory(&mut self, id: &str, remember_variant: bool, opener: Option<egui::Rect>) {
+ /// Existing Section editor uses the normal command-start lifecycle, with explicit edit intent.
+ pub(crate) fn start_section_edit(&mut self) {
+ self.start_with_variant_memory("inspect.section", true, None, true);
+ }
+
+ fn start_with_variant_memory(&mut self, id: &str, remember_variant: bool, opener: Option<egui::Rect>, section_edit: bool) {
self.tree.clear_folder_pick();
if id == "timeline.play" {
if let Err(why) = self.run(id, json!({})) {
@@ -1717,7 +1722,7 @@ impl SolveApp {
});
return;
}
- if !sketch_tools::start_hook(self, id) {
+ if !section_edit && !sketch_tools::start_hook(self, id) {
return;
}
if remember_variant && solidcraft_engine::find_command(id).is_some_and(|c| c.info(&self.session).enabled) {
@@ -2519,7 +2524,7 @@ impl SolveApp {
if first_pass {
self.escape_owner = None;
}
- if first_pass || !self.preferences.viewport_analysis_status {
+ if first_pass || !crate::viewport_status::enabled(self) {
self.esc_handled = false;
}
prefs::apply(self, ctx);
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index 87615a6ec9..a7c594b8a9 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -1063,6 +1063,7 @@ preference_settings! {
/// Show engine-derived persistent selection in the ribbon; off retains neutral buttons.
persistent_ribbon_pressed: bool = true, PAGE_INTERFACE => check_id("prefs.persistent_ribbon_pressed");
viewport_analysis_status: bool = true, PAGE_INTERFACE => check_id("prefs.viewport_analysis_status");
+ viewport_section_status: bool = true, PAGE_INTERFACE => check_id("prefs.viewport_section_status");
/// Keep the SKETCH tab in the ribbon, right after MODEL, while no sketch is open; its drawing
/// tools then start a sketch first (#7904).
sketch_tab_always: bool = false, PAGE_INTERFACE => check_id("prefs.sketch_tab_always");
@@ -5019,6 +5020,7 @@ mod tests {
("ribbon_labels", json!(false), PAGE_INTERFACE),
("persistent_ribbon_pressed", json!(false), PAGE_INTERFACE),
("viewport_analysis_status", json!(false), PAGE_INTERFACE),
+ ("viewport_section_status", json!(false), PAGE_INTERFACE),
("sketch_tab_always", json!(true), PAGE_INTERFACE),
("ribbon_reveal", json!(true), PAGE_INTERFACE),
("dialog_buttons", json!("top"), PAGE_INTERFACE),
@@ -6510,6 +6512,61 @@ mod tests {
assert_eq!(before, after, "a presentation preference never changes effects in any document");
}
+ #[test]
+ fn viewport_section_status_preference_checkbox_control_persists_cancels_and_resets() {
+ assert!(Prefs::default().viewport_section_status);
+ assert!(lenient(&json!({"theme":"light"})).viewport_section_status);
+ assert!(lenient(&json!({"viewport_section_status":"no"})).viewport_section_status);
+ let mut h = crate::scenario::Harness::new();
+ let design = h.app.session.doc.to_json();
+ let revision = h.app.session.revision;
+ h.call("ui.prefs", json!({"open":"Interface"}));
+ super::reveal_preference(&mut h, "prefs:viewport_section_status");
+ let checkbox = crate::scenario::handle_at("prefs:viewport_section_status").unwrap();
+ h.call("ui.click", json!({"x":checkbox.x,"y":checkbox.y}));
+ assert!(!h.app.preferences.viewport_section_status);
+ assert_eq!(h.call("ui.prefs", json!({}))["result"]["viewport_section_status"], false);
+ let mut restored = SolveApp::new(Default::default(), Default::default());
+ restored.load_prefs(&h.app.prefs());
+ assert!(!restored.preferences.viewport_section_status);
+ h.call("ui.prefs", json!({"button":"cancel"}));
+ assert!(h.app.preferences.viewport_section_status);
+ h.call("ui.prefs", json!({"open":"Interface","viewport_section_status":false,"button":"apply"}));
+ h.call("ui.prefs", json!({"button":"defaults"}));
+ assert!(h.app.preferences.viewport_section_status);
+ h.call("ui.prefs", json!({"button":"cancel"}));
+ assert!(!h.app.preferences.viewport_section_status);
+ for malformed in [json!("false"), json!(null), json!(0), json!([])] {
+ assert!(super::set(&mut h.app, &json!({"viewport_section_status":malformed})).is_err());
+ assert!(!h.app.preferences.viewport_section_status);
+ }
+ assert_eq!(h.app.session.revision, revision);
+ assert_eq!(h.app.session.doc.to_json(), design);
+ }
+
+ #[test]
+ fn viewport_section_status_is_independent_of_session_policy_in_background_documents() {
+ let mut app = SolveApp::new(Default::default(), Default::default());
+ super::set(&mut app, &json!({"single_surface_analysis":false,"persistent_ribbon_pressed":false})).unwrap();
+ app.run("inspect.zebra", json!({})).unwrap();
+ app.run("inspect.section", json!({"plane":"XY","at":4})).unwrap();
+ let mut other = solidcraft_engine::Session::default();
+ other.execute("inspect.draft", &json!({})).unwrap();
+ other.execute("inspect.section", &json!({"plane":"XZ","at":-3})).unwrap();
+ crate::documents::open_tab(&mut app, other).unwrap();
+ let before: Vec<_> =
+ std::iter::once(&app.session).chain(app.docs.background()).map(|s| (s.status_items(), s.revision, s.undo.len())).collect();
+ super::control(&mut app, &json!({"open":"Interface","viewport_section_status":false})).unwrap();
+ assert!(!app.preferences.viewport_section_status);
+ assert!(!app.preferences.persistent_ribbon_pressed);
+ assert!(std::iter::once(&app.session).chain(app.docs.background()).all(|s| !s.single_surface_analysis()));
+ super::control(&mut app, &json!({"button":"cancel"})).unwrap();
+ assert!(app.preferences.viewport_section_status);
+ let after: Vec<_> =
+ std::iter::once(&app.session).chain(app.docs.background()).map(|s| (s.status_items(), s.revision, s.undo.len())).collect();
+ assert_eq!(before, after, "a presentation preference never changes effects in any document");
+ }
+
#[test]
fn single_surface_analysis_preference_checkbox_persists_cancels_and_resets() {
assert!(Prefs::default().single_surface_analysis);
diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rs
index 30d29892d5..67a03818e3 100644
--- a/crates/ui-egui/src/prefs/interface.rs
+++ b/crates/ui-egui/src/prefs/interface.rs
@@ -102,6 +102,10 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {
let check = setting::viewport_analysis_status(app, ui).on_hover_text(app.tr("prefs.viewport_analysis_status_help"));
crate::scenario::publish_target("prefs:viewport_analysis_status", check.rect);
});
+ ui_kit::row(ui, "", |ui| {
+ let check = setting::viewport_section_status(app, ui).on_hover_text(app.tr("prefs.viewport_section_status_help"));
+ crate::scenario::publish_target("prefs:viewport_section_status", check.rect);
+ });
// The SKETCH tab outside a sketch too (#7904).
ui_kit::row(ui, "", |ui| {
let check = setting::sketch_tab_always(app, ui).on_hover_text(app.tr("prefs.sketch_tab_always_note"));
diff --git a/crates/ui-egui/src/section_browser_tests.rs b/crates/ui-egui/src/section_browser_tests.rs
index c060bf11f9..f2008b6d18 100644
--- a/crates/ui-egui/src/section_browser_tests.rs
+++ b/crates/ui-egui/src/section_browser_tests.rs
@@ -105,6 +105,7 @@ fn ok(h: &mut Harness) {
#[test]
fn edit_starts_from_the_section_as_it_was_left() {
let mut h = harness();
+ h.app.preferences.viewport_section_status = false;
h.app.run("solid.box", json!({"length":40,"width":30,"height":20})).unwrap();
h.app.session.selection = vec![solidcraft_engine::Sel::Plane { name: "XY".into() }];
h.app.start("inspect.section");
@@ -179,6 +180,7 @@ fn the_hatch_option_carries_through_the_section() {
#[test]
fn ok_with_no_plane_picked_turns_the_section_off() {
let mut h = harness();
+ h.app.preferences.viewport_section_status = false;
h.app.run("solid.box", json!({"length":40,"width":30,"height":20})).unwrap();
h.app.run("inspect.section", json!({"plane": "XZ", "offset": 10})).unwrap();
h.app.session.selection.clear();
@@ -202,3 +204,62 @@ fn ok_with_no_plane_picked_turns_the_section_off() {
h.frames(3);
assert_eq!(h.app.dialog.as_ref().and_then(|d| d.error.as_deref()), Some("select a plane or planar face first"));
}
+
+#[test]
+fn editing_programmatic_sections_keeps_actual_plane_flip_hatch_and_cancel_then_moves_it() {
+ for params in [
+ json!({"plane":"XY","at":-25.4,"flip":true,"hatch":false}),
+ json!({"plane":{"origin":[7,-12,4],"normal":[-3,-4,0]},"offset":5,"hatch":false}),
+ json!({"plane":{"origin":[7,-12,4],"normal":[0,0,-1]},"offset":-5,"flip":true}),
+ ] {
+ let mut h = harness();
+ h.app.run("inspect.section", params).unwrap();
+ assert!(h.app.dialog.is_none(), "programmatic commands never open a form");
+ let cut = h.app.session.section.unwrap();
+ let hatch = h.app.session.section_hatch;
+ crate::dialogs::edit_section(&mut h.app);
+ let d = h.app.dialog.as_ref().unwrap();
+ let cmds = crate::dialogs::apply_commands(&h.app, d).unwrap();
+ let mut scratch = h.app.session.scratch();
+ scratch.execute(&cmds[0].0, &cmds[0].1).unwrap();
+ let preview = scratch.section.unwrap();
+ assert!((preview.0 - cut.0).len() < 1e-9 && (preview.1 - cut.1).len() < 1e-9);
+ assert_eq!(scratch.section_hatch, hatch);
+ assert_eq!(h.app.session.section, Some(cut), "edit intent cannot toggle the active cut off");
+ crate::dialogs::cancel(&mut h.app);
+ assert_eq!(h.app.session.section, Some(cut));
+ crate::dialogs::edit_section(&mut h.app);
+ if let Some(crate::dialogs::Kind::Section { offset, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) {
+ *offset = "30 mm".into();
+ }
+ let cmds = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
+ h.app.run(&cmds[0].0, cmds[0].1.clone()).unwrap();
+ assert_ne!(h.app.session.section.unwrap().0, cut.0);
+ assert!(
+ (h.app.session.section.unwrap().1 - cut.1).len() < 1e-12,
+ "moving the plane retains its clipping direction within normalisation precision"
+ );
+ }
+}
+
+#[test]
+fn section_ribbon_toggle_and_setting_edit_have_separate_intent_and_compatibility() {
+ let mut h = harness();
+ h.app.run("inspect.zebra", json!({})).unwrap();
+ h.app.run("inspect.section", json!({"plane":"YZ","offset":3})).unwrap();
+ h.frames(3);
+ let effect = h.app.session.status_items().into_iter().find(|e| e.command == "inspect.section").unwrap();
+ let item = crate::viewport_status::presentation(&h.app, &effect).unwrap();
+ h.step(&json!({"click":{"handle":format!("viewport_status:{}:setting",item.id)}})).unwrap();
+ assert!(h.app.dialog.is_some() && h.app.session.section.is_some());
+ crate::dialogs::cancel(&mut h.app);
+ h.app.start("inspect.section");
+ assert!(h.app.dialog.is_none() && h.app.session.section.is_none());
+ assert!(h.app.session.analysis.is_some());
+ h.app.run("inspect.section", json!({"plane":"XY"})).unwrap();
+ h.app.preferences.viewport_section_status = false;
+ let cut = h.app.session.section;
+ h.app.start("inspect.section");
+ assert!(h.app.dialog.is_some());
+ assert_eq!(h.app.session.section, cut);
+}
diff --git a/crates/ui-egui/src/sketch_tools.rs b/crates/ui-egui/src/sketch_tools.rs
index 870102fc9c..1d1cd616f8 100644
--- a/crates/ui-egui/src/sketch_tools.rs
+++ b/crates/ui-egui/src/sketch_tools.rs
@@ -291,6 +291,10 @@ fn marks(app: &SolveApp, painter: &egui::Painter, proj: &Proj) {
/// Commands that start with a step of their own: Canvas and Decal ask for the image first,
/// Edit Canvas opens the canvas panel. False when the command should not go on.
pub fn start_hook(app: &mut SolveApp, id: &str) -> bool {
+ if id == "inspect.section" && app.preferences.viewport_section_status && app.session.section.is_some() {
+ let _ = app.run(id, json!({"clear":true}));
+ return false;
+ }
if id == "sketch.intersect"
&& let Some(dialog) = crate::dialogs::Dialog::for_command(app, id)
{
diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs
index 843bc9cf6d..11a41fc6c1 100644
--- a/crates/ui-egui/src/toolbar.rs
+++ b/crates/ui-egui/src/toolbar.rs
@@ -987,15 +987,26 @@ fn ribbon_label_lines(painter: &egui::Painter, label: &str, width: f32) -> Vec<S
}
/// Commands opt into persistent presentation; the engine status list remains the only truth.
-const PERSISTENT_COMMANDS: &[&str] =
- &["inspect.accessibility", "inspect.continuity", "inspect.curvature_map", "inspect.draft", "inspect.environment_map", "inspect.zebra"];
+const PERSISTENT_COMMANDS: &[&str] = &[
+ "inspect.accessibility",
+ "inspect.continuity",
+ "inspect.curvature_map",
+ "inspect.draft",
+ "inspect.environment_map",
+ "inspect.section",
+ "inspect.zebra",
+];
fn persistent_command(id: &str) -> bool {
PERSISTENT_COMMANDS.contains(&id)
}
+fn persistent_available(app: &SolveApp, id: &str) -> bool {
+ persistent_command(id) && (id != "inspect.section" || app.preferences.viewport_section_status)
+}
+
fn persistent_pressed(app: &SolveApp, id: &str) -> bool {
- app.preferences.persistent_ribbon_pressed && persistent_command(id) && app.session.status_items().iter().any(|item| item.command == id)
+ app.preferences.persistent_ribbon_pressed && persistent_available(app, id) && app.session.status_items().iter().any(|item| item.command == id)
}
pub(crate) fn persistent_button_name(app: &SolveApp, command: &solidcraft_engine::CommandSpec) -> String {
@@ -1016,6 +1027,8 @@ fn persistent_hint(app: &SolveApp, command: &solidcraft_engine::CommandSpec, ena
struct PersistentRibbonPaint {
command: &'static solidcraft_engine::CommandSpec,
response: egui::Response,
+ // Keep the allocating layer, clip and opacity when replacing these deferred slots.
+ painter: egui::Painter,
rect: Rect,
background: egui::layers::ShapeIdx,
label_slot: egui::layers::ShapeIdx,
@@ -1025,12 +1038,11 @@ struct PersistentRibbonPaint {
disabled: Option<String>,
}
-fn paint_persistent_ribbon(app: &SolveApp, ui: &egui::Ui, paints: Vec<PersistentRibbonPaint>, tab: &str) {
+fn paint_persistent_ribbon(app: &SolveApp, ui: &egui::Ui, paints: Vec<PersistentRibbonPaint>, tab: &str, namespace: &str) {
let t = Tokens::get();
- let items = app.session.status_items();
let mut count = 0;
for paint in paints {
- let selected = app.preferences.persistent_ribbon_pressed && items.iter().any(|item| item.command == paint.command.id);
+ let selected = persistent_pressed(app, paint.command.id);
let ink = if !paint.enabled {
t.text_dim
} else if selected {
@@ -1054,24 +1066,25 @@ fn paint_persistent_ribbon(app: &SolveApp, ui: &egui::Ui, paints: Vec<Persistent
};
let background = if selected {
count += 1;
- crate::scenario::publish_target(&format!("ribbon:pressed:{}", paint.command.id), paint.rect);
+ crate::scenario::publish_target(&format!("{namespace}:pressed:{}", paint.command.id), paint.rect);
ui_kit::persistent_button_shape(ui, &paint.response, paint.rect)
} else if paint.response.has_focus() && app.preferences.persistent_ribbon_pressed {
egui::Shape::Vec(vec![neutral, ui_kit::native_button_focus(ui, &paint.response, paint.rect)])
} else {
neutral
};
- ui.painter().set(paint.background, background);
+ paint.painter.set(paint.background, background);
if paint.response.has_focus() {
- crate::scenario::publish_target(&format!("ribbon:focus:{}", paint.command.id), paint.rect);
+ crate::scenario::publish_target(&format!("{namespace}:focus:{}", paint.command.id), paint.rect);
}
if let Some(label) = paint.label {
- let galley = ribbon_button_galley_weight(ui.painter(), &label, paint.rect.width() - BUTTON_LABEL_PADDING, ink, selected);
- ui.painter()
+ let galley = ribbon_button_galley_weight(&paint.painter, &label, paint.rect.width() - BUTTON_LABEL_PADDING, ink, selected);
+ paint
+ .painter
.set(paint.label_slot, egui::Shape::galley(pos2(paint.rect.center().x, ribbon_label_top(paint.rect, galley.size().y)), galley, ink));
}
paint.response.widget_info(|| {
- if app.preferences.persistent_ribbon_pressed {
+ if app.preferences.persistent_ribbon_pressed && persistent_available(app, paint.command.id) {
egui::WidgetInfo::selected(egui::WidgetType::Button, paint.enabled, selected, persistent_button_name(app, paint.command))
} else {
let info = crate::render_workspace::interactive_command_info(app, paint.command);
@@ -1080,7 +1093,7 @@ fn paint_persistent_ribbon(app: &SolveApp, ui: &egui::Ui, paints: Vec<Persistent
});
let _ = ribbon_tooltip(app, paint.response, paint.command, paint.disabled.as_deref());
}
- crate::scenario::publish_count("ribbon:pressed", count as f64);
+ crate::scenario::publish_count(&format!("{namespace}:pressed"), count as f64);
}
fn ribbon_button_galley(painter: &egui::Painter, label: &str, width: f32, color: Color32) -> std::sync::Arc<egui::Galley> {
@@ -1647,7 +1660,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
if resp.secondary_clicked() {
menu = Some((resp.interact_pointer_pos().unwrap_or(br.left_bottom()), c.id));
}
- let persistent = persistent_command(selected.id);
+ let persistent = persistent_available(app, selected.id);
let background_slot = painter.add(egui::Shape::Noop);
let accent = crate::theme::TabAccent::for_tab(&t, &tab);
let family_open = family.is_some_and(|f| egui::Popup::is_id_open(ui.ctx(), ui.id().with(("family", f.label)).with("popup")));
@@ -1707,6 +1720,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
persistent_paints.push(PersistentRibbonPaint {
command: selected,
response: resp,
+ painter: painter.clone(),
rect: whole,
background: background_slot,
label_slot: painter.add(egui::Shape::Noop),
@@ -1917,8 +1931,10 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
ui.label(egui::RichText::new(crate::i18n::tr_label("Not available yet")).color(t.text_dim));
}
if sketch_create && app.preferences.ribbon_icon_grid && !cmds.is_empty() {
- let action = dropdown_grid(app, ui, &tab, &sketch_create_grouped(&cmds), &[]);
+ let mut paints = Vec::new();
+ let action = dropdown_grid(app, ui, &tab, &sketch_create_grouped(&cmds), &[], &mut paints);
grid_action(app, ui, action, &mut menu, &mut toggle);
+ paint_persistent_ribbon(app, ui, paints, &tab, "ribbon_grid");
return;
}
if sketch_create {
@@ -1931,8 +1947,11 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
}
let grouped = crate::workspace::grouped_commands(&tab, panel, &cmds);
if app.preferences.ribbon_icon_grid && !grouped.is_empty() {
- let action = dropdown_grid(app, ui, &tab, &grouped, &crate::workspace::ungrouped(&tab, panel, &cmds));
+ let mut paints = Vec::new();
+ let action = dropdown_grid(app, ui, &tab, &grouped, &crate::workspace::ungrouped(&tab, panel, &cmds), &mut paints);
grid_action(app, ui, action, &mut menu, &mut toggle);
+ // Paint in this popup's layer, after its command has changed the session.
+ paint_persistent_ribbon(app, ui, paints, &tab, "ribbon_grid");
return;
}
let cmds: Vec<_> = grouped.iter().map(|(_, c)| *c).collect();
@@ -2015,7 +2034,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
for c in cmds {
let info = crate::render_workspace::interactive_command_info(app, c);
let shortcut = crate::keymap::display_for(app, c.id).unwrap_or_default();
- let response = if persistent_command(c.id) && app.preferences.persistent_ribbon_pressed {
+ let response = if persistent_available(app, c.id) && app.preferences.persistent_ribbon_pressed {
let mut item = ui_kit::MenuItem::new(c.id, info.label, info.icon);
item.shortcut = &shortcut;
item.enabled = info.enabled;
@@ -2042,7 +2061,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
// Resolve persistent paint only after large buttons, dropdowns and overflow have
// dispatched their actions. No already-painted old analysis can survive replacement.
- paint_persistent_ribbon(app, ui, persistent_paints, &tab);
+ paint_persistent_ribbon(app, ui, persistent_paints, &tab, "ribbon");
// Dragging a command: its icon follows the pointer; a toolbar button dragged off the
// toolbar (or into the open drop-down) shows it will be removed.
@@ -2309,7 +2328,7 @@ fn dropdown_row(
let hot = info.enabled && (pointer_on || resp.has_focus());
let mut row = crate::ui_kit::MenuItem::new(c.id, &label, info.icon);
row.enabled = info.enabled;
- if persistent_command(c.id) && app.preferences.persistent_ribbon_pressed {
+ if persistent_available(app, c.id) && app.preferences.persistent_ribbon_pressed {
row.checked = Some(persistent_pressed(app, c.id));
}
if c.id == "view.shots_strip" {
@@ -2579,6 +2598,7 @@ fn dropdown_grid(
tab: &str,
grouped: &[(Option<&'static str>, &'static solidcraft_engine::CommandSpec)],
loose: &[&str],
+ paints: &mut Vec<PersistentRibbonPaint>,
) -> Option<(&'static str, RowAction)> {
// Wide enough for groups side by side, short of the window's edge.
let room = ui.ctx().content_rect().right() - ui.cursor().left() - 24.0;
@@ -2612,7 +2632,7 @@ fn dropdown_grid(
for ((_, c), (rect, _)) in grouped.iter().zip(&layout.cells) {
let rect = rect.translate(origin.to_vec2());
let pinned = crate::toolbar_custom::pinned_on(app, tab, c.id).is_some();
- match dropdown_cell(app, ui, c, rect, pinned) {
+ match dropdown_cell(app, ui, c, rect, pinned, paints) {
RowAction::None => {}
done => action = Some((c.id, done)),
}
@@ -2655,7 +2675,14 @@ fn pin_armed(ui: &egui::Ui, id: &'static str, on: bool) -> bool {
/// One icon of a grid drop-down: clicked, dragged onto the ribbon (to pin it) or right-clicked
/// like a list row; its tooltip is a ribbon button's (name, shortcut, help, why it is off), and a
/// pin in its corner says it is on the ribbon.
-fn dropdown_cell(app: &SolveApp, ui: &mut egui::Ui, c: &'static solidcraft_engine::CommandSpec, rect: Rect, pinned: bool) -> RowAction {
+fn dropdown_cell(
+ app: &SolveApp,
+ ui: &mut egui::Ui,
+ c: &'static solidcraft_engine::CommandSpec,
+ rect: Rect,
+ pinned: bool,
+ paints: &mut Vec<PersistentRibbonPaint>,
+) -> RowAction {
let t = Tokens::get();
let info = c.info(&app.session);
let sense = if info.enabled { Sense::click_and_drag() } else { Sense::drag() };
@@ -2674,20 +2701,42 @@ fn dropdown_cell(app: &SolveApp, ui: &mut egui::Ui, c: &'static solidcraft_engin
let armed = pin_armed(ui, c.id, ui.rect_contains_pointer(rect) && !dragging);
let pin = armed.then(|| ui.interact(pr, ui.id().with(("dropdown_pin", c.id)), Sense::click()));
let pin_hovered = pin.as_ref().is_some_and(egui::Response::hovered);
- let label = app.tr_label(c.label).to_string();
- resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled() && info.enabled, &label));
+ let persistent = app.preferences.persistent_ribbon_pressed && persistent_available(app, c.id);
+ if !persistent {
+ let label = app.tr_label(c.label).to_string();
+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled() && info.enabled, &label));
+ }
crate::scenario::publish_handle(&format!("toolbar:{}", c.id), rect.center());
crate::scenario::publish_handle(&format!("dropdown:{}", c.id), rect.center());
let pointer_on = (resp.hovered() || pin_hovered) && !dragging;
let hot = info.enabled && (pointer_on || resp.has_focus());
let painter = ui.painter().with_clip_rect(ui.clip_rect().intersect(rect));
let cell = rect.shrink(2.0);
+ let mut neutral = Vec::new();
if hot {
- painter.rect_filled(cell, t.control_radius, t.accent_soft);
+ neutral.push(egui::Shape::rect_filled(cell, t.control_radius, t.accent_soft));
crate::scenario::publish_handle(&format!("dropdown_hot:{}", c.id), rect.center());
}
- if resp.has_focus() {
- painter.rect_stroke(cell, t.control_radius, Stroke::new(1.0, t.accent), egui::StrokeKind::Inside);
+ if resp.has_focus() && !persistent {
+ neutral.push(egui::Shape::rect_stroke(cell, t.control_radius, Stroke::new(1.0, t.accent), egui::StrokeKind::Inside));
+ }
+ let neutral = egui::Shape::Vec(neutral);
+ if persistent {
+ // Reuse the native ribbon recipe; only responses/paint slots survive until dispatch.
+ paints.push(PersistentRibbonPaint {
+ command: c,
+ response: resp.clone(),
+ painter: painter.clone(),
+ rect: cell,
+ background: painter.add(egui::Shape::Noop),
+ label_slot: painter.add(egui::Shape::Noop),
+ neutral,
+ label: None,
+ enabled: ui.is_enabled() && info.enabled,
+ disabled: info.disabled_reason.clone(),
+ });
+ } else {
+ painter.add(neutral);
}
icons::paint_icon(&painter, Rect::from_center_size(rect.center(), vec2(GRID_ICON, GRID_ICON)), c.icon, if info.enabled { 1.0 } else { 0.4 });
// A pinned command always shows its pin, clear of the icon's own artwork; any other shows one
@@ -2705,7 +2754,7 @@ fn dropdown_cell(app: &SolveApp, ui: &mut egui::Ui, c: &'static solidcraft_engin
return RowAction::TogglePin;
}
}
- let resp = ribbon_tooltip(app, resp, c, info.disabled_reason.as_deref());
+ let resp = if persistent { resp } else { ribbon_tooltip(app, resp, c, info.disabled_reason.as_deref()) };
if resp.secondary_clicked() {
return RowAction::Menu(resp.interact_pointer_pos().unwrap_or(rect.left_bottom()));
}
@@ -2869,7 +2918,7 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {
if app.file_load.busy() {
return;
}
- if app.preferences.viewport_analysis_status
+ if crate::viewport_status::enabled(app)
&& (app.esc_handled || app.escape_owner.is_some())
&& ctx.input(|input| input.key_pressed(egui::Key::Escape))
{
@@ -2906,7 +2955,7 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {
&& (app.prefs_window.open || app.keymap.open || app.ui.palette_open || ctx.memory(|memory| memory.top_modal_layer().is_some()))
{
app.escape_owner = Some(crate::EscapeOwner::Overlay);
- if app.preferences.viewport_analysis_status {
+ if crate::viewport_status::enabled(app) {
app.last_escape = None;
return;
}
@@ -2921,15 +2970,15 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {
let inline_editor = crate::dim_view::editing();
if popup_owner
|| inline_editor
- || (app.preferences.viewport_analysis_status && app.ui.palette_open)
- || (ctx.egui_wants_keyboard_input() && !(app.preferences.viewport_analysis_status && app.viewport_status.owns_focus(ctx)))
+ || (crate::viewport_status::enabled(app) && app.ui.palette_open)
+ || (ctx.egui_wants_keyboard_input() && !(crate::viewport_status::enabled(app) && app.viewport_status.owns_focus(ctx)))
{
if ctx.input(|input| input.key_pressed(egui::Key::Escape)) {
let owner = if app.dialog.is_some() && !popup_owner && !inline_editor { crate::EscapeOwner::Dialog } else { crate::EscapeOwner::Overlay };
// Reserve first refusal without claiming that cancellation already occurred.
// A dialog's own late handler must still be able to cancel its focused field.
app.escape_owner.get_or_insert(owner);
- if app.preferences.viewport_analysis_status {
+ if crate::viewport_status::enabled(app) {
app.last_escape = None;
}
}
@@ -3020,8 +3069,7 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {
// Not while a tool is still out (its first Esc only ended a chain): this press
// puts it down, and the next quick one finishes.
if again
- && !(app.preferences.viewport_analysis_status
- && (app.viewport_status.open_key.is_some() || crate::viewport_status::has_effect(app)))
+ && !(crate::viewport_status::enabled(app) && (app.viewport_status.open_key.is_some() || crate::viewport_status::has_effect(app)))
&& app.tool.is_none()
&& app.dialog.is_none()
&& let Some(sketch) = app.session.active_sketch
@@ -3046,7 +3094,7 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {
crate::tools::finish(app);
} else if app.dialog.is_some() || app.pending_feature_edit.is_some() {
crate::dialogs::cancel(app);
- } else if app.preferences.viewport_analysis_status && crate::viewport_status::escape(app, repeat) {
+ } else if crate::viewport_status::enabled(app) && crate::viewport_status::escape(app, repeat) {
app.last_escape = None;
} else if !app.session.selection.is_empty() || app.session.active_sketch.is_none() {
crate::edit_clipboard::drop_cut(app);
@@ -5192,12 +5240,283 @@ mod persistent_ribbon_tests {
}
}
+ fn open_status_grid(h: &mut Harness, panel: &str) {
+ h.app.preferences.ribbon_icon_grid = true;
+ h.app.preferences.ribbon_menus_skip_pinned = false;
+ h.frames(3);
+ h.step(&json!({"click":{"handle":format!("panel:INSPECT:{panel}")}})).unwrap();
+ // Exact token colours are checked after the native Area fade, not during its opacity ramp.
+ let settle_frames = (h.ctx.global_style().animation_time * 60.0).ceil() as usize + 2;
+ h.frames(settle_frames.max(3));
+ assert!(scenario::rect_of("toolbar_dropdown").is_some());
+ }
+
+ fn close_status_grid(h: &mut Harness, panel: &str) {
+ // Use the real header toggle so closing a menu never supplies an idle effect Escape.
+ h.step(&json!({"click":{"handle":format!("panel:INSPECT:{panel}")}})).unwrap();
+ h.frames(3);
+ assert!(scenario::rect_of("toolbar_dropdown").is_none());
+ }
+
+ fn status_grid_rect(_h: &Harness, id: &str) -> Rect {
+ let at = scenario::handle_at(&format!("dropdown:{id}")).unwrap();
+ Rect::from_center_size(at, vec2(GRID_CELL, GRID_CELL)).shrink(2.0)
+ }
+
+ fn assert_status_grid(h: &Harness, id: &str, selected: bool, toggled: Option<egui::accesskit::Toggled>) {
+ let rect = status_grid_rect(h, id);
+ let t = Tokens::get();
+ let mut drawn = Vec::new();
+ for shape in &h.shapes {
+ shapes(&shape.shape, &mut drawn);
+ }
+ assert_eq!(
+ drawn.iter().any(|shape| matches!(shape, egui::Shape::Rect(s) if s.rect == rect && s.fill == t.selected_bg)),
+ selected,
+ "{id} grid fill"
+ );
+ assert_eq!(drawn.iter().any(|shape| matches!(shape, egui::Shape::LineSegment { points, stroke } if stroke.width == 2.0 && stroke.color == t.accent && points[0].y == rect.bottom() - t.space_4 && rect.contains(points[0]))), selected, "{id} grid underline");
+ let command = solidcraft_engine::find_command(id).unwrap();
+ let label = if toggled.is_some() { persistent_button_name(&h.app, command) } else { h.app.tr_label(command.label).to_string() };
+ let node = h
+ .output
+ .accesskit_update
+ .as_ref()
+ .and_then(|tree| {
+ tree.nodes.iter().find(|(_, node)| {
+ node.role() == egui::accesskit::Role::Button
+ && node.label() == Some(label.as_str())
+ && node.bounds().is_some_and(|b| rect.contains(pos2(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32)))
+ })
+ })
+ .map(|(_, node)| node)
+ .expect("the actual grid button, distinguished from a same-named pinned ribbon button by bounds");
+ assert_eq!(node.toggled(), toggled, "{id} grid accessibility");
+ }
+
+ #[test]
+ fn persistent_grid_deferred_paint_retains_partial_and_offscreen_scroll_clips() {
+ let mut saw_partial = false;
+ let mut saw_offscreen = false;
+ for offset in [0.0, 24.0, 96.0] {
+ let mut h = harness();
+ h.app.session.execute("inspect.section", &json!({"plane":"XY","at":4})).unwrap();
+ h.app.session.execute("inspect.zebra", &json!({})).unwrap();
+ let effects = h.app.session.status_items();
+ let ctx = h.ctx.clone();
+ let mut expected = Vec::new();
+ let output = ctx.run_ui(
+ egui::RawInput { screen_rect: Some(Rect::from_min_size(egui::Pos2::ZERO, vec2(400.0, 240.0))), focused: true, ..Default::default() },
+ |ui| {
+ expected.clear(); // Context layout passes never accumulate stale paint expectations.
+ // Leave visible space above the scroll viewport, where a broadened clip leaks.
+ ui.add_space(80.0);
+ let mut paints = Vec::new();
+ egui::ScrollArea::vertical()
+ .id_salt("persistent_grid_clip_regression")
+ .auto_shrink([false, false])
+ .max_height(64.0)
+ .min_scrolled_height(64.0)
+ .vertical_scroll_offset(offset)
+ .show(ui, |ui| {
+ ui.spacing_mut().item_spacing.y = 0.0;
+ for id in ["inspect.section", "inspect.zebra", "inspect.draft"] {
+ let command = solidcraft_engine::find_command(id).unwrap();
+ let (rect, _) = ui.allocate_exact_size(vec2(GRID_CELL, GRID_CELL), Sense::hover());
+ let clip = ui.clip_rect().intersect(rect);
+ let _ = dropdown_cell(&h.app, ui, command, rect, false, &mut paints);
+ if id != "inspect.draft" {
+ expected.push((id, rect.shrink(2.0), clip));
+ }
+ }
+ });
+ // This is deliberately the larger parent Ui, matching the real post-dispatch call.
+ paint_persistent_ribbon(&h.app, ui, paints, "INSPECT", "ribbon_grid");
+ },
+ );
+ assert_eq!(h.app.session.status_items(), effects, "rendering real active cells never changes their effects");
+ for (id, cell, original_clip) in expected {
+ let mut backgrounds = Vec::new();
+ for clipped in &output.shapes {
+ let mut drawn = Vec::new();
+ shapes(&clipped.shape, &mut drawn);
+ if drawn
+ .iter()
+ .any(|shape| matches!(shape, egui::Shape::Rect(rect) if rect.rect == cell && rect.fill == Tokens::get().selected_bg))
+ {
+ backgrounds.push(clipped.clip_rect);
+ }
+ }
+ if original_clip.intersect(cell).is_positive() {
+ assert!(!backgrounds.is_empty(), "{id} actually paints its visible selected fragment at offset {offset}");
+ assert!(
+ backgrounds.iter().all(|clip| *clip == original_clip),
+ "{id} retains its original cell/scroll clip, not the parent clip, at offset {offset}"
+ );
+ saw_partial |= !original_clip.contains_rect(cell);
+ } else {
+ assert!(
+ backgrounds.iter().all(|clip| !clip.intersect(cell).is_positive()),
+ "offscreen {id} must not paint into the space above its scroll viewport"
+ );
+ saw_offscreen = true;
+ }
+ }
+ }
+ assert!(saw_partial, "the native ScrollArea must actually partly clip an active cell");
+ assert!(saw_offscreen, "the native ScrollArea must actually scroll an active cell out of view");
+ }
+
+ #[test]
+ fn persistent_grid_uses_actual_section_and_analysis_with_independent_compatibility_preferences() {
+ for section in [false, true] {
+ for ribbon in [false, true] {
+ let mut h = harness();
+ h.app.preferences.viewport_analysis_status = false;
+ h.app.preferences.viewport_section_status = section;
+ h.app.preferences.persistent_ribbon_pressed = ribbon;
+ h.app.session.execute("inspect.zebra", &json!({"stripes":14})).unwrap();
+ h.app.session.execute("inspect.section", &json!({"plane":"XY","at":4})).unwrap();
+ let effects = h.app.session.status_items();
+ open_status_grid(&mut h, "SECTION");
+ assert_status_grid(&h, "inspect.section", section && ribbon, (section && ribbon).then_some(egui::accesskit::Toggled::True));
+ assert_eq!(h.app.session.status_items(), effects);
+ close_status_grid(&mut h, "SECTION");
+ open_status_grid(&mut h, "SURFACE QUALITY");
+ assert_status_grid(&h, "inspect.zebra", ribbon, ribbon.then_some(egui::accesskit::Toggled::True));
+ assert_eq!(h.app.session.status_items(), effects, "presentation preferences and menu navigation never mutate effects");
+ close_status_grid(&mut h, "SURFACE QUALITY");
+ }
+ }
+ }
+
+ #[test]
+ fn persistent_grid_tracks_all_six_analysis_replacements_queries_and_failed_activation() {
+ let mut h = harness();
+ h.app.session.execute("inspect.section", &json!({"plane":"YZ","at":3})).unwrap();
+ let cut = h.app.session.section;
+ for id in PERSISTENT_COMMANDS.iter().copied().filter(|id| *id != "inspect.section") {
+ h.app.session.execute(id, &json!({})).unwrap();
+ let before = h.app.session.status_items();
+ h.app.session.execute("view.status_items", &json!({})).unwrap();
+ assert!(h.app.session.execute("inspect.draft", &json!({"pull":[0,0,0]})).is_err());
+ assert_eq!(h.app.session.status_items(), before);
+ let panel = if matches!(id, "inspect.draft" | "inspect.accessibility") { "CHECK" } else { "SURFACE QUALITY" };
+ open_status_grid(&mut h, panel);
+ assert_status_grid(&h, id, true, Some(egui::accesskit::Toggled::True));
+ assert_eq!(h.app.session.section, cut, "analysis replacement leaves Section independent");
+ close_status_grid(&mut h, panel);
+ }
+ }
+
#[test]
- fn persistent_commands_derive_all_six_programmatic_effects_and_clear_without_residue() {
+ fn persistent_grid_keeps_native_keyboard_focus_and_active_tooltip() {
+ let mut h = harness();
+ h.app.session.execute("inspect.section", &json!({"plane":"XY","at":4})).unwrap();
+ open_status_grid(&mut h, "SECTION");
+ h.step(&json!({"key":"ArrowRight"})).unwrap();
+ h.frames(3);
+ assert!(scenario::rect_of("ribbon_grid:focus:inspect.section").is_some());
+ assert_status_grid(&h, "inspect.section", true, Some(egui::accesskit::Toggled::True));
+ h.step(&json!({"move":{"handle":"dropdown:inspect.section"}})).unwrap();
+ h.frames(100);
+ let command = solidcraft_engine::find_command("inspect.section").unwrap();
+ let hint = persistent_hint(&h.app, command, true).unwrap();
+ let mut drawn = Vec::new();
+ for shape in &h.shapes {
+ shapes(&shape.shape, &mut drawn);
+ }
+ assert!(
+ drawn.iter().any(|shape| matches!(shape, egui::Shape::Text(text) if text.galley.text() == hint)),
+ "the actual grid uses the same native turn-off tooltip"
+ );
+ assert!(h.app.session.section.is_some());
+ }
+
+ #[test]
+ fn persistent_grid_clear_uses_post_dispatch_session_without_stale_paint_or_cross_effect_clear() {
+ for (id, panel) in [("inspect.section", "SECTION"), ("inspect.zebra", "SURFACE QUALITY")] {
+ let mut h = harness();
+ h.app.session.execute("inspect.zebra", &json!({})).unwrap();
+ h.app.session.execute("inspect.section", &json!({"plane":"XY","at":4})).unwrap();
+ open_status_grid(&mut h, panel);
+ assert_status_grid(&h, id, true, Some(egui::accesskit::Toggled::True));
+ let rect = status_grid_rect(&h, id);
+ let at = scenario::handle_at(&format!("dropdown:{id}")).unwrap();
+ let before = h.app.session.status_items();
+ h.frame_with(crate::test_support::pointer(at, true));
+ assert_eq!(h.app.session.status_items(), before, "pointer down is not a command activation");
+ h.frame_with(crate::test_support::pointer(at, false));
+ // Check the release frame, with no settling frame: both paint paths resolve after dispatch.
+ assert_paint(&h, id, false);
+ let mut drawn = Vec::new();
+ for shape in &h.shapes {
+ shapes(&shape.shape, &mut drawn);
+ }
+ let t = Tokens::get();
+ // The pointer still hovers this cell: native hover may share the selected fill.
+ // Persistence is distinguished by the underline, identity and native toggled state.
+ assert!(
+ drawn.iter().any(|shape| matches!(shape, egui::Shape::Rect(s) if s.rect == rect && s.fill == t.accent_soft)),
+ "{id} retains its normal hovered fill on release"
+ );
+ assert!(!drawn.iter().any(|shape| matches!(shape, egui::Shape::LineSegment { points, stroke } if stroke.width == 2.0 && stroke.color == t.accent && points[0].y == rect.bottom() - t.space_4 && rect.contains(points[0]))), "{id} has no persistent underline on release");
+ assert!(scenario::rect_of(&format!("ribbon_grid:pressed:{id}")).is_none(), "{id} has no published pressed identity on release");
+ let command = solidcraft_engine::find_command(id).unwrap();
+ let label = persistent_button_name(&h.app, command);
+ let node = h
+ .output
+ .accesskit_update
+ .as_ref()
+ .and_then(|tree| {
+ tree.nodes.iter().find(|(_, node)| {
+ node.role() == egui::accesskit::Role::Button
+ && node.label() == Some(label.as_str())
+ && node.bounds().is_some_and(|b| rect.contains(pos2(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32)))
+ })
+ })
+ .map(|(_, node)| node)
+ .expect("the actual cleared grid button, distinguished from its pinned ribbon button by bounds");
+ assert_eq!(node.toggled(), Some(egui::accesskit::Toggled::False), "{id} grid accessibility is off on the release frame");
+ assert_eq!(h.app.session.section.is_some(), id != "inspect.section");
+ assert_eq!(h.app.session.analysis.is_some(), id != "inspect.zebra");
+ }
+ }
+
+ #[test]
+ fn section_persistent_ribbon_uses_independent_status_preference_and_active_toggle() {
+ let mut h = harness();
+ h.app.session.execute("inspect.zebra", &json!({})).unwrap();
+ h.app.session.execute("inspect.section", &json!({"plane":"XY","at":4})).unwrap();
+ h.frame();
+ assert_paint(&h, "inspect.section", true);
+ assert_paint(&h, "inspect.zebra", true);
+ h.app.preferences.viewport_analysis_status = false;
+ h.frame();
+ assert_paint(&h, "inspect.section", true);
+ h.app.preferences.viewport_section_status = false;
+ h.frame();
+ assert_paint(&h, "inspect.section", false);
+ assert!(persistent_hint(&h.app, solidcraft_engine::find_command("inspect.section").unwrap(), true).is_none());
+ assert!(h.app.session.section.is_some());
+ h.app.preferences.viewport_section_status = true;
+ h.app.preferences.persistent_ribbon_pressed = false;
+ h.frame();
+ assert_paint(&h, "inspect.section", false);
+ h.app.preferences.persistent_ribbon_pressed = true;
+ h.frames(2);
+ tap(&mut h, "inspect.section");
+ assert!(h.app.session.section.is_none() && h.app.session.analysis.is_some());
+ assert_paint(&h, "inspect.section", false);
+ assert_paint(&h, "inspect.zebra", true);
+ }
+
+ #[test]
+ fn persistent_commands_derive_all_seven_programmatic_effects_and_clear_without_residue() {
let mut h = harness();
for id in PERSISTENT_COMMANDS {
assert!(!persistent_pressed(&h.app, id));
- h.app.session.execute(id, &json!({})).unwrap();
+ h.app.session.execute(id, &if *id == "inspect.section" { json!({"plane":"XY"}) } else { json!({}) }).unwrap();
h.frame(); // Exactly the first output following the engine mutation.
assert_eq!(h.app.session.status_items().iter().map(|s| s.command.as_str()).collect::<Vec<_>>(), [*id]);
for c in PERSISTENT_COMMANDS {
@@ -5212,7 +5531,7 @@ mod persistent_ribbon_tests {
h.frame();
assert_paint(&h, id, false);
}
- for id in ["inspect.minimum_radius", "solid.extrude", "inspect.section"] {
+ for id in ["inspect.minimum_radius", "solid.extrude"] {
assert!(!persistent_command(id));
}
h.app.session.execute("inspect.zebra", &json!({})).unwrap();
diff --git a/crates/ui-egui/src/ui_kit/viewport_status.rs b/crates/ui-egui/src/ui_kit/viewport_status.rs
index 2f5f3e115d..cda25b9b9f 100644
--- a/crates/ui-egui/src/ui_kit/viewport_status.rs
+++ b/crates/ui-egui/src/ui_kit/viewport_status.rs
@@ -116,6 +116,9 @@ pub(crate) fn viewport_status_item(ui: &mut Ui, item: &StatusItem, state: &mut S
let text = RichText::new(&item.setting).monospace().size(t.font_small).color(t.text_dim);
let response = if item.editable { super::button(ui, text, Button::Ghost) } else { ui.label(text) };
scenario::publish_target(&target(item, "setting"), response.rect);
+ if item.editable {
+ state.focus_ids.push(response.id);
+ }
if item.editable && response.clicked() {
action = Some(StatusAction::Edit(item.id.clone()));
}
diff --git a/crates/ui-egui/src/viewport_overlays_tests.rs b/crates/ui-egui/src/viewport_overlays_tests.rs
index c34a5b588b..f5de33f693 100644
--- a/crates/ui-egui/src/viewport_overlays_tests.rs
+++ b/crates/ui-egui/src/viewport_overlays_tests.rs
@@ -1222,6 +1222,7 @@ fn analysis_status_formats_units_and_truthful_non_axis_directions() {
#[test]
fn analysis_status_escape_ends_live_tool_before_effect_and_never_hidden_section() {
let mut h = Harness::new();
+ h.app.preferences.viewport_section_status = false;
h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
h.app.start("inspect.continuity");
assert!(h.app.tool.is_some());
@@ -1278,6 +1279,103 @@ fn analysis_status_ignores_invalid_layout_bounds_without_ending_the_effect() {
}
}
+#[test]
+fn section_status_formats_actual_geometry_in_design_units_without_flip_sign_changes() {
+ let mut h = Harness::new();
+ for (params, metric, imperial) in [
+ (json!({"plane":"XY","at":25.4,"hatch":false}), "Z 25.40 mm", "Z 1.000 in"),
+ (json!({"plane":"XZ","at":-25.4,"flip":true}), "Y -25.40 mm · hatch", "Y -1.000 in · hatch"),
+ (json!({"plane":{"origin":[-25.4,8,2],"normal":[-3,0,0]},"hatch":false}), "X -25.40 mm", "X -1.000 in"),
+ (json!({"plane":{"origin":[0,0,25.4],"normal":[1e-10,0,-2]},"hatch":false}), "Z 25.40 mm", "Z 1.000 in"),
+ (json!({"plane":{"origin":[-12,-9,4],"normal":[3,4,0]},"hatch":false}), "tilted · -14.40 mm", "tilted · -0.5669 in"),
+ (json!({"plane":{"origin":[-12,-9,4],"normal":[3,4,0]},"flip":true}), "tilted · -14.40 mm · hatch", "tilted · -0.5669 in · hatch"),
+ ] {
+ h.app.session.doc_mut().units = "mm".into();
+ h.app.run("inspect.section", params).unwrap();
+ let effect = h.app.session.status_items().into_iter().find(|e| e.command == "inspect.section").unwrap();
+ for (units, expected) in [("mm", metric), ("in", imperial)] {
+ h.app.session.doc_mut().units = units.into();
+ let item = crate::viewport_status::presentation(&h.app, &effect).unwrap();
+ assert_eq!(item.setting, expected);
+ assert!(item.editable && !item.has_key);
+ assert_eq!(item.name, crate::toolbar::persistent_button_name(&h.app, solidcraft_engine::find_command("inspect.section").unwrap()));
+ }
+ }
+}
+
+#[test]
+fn section_status_and_analysis_keep_slots_clear_independently_and_filter_escape_by_preferences() {
+ let mut h = Harness::new();
+ h.app.run("inspect.zebra", json!({})).unwrap();
+ h.app.run("inspect.section", json!({"plane":"XY","at":4})).unwrap();
+ h.app.run("inspect.draft", json!({})).unwrap();
+ let before = h.app.session.status_items();
+ assert_eq!(before.iter().map(|e| e.command.as_str()).collect::<Vec<_>>(), ["inspect.draft", "inspect.section"]);
+ assert!(crate::viewport_status::escape(&mut h.app, false));
+ assert!(h.app.session.analysis.is_none() && h.app.session.section.is_some());
+ assert!(crate::viewport_status::escape(&mut h.app, true));
+ assert!(h.app.session.section.is_some(), "repeat cannot cascade");
+ h.app.run("inspect.zebra", json!({})).unwrap();
+ h.app.run("inspect.section", json!({"plane":"YZ","at":2})).unwrap();
+ h.app.preferences.viewport_section_status = false;
+ assert!(crate::viewport_status::escape(&mut h.app, false));
+ assert!(h.app.session.analysis.is_none() && h.app.session.section.is_some(), "hidden Section is ineligible");
+ h.app.preferences.viewport_analysis_status = false;
+ assert!(!crate::viewport_status::escape(&mut h.app, false));
+ h.app.preferences.viewport_section_status = true;
+ h.app.run("inspect.zebra", json!({})).unwrap();
+ assert!(crate::viewport_status::escape(&mut h.app, false));
+ assert!(h.app.session.analysis.is_some() && h.app.session.section.is_none(), "Section clears while analysis HUD is disabled");
+ h.app.preferences.viewport_analysis_status = true;
+ h.app.run("inspect.section", json!({"plane":"XY"})).unwrap();
+ h.frames(3);
+ let section = h.app.session.status_items().into_iter().find(|e| e.command == "inspect.section").unwrap();
+ let item = crate::viewport_status::presentation(&h.app, &section).unwrap();
+ h.step(&json!({"click":{"handle":format!("viewport_status:{}:close",item.id)}})).unwrap();
+ assert!(h.app.session.analysis.is_some() && h.app.session.section.is_none());
+}
+
+#[test]
+fn section_status_preserves_legacy_three_items_and_dialog_escape_ownership() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
+ h.call("ui.prefs", json!({"single_surface_analysis":false}));
+ h.app.run("inspect.zebra", json!({})).unwrap();
+ h.app.run("inspect.continuity", json!({})).unwrap();
+ h.app.run("inspect.section", json!({"plane":"XY","at":3})).unwrap();
+ h.frames(3);
+ let effects = h.app.session.status_items();
+ assert_eq!(effects.len(), 3);
+ for effect in &effects {
+ let item = crate::viewport_status::presentation(&h.app, effect).unwrap();
+ assert!(crate::scenario::rect_of(&format!("viewport_status:{}:item", item.id)).is_some());
+ }
+ crate::dialogs::edit_section(&mut h.app);
+ h.frames(3);
+ let cut = h.app.session.section;
+ h.step(&json!({"key":"Escape"})).unwrap();
+ assert!(h.app.dialog.is_none());
+ assert_eq!(h.app.session.section, cut);
+ h.step(&json!({"key":"Escape"})).unwrap();
+ assert!(h.app.session.section.is_none());
+ assert!(h.app.session.analysis.is_some() && !h.app.session.continuity.is_empty());
+}
+
+#[test]
+fn section_close_ends_actual_cut_while_an_unrelated_tool_owns_escape() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
+ h.app.start("inspect.continuity");
+ h.app.run("inspect.section", json!({"plane":"XY","at":4})).unwrap();
+ h.frames(3);
+ assert!(h.app.tool.is_some());
+ let effect = h.app.session.status_items().into_iter().find(|e| e.command == "inspect.section").unwrap();
+ let item = crate::viewport_status::presentation(&h.app, &effect).unwrap();
+ h.step(&json!({"click":{"handle":format!("viewport_status:{}:close",item.id)}})).unwrap();
+ assert!(h.app.session.section.is_none());
+ assert!(h.app.tool.is_some() && !h.app.session.continuity.is_empty());
+}
+
#[test]
fn analysis_status_preferences_take_first_escape_and_release_the_next_frame() {
let mut h = Harness::new();
@@ -1403,6 +1501,7 @@ fn analysis_status_focused_dialog_and_real_text_popup_preserve_owner_priority_in
for enabled in [false, true] {
for popup in [false, true] {
let mut h = Harness::new();
+ h.app.preferences.viewport_section_status = false;
h.call("ui.prefs", json!({"viewport_analysis_status":enabled}));
h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
h.app.run("inspect.draft", json!({})).unwrap();
@@ -1491,6 +1590,7 @@ fn analysis_escape_relayout_frame(h: &mut Harness, mut first_pass: impl FnMut(&c
fn analysis_status_preferences_cancel_can_restore_either_policy_without_reusing_escape() {
for saved in [false, true] {
let mut h = Harness::new();
+ h.app.preferences.viewport_section_status = false;
h.call("ui.prefs", json!({"viewport_analysis_status":saved}));
h.app.run("inspect.zebra", json!({})).unwrap();
h.call("ui.prefs", json!({"open":"Interface"}));
@@ -1510,6 +1610,7 @@ fn analysis_status_preferences_cancel_can_restore_either_policy_without_reusing_
#[test]
fn analysis_status_preferences_restore_false_keeps_underlying_dialog_through_the_owned_frame() {
let mut h = Harness::new();
+ h.app.preferences.viewport_section_status = false;
h.call("ui.prefs", json!({"viewport_analysis_status":false}));
h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
h.app.run("inspect.draft", json!({})).unwrap();
@@ -1609,3 +1710,130 @@ fn the_status_toast_closes_with_its_x_and_shows_its_time_left() {
h.frames(2);
assert!(h.app.messages.open, "the card opens the messages");
}
+
+#[test]
+fn section_only_status_modal_owners_take_first_escape_across_real_layout_repasses() {
+ for owner in ["preferences", "command", "tool", "search"] {
+ let mut h = Harness::new();
+ h.call("ui.prefs", json!({"viewport_analysis_status":false,"viewport_section_status":true}));
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
+ h.app.run("inspect.section", json!({"plane":"XY","at":4})).unwrap();
+ match owner {
+ "preferences" => {
+ h.call("ui.prefs", json!({"open":"Interface"}));
+ }
+ "command" => h.app.start("solid.fillet"),
+ "tool" => h.app.start("inspect.continuity"),
+ _ => h.app.start("ui.palette"),
+ }
+ h.frames(3);
+ h.ctx.memory_mut(|memory| {
+ if let Some(id) = memory.focused() {
+ memory.surrender_focus(id);
+ }
+ });
+ let cut = h.app.session.section;
+ analysis_escape_relayout_frame(&mut h, |app| {
+ assert_eq!(app.session.section, cut, "{owner} owns the tap in pass one");
+ assert!(!app.prefs_window.open && app.dialog.is_none() && app.tool.is_none() && !app.ui.palette_open);
+ });
+ assert_eq!(h.app.session.section, cut, "{owner} keeps the cut through the discarded frame");
+ h.step(&json!({"key":"Escape"})).unwrap();
+ assert!(h.app.session.section.is_none(), "a distinct idle tap clears Section after {owner}");
+ }
+}
+
+#[test]
+fn section_only_status_real_editor_popup_then_dialog_own_escape_before_the_cut() {
+ let mut h = Harness::new();
+ h.call("ui.prefs", json!({"viewport_analysis_status":false,"viewport_section_status":true}));
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
+ h.app.run("inspect.section", json!({"plane":"XY","at":4})).unwrap();
+ h.app.start("solid.fillet");
+ h.frames(3);
+ let at = crate::scenario::handle_at("dialog:Radius").unwrap();
+ h.call("ui.click", json!({"x":at.x,"y":at.y}));
+ assert!(h.ctx.memory(|memory| memory.focused().is_some()));
+ h.call("ui.click", json!({"x":at.x,"y":at.y,"button":"right"}));
+ assert!(egui::Popup::is_any_open(&h.ctx));
+ let cut = h.app.session.section;
+ analysis_escape_relayout_frame(&mut h, |app| {
+ assert!(app.dialog.is_some(), "the real popup has first refusal before Dialog cancellation");
+ assert_eq!(app.session.section, cut);
+ });
+ assert!(!egui::Popup::is_any_open(&h.ctx));
+ assert!(h.app.dialog.is_some());
+ h.step(&json!({"key":"Escape"})).unwrap();
+ assert!(h.app.dialog.is_none());
+ assert_eq!(h.app.session.section, cut, "the distinct second tap belongs to the command dialog");
+ h.step(&json!({"key":"Escape"})).unwrap();
+ assert!(h.app.session.section.is_none());
+}
+
+#[test]
+fn section_and_analysis_key_release_distinct_idle_escape_to_the_newest_cut() {
+ let mut h = Harness::new();
+ h.app.run("inspect.draft", json!({})).unwrap();
+ h.app.run("inspect.section", json!({"plane":"XY","at":4})).unwrap();
+ h.frames(3);
+ let effect = h.app.session.status_items().into_iter().find(|effect| effect.has_key).unwrap();
+ let item = crate::viewport_status::presentation(&h.app, &effect).unwrap();
+ h.step(&json!({"click":{"handle":format!("viewport_status:{}:key",item.id)}})).unwrap();
+ assert!(h.app.viewport_status.open_key.is_some());
+ let cut = h.app.session.section;
+ analysis_escape_relayout_frame(&mut h, |app| {
+ assert!(app.viewport_status.open_key.is_none());
+ assert_eq!(app.session.section, cut, "a coexisting analysis key owns the first tap");
+ });
+ assert!(h.app.session.analysis.is_some());
+ h.step(&json!({"key":"Escape"})).unwrap();
+ assert!(h.app.session.section.is_none() && h.app.session.analysis.is_some());
+}
+
+#[test]
+fn section_only_preferences_cancel_restores_either_policy_and_shields_existing_dialog() {
+ for saved in [false, true] {
+ let mut h = Harness::new();
+ h.call("ui.prefs", json!({"viewport_analysis_status":false,"viewport_section_status":saved}));
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
+ h.app.run("inspect.section", json!({"plane":"XY","at":4})).unwrap();
+ if !saved {
+ h.app.start("solid.fillet");
+ }
+ h.call("ui.prefs", json!({"open":"Interface"}));
+ h.call("ui.prefs", json!({"viewport_section_status":!saved}));
+ let cut = h.app.session.section;
+ analysis_escape_relayout_frame(&mut h, |app| {
+ assert!(!app.prefs_window.open);
+ assert_eq!(app.preferences.viewport_section_status, saved);
+ assert!(!app.preferences.viewport_analysis_status);
+ assert_eq!(app.dialog.is_some(), !saved, "enabled routing protects the existing form in pass one");
+ assert_eq!(app.session.section, cut);
+ });
+ assert_eq!(h.app.dialog.is_some(), !saved, "no tap is reinserted during the actual second pass");
+ if !saved {
+ h.step(&json!({"key":"Escape"})).unwrap();
+ assert!(h.app.dialog.is_none());
+ assert_eq!(h.app.session.section, cut);
+ }
+ h.step(&json!({"key":"Escape"})).unwrap();
+ assert_eq!(h.app.session.section.is_none(), saved, "both-false restores the actual legacy idle policy");
+ }
+}
+
+#[test]
+fn section_only_status_stays_below_preferences_for_paint_and_hit_testing() {
+ let mut h = Harness::new();
+ h.call("ui.prefs", json!({"viewport_analysis_status":false,"viewport_section_status":true}));
+ h.app.run("inspect.section", json!({"plane":"XY","at":4})).unwrap();
+ h.frames(3);
+ h.call("ui.prefs", json!({"open":"Interface"}));
+ h.frames(3);
+ let effect = h.app.session.status_items().into_iter().find(|e| e.command == "inspect.section").unwrap();
+ let item = crate::viewport_status::presentation(&h.app, &effect).unwrap();
+ let at = crate::scenario::handle_at(&format!("viewport_status:{}:close", item.id)).unwrap();
+ assert!(crate::scenario::rect_of("prefs:window").unwrap().contains(at));
+ assert_eq!(h.ctx.layer_id_at(at).unwrap().order, egui::Order::Middle);
+ h.call("ui.click", json!({"x":at.x,"y":at.y}));
+ assert!(h.app.prefs_window.open && h.app.session.section.is_some());
+}
diff --git a/crates/ui-egui/src/viewport_status.rs b/crates/ui-egui/src/viewport_status.rs
index 0879dd44ae..df47bd7934 100644
--- a/crates/ui-egui/src/viewport_status.rs
+++ b/crates/ui-egui/src/viewport_status.rs
@@ -5,7 +5,59 @@ use crate::{
};
use solidcraft_engine::status_items::{StatusId, StatusItem as Effect, StatusSetting};
-const PRESENTED: &[StatusId] = &[StatusId::SurfaceAnalysis, StatusId::Continuity];
+fn allowed(app: &SolveApp) -> Vec<StatusId> {
+ let mut ids = Vec::new();
+ if app.preferences.viewport_analysis_status {
+ ids.extend([StatusId::SurfaceAnalysis, StatusId::Continuity]);
+ }
+ if app.preferences.viewport_section_status {
+ ids.push(StatusId::Section);
+ }
+ ids
+}
+
+fn eligible(app: &SolveApp) -> Vec<StatusId> {
+ app.session.status_items().iter().filter(|effect| presentation(app, effect).is_some()).map(|effect| effect.id).collect()
+}
+
+pub(crate) fn enabled(app: &SolveApp) -> bool {
+ app.preferences.viewport_analysis_status || app.preferences.viewport_section_status
+}
+
+/// Canonical plane coordinates: reversing the clipping side never reverses the offset.
+/// Axis planes use world coordinates; other planes use signed distance to the origin.
+pub(crate) fn section_coordinates(origin: [f64; 3], normal: [f64; 3]) -> Option<(Option<&'static str>, f64, [f64; 3])> {
+ let scale = normal.iter().fold(0.0_f64, |a, b| a.max(b.abs()));
+ if !normal.iter().chain(origin.iter()).all(|v| v.is_finite()) || !scale.is_finite() || scale == 0.0 {
+ return None;
+ }
+ let scaled = normal.map(|n| n / scale);
+ let length = scaled.iter().map(|n| n * n).sum::<f64>().sqrt();
+ let mut n = scaled.map(|n| n / length);
+ if n.iter().find(|v| v.abs() > 1e-8).is_some_and(|v| *v < 0.0) {
+ n = n.map(|v| -v);
+ }
+ for (i, axis) in ["X", "Y", "Z"].into_iter().enumerate() {
+ if n.iter().enumerate().all(|(j, v)| (*v - if i == j { 1.0 } else { 0.0 }).abs() < 1e-8) {
+ return Some((Some(axis), *origin.get(i)?, n));
+ }
+ }
+ let distance = origin.iter().zip(n).map(|(o, n)| o * n).sum::<f64>();
+ distance.is_finite().then_some((None, distance, n))
+}
+
+pub(crate) fn section_setting(app: &SolveApp, origin: [f64; 3], normal: [f64; 3], hatch: bool) -> Option<String> {
+ let (axis, offset, _) = section_coordinates(origin, normal)?;
+ let distance = crate::prefs::show_mm(app, offset, 1);
+ let mut text = match axis {
+ Some(axis) => format!("{axis} {distance}"),
+ None => crate::i18n::format("ui.viewport_status_section_tilted", &[("offset", &distance)]),
+ };
+ if hatch {
+ text = crate::i18n::format("ui.viewport_status_section_hatch", &[("setting", &text)]);
+ }
+ Some(text)
+}
fn identity(effect: &Effect) -> String {
format!("{:?}:{}", effect.id, effect.command)
@@ -25,7 +77,7 @@ fn direction(value: [f64; 3]) -> String {
}
pub(crate) fn presentation(app: &SolveApp, effect: &Effect) -> Option<StatusItem> {
- if !PRESENTED.contains(&effect.id) {
+ if !allowed(app).contains(&effect.id) {
return None;
}
let command = solidcraft_engine::find_command(&effect.command)?;
@@ -36,7 +88,7 @@ pub(crate) fn presentation(app: &SolveApp, effect: &Effect) -> Option<StatusItem
StatusSetting::Accessibility { direction: from } => crate::i18n::format("ui.viewport_status_from", &[("direction", &direction(from))]),
StatusSetting::Curvature { radius_mm } => format!("R {}", crate::prefs::show_mm(app, radius_mm, 1)),
StatusSetting::Continuity { edge_count } => crate::i18n::format("ui.viewport_status_edges", &[("count", &edge_count.to_string())]),
- StatusSetting::Section { .. } => return None,
+ StatusSetting::Section { origin_mm, normal, hatch } => section_setting(app, origin_mm, normal, hatch)?,
};
Some(StatusItem {
id: identity(effect),
@@ -44,7 +96,7 @@ pub(crate) fn presentation(app: &SolveApp, effect: &Effect) -> Option<StatusItem
name: crate::toolbar::persistent_button_name(app, command),
setting,
has_key: effect.has_key,
- editable: false,
+ editable: effect.id == StatusId::Section,
})
}
@@ -53,7 +105,7 @@ fn clear(app: &mut SolveApp, effect: &Effect) {
}
pub(crate) fn has_effect(app: &SolveApp) -> bool {
- app.session.newest_status_item(PRESENTED).is_some()
+ app.session.newest_status_item(&eligible(app)).is_some()
}
/// Called only after existing Escape owners have yielded. A repeat cannot cascade clears.
@@ -62,11 +114,11 @@ pub(crate) fn escape(app: &mut SolveApp, repeat: bool) -> bool {
return app.viewport_status.open_key.is_some() || has_effect(app);
}
if let Some(open) = app.viewport_status.open_key.take()
- && app.session.status_items().iter().any(|effect| effect.has_key && identity(effect) == open)
+ && app.session.status_items().iter().any(|effect| eligible(app).contains(&effect.id) && effect.has_key && identity(effect) == open)
{
return true;
}
- if let Some(effect) = app.session.newest_status_item(PRESENTED) {
+ if let Some(effect) = app.session.newest_status_item(&eligible(app)) {
clear(app, &effect);
return true;
}
@@ -74,11 +126,14 @@ pub(crate) fn escape(app: &mut SolveApp, repeat: bool) -> bool {
}
pub(crate) fn show(app: &mut SolveApp, ctx: &egui::Context, viewport: egui::Rect) {
- if !app.preferences.viewport_analysis_status {
+ if !enabled(app) {
app.viewport_status.open_key = None;
return;
}
let effects = app.session.status_items();
+ if !app.preferences.viewport_analysis_status {
+ app.viewport_status.open_key = None;
+ }
let items: Vec<_> = effects.iter().filter_map(|effect| presentation(app, effect)).collect();
if items.is_empty() {
app.viewport_status = Default::default();
@@ -105,11 +160,18 @@ pub(crate) fn show(app: &mut SolveApp, ctx: &egui::Context, viewport: egui::Rect
}
});
for action in actions {
- if let StatusAction::Clear(id) = action
- && let Some(effect) = effects.iter().find(|effect| identity(effect) == id)
- {
- clear(app, effect);
- app.viewport_status.open_key = None;
+ match action {
+ StatusAction::Clear(id) => {
+ if let Some(effect) = effects.iter().find(|effect| identity(effect) == id) {
+ clear(app, effect);
+ app.viewport_status.open_key = None;
+ }
+ }
+ StatusAction::Edit(id) => {
+ if effects.iter().any(|effect| effect.id == StatusId::Section && identity(effect) == id) {
+ crate::dialogs::edit_section(app);
+ }
+ }
}
}
}
diff --git a/crates/ui-egui/tests/scenarios/dialog_buttons_top.json b/crates/ui-egui/tests/scenarios/dialog_buttons_top.json
index 9ef1f2faf9..68a01d46fc 100644
--- a/crates/ui-egui/tests/scenarios/dialog_buttons_top.json
+++ b/crates/ui-egui/tests/scenarios/dialog_buttons_top.json
@@ -4,7 +4,7 @@
{"call": "engine.execute", "params": {"command": "sketch.rectangle.two_point", "params": {"p0": [0, 0], "p1": [40, 30]}}},
{"call": "engine.execute", "params": {"command": "sketch.finish", "params": {}}},
{"call": "ui.prefs", "params": {"open": "Interface"}},
- {"click": {"handle": "prefs:dialog_buttons:top"}},
+ {"widget": "Top", "near": "Dialog buttons"},
{"widget": "OK"},
{"expect": {"prefs": {"dialog": null, "dialog_buttons": "top"}}},
{"note": "Extrude picks the sketch's one profile; its buttons are in the title row."},