Skip to content

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

Browser: drag over the eyes to show or hide many rows at once (#9680) (#9681)

momysnowffbaf292f0f0
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index 0476a0d3fb..60fb04db5f 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -166,6 +166,9 @@ pub struct TreeState {
pub section_hidden: bool,
/// What waits for the Capture Position question: a command id, or [`SAVE`].
pub capture_prompt: Option<String>,
+ /// The design, undo depth and visibility when the button last went down: a drag over the eyes
+ /// merges the steps it made into one (`eye_drag_frame`).
+ eye_press: Option<(Arc<Document>, usize, solidcraft_engine::Visibility)>,
/// The last row clicked (for Shift ranges).
anchor: Option<String>,
/// Row keys in drawing order this frame (for Shift ranges).
@@ -435,6 +438,35 @@ pub fn toggle_folder(app: &mut SolveApp, key: &str) {
let _ = app.run("browser.visibility", json!({ "tree_folders": [key], "visible": app.session.folder_hidden(key) }));
}
+/// A drag over the eyes is one undo step (#9680). When the button goes down the undo depth and the
+/// hidden items are noted; when it comes up, the steps the drag made are merged into the first of
+/// them. Runs every frame, whatever else is open, so a release is never missed.
+pub(crate) fn eye_drag_frame(app: &mut SolveApp, ctx: &egui::Context) {
+ let (pressed, down) = ctx.input(|i| (i.pointer.primary_pressed(), i.pointer.primary_down()));
+ if pressed {
+ app.tree.eye_press = Some((app.session.doc.clone(), app.session.undo.len(), without_origin(app.session.visibility.clone())));
+ }
+ if down {
+ return;
+ }
+ let dragged = ctx.data_mut(|d| d.remove_temp::<bool>(crate::ui_kit::eye_drag_id())).is_some();
+ let Some((doc, depth, visibility)) = app.tree.eye_press.take().filter(|_| dragged) else { return };
+ // shortcut: once the history is full (200 steps) its length stops growing, so the drag is left as
+ // separate steps, like the point-cloud and canvas drags; the visibility test keeps a trimmed front
+ // from being merged wrongly.
+ let undo = &mut app.session.undo;
+ if undo.len() > depth + 1 && undo.get(depth).is_some_and(|s| Arc::ptr_eq(&s.doc, &doc) && without_origin(s.visibility.clone()) == visibility) {
+ undo.truncate(depth + 1);
+ }
+}
+
+/// The Origin's own eye is not an undo step (`set_origin_shown`), so the drag's steps do not hold it:
+/// it is left out of the comparison.
+fn without_origin(mut visibility: solidcraft_engine::Visibility) -> solidcraft_engine::Visibility {
+ visibility.origin_hidden = None;
+ visibility
+}
+
/// A folder shortcut target lasts until another click, Escape, or a change of design/model.
/// Visibility changes keep the document snapshot, so V can toggle the same folder again.
pub(crate) fn update_folder_pick(app: &mut SolveApp, ctx: &egui::Context) {
diff --git a/crates/ui-egui/src/browser_card_tests.rs b/crates/ui-egui/src/browser_card_tests.rs
index 7a778c9223..e15d7aad40 100644
--- a/crates/ui-egui/src/browser_card_tests.rs
+++ b/crates/ui-egui/src/browser_card_tests.rs
@@ -826,3 +826,117 @@ fn a_group_dragged_onto_another_group_nests_in_it_or_goes_before_it() {
drag(&mut h, "row:Gamma (1)", "row:Beta (2)", -10.0);
assert_eq!(h.app.session.doc.ordered_entries(0, "bodies", None), [BrowserEntry::Group(gamma), BrowserEntry::Group(beta)]);
}
+
+/// Three bodies with their eyes in the Browser, the first one's eye hidden or shown per the test.
+fn three_bodies(h: &mut Harness) {
+ for (name, x) in [("One", 0), ("Two", 20), ("Three", 40)] {
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"corner":[x,0,0],"operation":"new_body","body_name":name})).unwrap();
+ }
+ h.settle();
+}
+
+fn body_hidden(h: &Harness, name: &str) -> bool {
+ h.app.session.visibility.hidden_bodies.iter().any(|b| b == name)
+}
+
+/// #9680: a press on an eye that drags over other eyes sets each eye it passes to the first eye's
+/// new state, and the whole drag is one undo step.
+#[test]
+fn eye_drag_sets_every_eye_it_passes_in_one_undo_step() {
+ for eye_left in [false, true] {
+ let mut h = Harness::new();
+ three_bodies(&mut h);
+ if eye_left {
+ h.call("ui.prefs", json!({"browser_eye_left": true}));
+ h.settle();
+ }
+ let undo = h.app.session.undo.len();
+ h.step(&json!({"drag":[{"handle":"eye:One"},{"handle":"eye:Three"}],"steps":40})).unwrap();
+ h.settle();
+ for name in ["One", "Two", "Three"] {
+ assert!(body_hidden(&h, name), "eye_left {eye_left}: {name} is hidden by the drag");
+ }
+ assert_eq!(h.app.session.undo.len(), undo + 1, "eye_left {eye_left}: the drag is one undo step");
+ h.app.run("edit.undo", json!({})).unwrap();
+ for name in ["One", "Two", "Three"] {
+ assert!(!body_hidden(&h, name), "eye_left {eye_left}: one undo shows {name} again");
+ }
+ }
+}
+
+/// #9680: an eye already in the target state stays as it is: a drag from a shown eye over a hidden
+/// one hides both, and undo brings back the hidden one as it was.
+#[test]
+fn eye_drag_leaves_an_eye_already_in_the_target_state_alone() {
+ let mut h = Harness::new();
+ three_bodies(&mut h);
+ h.app.run("browser.visibility", json!({"items":["Two"],"visible":false})).unwrap();
+ h.settle();
+ h.step(&json!({"drag":[{"handle":"eye:One"},{"handle":"eye:Three"}],"steps":40})).unwrap();
+ h.settle();
+ for name in ["One", "Two", "Three"] {
+ assert!(body_hidden(&h, name), "{name} is hidden: the hidden eye is not flipped back");
+ }
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert!(!body_hidden(&h, "One") && !body_hidden(&h, "Three"), "undo shows the two the drag hid");
+ assert!(body_hidden(&h, "Two"), "undo keeps the eye hidden before the drag");
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert!(!body_hidden(&h, "Two"), "the hide before the drag is its own undo step");
+}
+
+/// #9680: a plain click on an eye still toggles that one row, as one undo step.
+#[test]
+fn a_plain_eye_click_still_toggles_one_row_as_one_undo_step() {
+ let mut h = Harness::new();
+ three_bodies(&mut h);
+ let undo = h.app.session.undo.len();
+ h.step(&json!({"click":{"handle":"eye:Two"}})).unwrap();
+ h.settle();
+ assert!(body_hidden(&h, "Two") && !body_hidden(&h, "One") && !body_hidden(&h, "Three"), "only Two is hidden");
+ assert_eq!(h.app.session.undo.len(), undo + 1, "the click is one undo step");
+}
+
+/// #9680: a drag over the eyes that rests near the rows' bottom edge scrolls them, and the eyes
+/// the rows bring under the pointer take the drag's state too.
+#[test]
+fn eye_drag_near_the_rows_bottom_edge_scrolls_them() {
+ let mut h = Harness::new();
+ h.call("ui.resize", json!({"width":1400,"height":900}));
+ for i in 0..35 {
+ h.app.run("sketch.create", json!({"plane":"XY", "name":format!("Sketch{i}")})).unwrap();
+ h.app.run("sketch.finish", json!({})).unwrap();
+ }
+ h.settle();
+ assert!(handle_at("row:Sketch34").is_none(), "the rows overflow the card");
+ let card = rect_of("browser:card").unwrap();
+ let eye = handle_at("eye:Sketch0").unwrap();
+ h.call("ui.drag", json!({"x0": eye.x, "y0": eye.y, "x1": eye.x, "y1": card.bottom() - 10.0, "steps": 20, "hold_end": 240}));
+ h.settle();
+ assert!(handle_at("row:Sketch34").is_some(), "the drag scrolled the list down to its last row");
+ assert!(h.app.session.visibility.hidden_sketches.len() > 10, "the eyes the drag reached are hidden");
+}
+
+/// #9680: a drag from the Origin's eye over the plane eyes is one undo step of its own, and the show
+/// before it stays a step: one undo takes back only the drag. The Origin's eye is not an undo step (a
+/// click on it is not either), so that one undo leaves it as the drag set it.
+#[test]
+fn eye_drag_from_the_origin_is_its_own_undo_step_and_leaves_an_earlier_show_alone() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"One"})).unwrap();
+ h.app.run("browser.visibility", json!({"items":["One"],"visible":false})).unwrap();
+ h.app.run("browser.visibility", json!({"items":["One"],"visible":true})).unwrap();
+ h.app.run("browser.expand_all", json!({})).unwrap();
+ h.settle();
+ let undo = h.app.session.undo.len();
+ h.step(&json!({"drag":[{"handle":"eye:Origin"},{"handle":"eye:YZ"}],"steps":40})).unwrap();
+ h.settle();
+ let origin_hidden = |h: &Harness| h.app.session.visibility.origin_hidden == Some(true);
+ assert!(origin_hidden(&h) && h.app.session.visibility.hidden_origin.iter().any(|k| k == "YZ"), "the drag hid the Origin and its planes");
+ assert_eq!(h.app.session.undo.len(), undo + 1, "the drag is one undo step");
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert!(!body_hidden(&h, "One"), "one undo takes back only the drag: the show before it stays");
+ assert!(h.app.session.visibility.hidden_origin.is_empty(), "the planes the drag hid are shown again");
+ assert!(origin_hidden(&h), "the Origin's eye is not an undo step: it keeps what the drag set");
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert!(body_hidden(&h, "One"), "the show is its own undo step: undoing it hides One again");
+}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index a5082af89f..6b6b9bcf16 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -2569,6 +2569,7 @@ impl SolveApp {
self.drain_control(ctx);
self.follow_view_request(true);
agent_cursor::step(self, ctx);
+ browser::eye_drag_frame(self, ctx);
if !self.synthetic.is_empty() {
ctx.request_repaint();
}
diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rs
index 4c32a2d099..749ac2ed72 100644
--- a/crates/ui-egui/src/ui_kit/gallery.rs
+++ b/crates/ui-egui/src/ui_kit/gallery.rs
@@ -1939,8 +1939,8 @@ fn gallery_covers_every_inline_element() {
&& matches!(&item.vis, syn::Visibility::Restricted(v) if v.path.is_ident("crate"))
{
let name = item.sig.ident.to_string();
- // The inherited row label is metadata, not a renderable element.
- if name != "label" {
+ // The inherited row label and the eye-drag state key are metadata, not renderable elements.
+ if name != "label" && name != "eye_drag_id" {
assert!(names.contains(name.as_str()), "{file}: {name} needs a gallery entry");
}
}
diff --git a/crates/ui-egui/src/ui_kit/tree.rs b/crates/ui-egui/src/ui_kit/tree.rs
index f89b2061bb..781d499ba1 100644
--- a/crates/ui-egui/src/ui_kit/tree.rs
+++ b/crates/ui-egui/src/ui_kit/tree.rs
@@ -5,6 +5,10 @@ use egui::{Color32, FontId, Pos2, Rect, Sense, Stroke, pos2, vec2};
const ROW_H: f32 = super::TREE_ROW_HEIGHT;
const INDENT: f32 = 14.0;
const DIM_ICON_OPACITY: f32 = 0.4;
+/// A drag over the eyes scrolls the rows when the pointer is this near their top or bottom edge,
+/// by this many points a frame (#9680).
+const DRAG_EDGE: f32 = 24.0;
+const DRAG_SCROLL: f32 = 6.0;
/// Trailing tree action; disabled actions retain their reason and a scenario rectangle.
pub(crate) struct TreeAction<'a> {
@@ -99,6 +103,7 @@ pub(crate) struct RowResp {
pub(crate) double: bool,
pub(crate) secondary: Option<Pos2>,
pub(crate) fold: bool,
+ /// The eye was clicked, or a drag over the eyes sets it (#9680, see [`eye_drag_id`]).
pub(crate) eye: bool,
pub(crate) eye_rect: Option<Rect>,
pub(crate) radio: bool,
@@ -118,6 +123,12 @@ pub(crate) struct RowResp {
pub(crate) actions: Vec<egui::Response>,
}
+/// The state a drag over the eyes sets them to: the first eye's new state, while the button is
+/// down (egui temporary data). Absent when no eye drag is under way.
+pub(crate) fn eye_drag_id() -> egui::Id {
+ egui::Id::new("sc_tree_eye_drag")
+}
+
/// Geometry used by Browser culling and the shared row painter.
pub(crate) fn tree_row_rect(ui: &egui::Ui, row: &Row<'_>) -> Rect {
let t = Tokens::get();
@@ -246,6 +257,26 @@ pub(crate) fn tree_row(ui: &mut egui::Ui, id: egui::Id, row: &Row) -> RowResp {
// Hidden or faded rows keep main's dimming, with the rounded suppression asset.
icons::paint_icon(ui.painter(), er, if vis { "eye" } else { "suppress" }, if vis && !row.dim { 0.85 } else { DIM_ICON_OPACITY });
out.eye = resp.clicked() && click_on == 2;
+ // A press on an eye that turns into a drag takes the opposite state, and each eye the
+ // pointer then passes over takes that same state (#9680).
+ if resp.drag_started() && press_on == 2 {
+ ui.data_mut(|d| d.insert_temp(eye_drag_id(), !vis));
+ out.eye = true;
+ } else if let Some(p) = ui.input(|i| i.pointer.primary_down().then(|| i.pointer.hover_pos()).flatten())
+ && at(p) == 2
+ && ui.rect_contains_pointer(eye_r)
+ && let Some(target) = ui.data(|d| d.get_temp::<bool>(eye_drag_id()))
+ {
+ out.eye |= target != vis;
+ // Within a few points of the rows' top or bottom edge, the drag scrolls them.
+ let clip = ui.clip_rect();
+ if p.y < clip.top() + DRAG_EDGE {
+ ui.scroll_to_rect(Rect::from_min_size(pos2(r.left(), clip.top() - DRAG_SCROLL), vec2(1.0, 1.0)), None);
+ } else if p.y > clip.bottom() - DRAG_EDGE {
+ ui.scroll_to_rect(Rect::from_min_size(pos2(r.left(), clip.bottom() + DRAG_SCROLL), vec2(1.0, 1.0)), None);
+ }
+ ui.ctx().request_repaint();
+ }
out.eye_rect = Some(eye_r.intersect(ui.clip_rect()));
out.eye_at = Some(er.center());
crate::scenario::publish_handle(&format!("eye:{}", row.label), er.center());
diff --git a/docs/book/src/guide/ui-tour.md b/docs/book/src/guide/ui-tour.md
index db0225189b..611c278d6e 100644
--- a/docs/book/src/guide/ui-tour.md
+++ b/docs/book/src/guide/ui-tour.md
@@ -22,7 +22,7 @@
- **Browser** (left). The design as a tree: document settings and units, named views, the
origin, bodies, sketches, construction planes, canvases, joints and components. The eye at the
row's right end shows or hides an item (**Preferences › Interface › Eye next to the fold arrow**
- puts it back beside the fold arrow), a component's radio button makes it the active component,
+ puts it back beside the fold arrow; press an eye and drag up or down over other eyes to show or hide them all at once, as one undo step), a component's radio button makes it the active component,
and right-clicking any row gives that item's menu. Right-click the design or a component and choose **Expand All** or
**Collapse All** to open or close every folder under that row (the design row stays visible
when the whole tree is collapsed). Rows drag into groups and other components. **Preferences ›