Skip to content

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

Ribbon: Finish Sketch follows the last sketch panel (#3958)

bherbruck9974413a5bb3
diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs
index 4f6b1bf2c0..d8983a23b0 100644
--- a/crates/ui-egui/src/toolbar.rs
+++ b/crates/ui-egui/src/toolbar.rs
@@ -1005,11 +1005,13 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
})
.collect();
let right = r.right();
- // Keep the Sketch exit group at the far right and reachable at every width.
+ // The Sketch exit group follows the last sketch panel, and is always kept room for so it
+ // stays reachable at every width; when panels go into the » menu it moves to the far right.
let finish_plan = sizes.last().filter(|_| tab == "SKETCH").map(Plan::full);
let finish_width = finish_plan.as_ref().map_or(0.0, |p| p.width().max(80.0));
let normal_count = sizes.len().saturating_sub(usize::from(finish_plan.is_some()));
let mut plans = fit(sizes.get(..normal_count).unwrap_or_default(), right - 4.0 - px - finish_width);
+ let finish_right = plans.iter().any(|p| p.fit == Fit::More);
plans.extend(finish_plan);
crate::scenario::publish_count("toolbar_collapsed", plans.iter().filter(|p| p.fit == Fit::Collapsed).count() as f64);
crate::scenario::publish_count("toolbar_more", plans.iter().filter(|p| p.fit == Fit::More).count() as f64);
@@ -1027,7 +1029,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
let trimmed = plan.shown < plan.widths.len();
let finish = tab == "SKETCH" && *panel == "FINISH SKETCH";
let width = if finish { finish_width } else { plan.width() };
- if finish {
+ if finish && finish_right {
px = right - finish_width;
painter.line_segment([pos2(px, top), pos2(px, r.bottom() - 1.0)], Stroke::new(1.0, t.border));
}
@@ -2774,7 +2776,8 @@ mod fill_width_tests {
let at = format!("{tab} at {w}");
let bar = crate::scenario::rect_of("toolbar").unwrap();
let finish = crate::scenario::rect_of("panel:SKETCH:FINISH SKETCH");
- let right = finish.map_or(bar.right() - 4.0, |f| f.left() - 4.0);
+ // The room for the other panels: the bar less the Finish group kept for it.
+ let right = bar.right() - 4.0 - finish.map_or(0.0, |f| f.width() + 4.0);
let count = |name: &str| crate::scenario::count_of(name).unwrap_or(-1.0);
let (collapsed, trimmed, more) = (count("toolbar_collapsed"), count("toolbar_trimmed"), count("toolbar_more"));
let lists = crate::toolbar_custom::panel_lists(tab);
@@ -2821,7 +2824,11 @@ mod fill_width_tests {
}
if sketch {
let finish = finish.expect("Finish group stays visible");
- assert_eq!(finish.right(), bar.right(), "{at}: Finish stays anchored right");
+ if more > 0.0 {
+ assert_eq!(finish.right(), bar.right(), "{at}: Finish moves right of the » menu");
+ } else {
+ assert!((finish.left() - end).abs() < 0.5, "{at}: Finish follows the last panel ({} vs {end})", finish.left());
+ }
assert!(crate::scenario::handle_at("button:sketch.finish").is_some(), "{at}: Finish stays reachable");
}
// The assistant lives in the title bar; visible ribbon tabs fit before search.
diff --git a/crates/ui-egui/tests/ui_layout.rs b/crates/ui-egui/tests/ui_layout.rs
index 74d5e3e2b8..571321e8e8 100644
--- a/crates/ui-egui/tests/ui_layout.rs
+++ b/crates/ui-egui/tests/ui_layout.rs
@@ -161,7 +161,7 @@ fn docked_ribbon_geometry_and_search() {
#[test]
fn finish_sketch_stays_at_the_right_when_groups_collapse() {
- use solidcraft_ui_egui::scenario::handle_at;
+ use solidcraft_ui_egui::scenario::{count_of, handle_at};
for layout in ["docked", "floating"] {
let mut h = Harness::new();
h.call("ui.set", json!({"layout":layout}));
@@ -172,7 +172,16 @@ fn finish_sketch_stays_at_the_right_when_groups_collapse() {
let ribbon = rect_of("toolbar").unwrap();
let exit = rect_of("ribbon:section:SKETCH:FINISH SKETCH").unwrap();
let finish = rect_of("button:sketch.finish").unwrap();
- assert_eq!(exit.right(), ribbon.right() - 4.0);
+ // Finish follows the last sketch panel; once panels spill into the » menu it sits at
+ // the right end, after it.
+ if count_of("toolbar_more").unwrap_or(0.0) > 0.0 {
+ assert_eq!(exit.right(), ribbon.right() - 4.0, "{layout} at {width}");
+ } else {
+ assert!(exit.right() <= ribbon.right() - 4.0, "{layout} at {width}");
+ let last = rect_of("panel:SKETCH:CONFIGURE").or_else(|| rect_of("panel:SKETCH:REFERENCE")).unwrap();
+ let group = rect_of("panel:SKETCH:FINISH SKETCH").unwrap();
+ assert!(group.left() - last.right() < 16.0, "{layout} at {width}: Finish follows the last panel");
+ }
assert!(ribbon.contains_rect(finish));
assert!(finish.bottom() < exit.top());
assert!(handle_at("tab:SKETCH").is_some(), "the selected contextual tab scrolls into view");