Browser: a feature's menu edits its profile sketch, suppresses and rolls back (#6673) (#6674)

* Browser: a feature row edits its profile sketch, suppresses and rolls back

A sketch button on feature rows with a profile sketch, and the feature menu gains
Edit Profile Sketch, Suppress/Unsuppress and Roll Back Here. Features behind the
history marker or suppressed are drawn faint, as in the timeline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Browser: the sketch button sits right after the feature's name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tr1pp4
2026-10-26 11:05:38 +00:00
committed by GitHub
parent cfb3f52aec
commit 25ad6c7266
3 changed files with 128 additions and 29 deletions
+38 -17
View File
@@ -367,6 +367,8 @@ pub(crate) struct Row<'a> {
pub(crate) radio: Option<bool>,
/// Trailing badges: "lock", "pin".
pub(crate) badges: &'a [&'a str],
/// A button at the row's right end: (icon, tooltip label), e.g. a feature's profile sketch.
pub(crate) action: Option<(&'a str, &'a str)>,
/// Lit by the selection or the 3D view's pointer: the item's own row, or a row leading to it.
pub(crate) mark: Mark,
}
@@ -392,6 +394,8 @@ pub(crate) struct RowResp {
pub(crate) fold: bool,
pub(crate) eye: bool,
pub(crate) radio: bool,
/// The row's [`Row::action`] button was clicked.
pub(crate) action: bool,
pub(crate) hovered: bool,
/// The row's response (drag and drop).
pub(crate) resp: Option<egui::Response>,
@@ -438,8 +442,30 @@ pub(crate) fn draw_row(ui: &mut egui::Ui, id: egui::Id, row: &Row) -> RowResp {
let fold_r = Rect::from_min_max(pos2(x - 4.0, r.top()), pos2(x + 15.0, r.bottom()));
let eye_r = Rect::from_center_size(pos2(x + 14.0 + 8.0, cy), vec2(19.0, r.height()));
let radio_r = Rect::from_center_size(pos2(x + 32.0 + 6.0, cy), vec2(15.0, r.height()));
// The label follows the fold arrow, eye, radio and icon (drawn below in that order). It is
// laid out first, so the action button can sit right after the name and read as the row's.
let label_x = x + 14.0 + 18.0 + if row.radio.is_some() { 15.0 } else { 0.0 } + if row.icon.is_empty() { 0.0 } else { 21.0 };
let col =
if row.selected { crate::theme::TabAccent::current(ui.ctx()).ink } else { row.color.unwrap_or(if row.dim { t.text_dim } else { t.text }) };
let label_display = if row.name { crate::i18n::tr_name(row.label) } else { crate::i18n::tr_dyn(row.label) };
let font = if row.selected { crate::fonts::semibold(t.font_label) } else { FontId::proportional(t.font_label) };
// The label stops before the action, the badges and the card's edge; a longer name ends in
// an ellipsis and its full text is in the tooltip.
let badges_width = row.badges.len() as f32 * 15.0;
let action_width = if row.action.is_some() { 22.0 } else { 0.0 };
let room = (r.right() - 4.0 - badges_width - action_width - label_x).max(0.0);
let mut job = egui::text::LayoutJob::simple(label_display.to_string(), font, col, room);
job.wrap.max_rows = 1;
job.wrap.break_anywhere = true;
job.wrap.overflow_character = Some('\u{2026}');
let galley = ui.painter().layout_job(job);
let lw = galley.size().x;
let elided = galley.elided;
let action_r = Rect::from_min_size(pos2(label_x + lw + 2.0, r.top()), vec2(20.0, r.height()));
let at = |p: Pos2| -> u8 {
if row.fold.is_some() && fold_r.contains(p) {
if row.action.is_some() && action_r.contains(p) {
4
} else if row.fold.is_some() && fold_r.contains(p) {
1
} else if row.eye.is_some() && eye_r.contains(p) {
2
@@ -486,34 +512,29 @@ pub(crate) fn draw_row(ui: &mut egui::Ui, id: egui::Id, row: &Row) -> RowResp {
icons::paint_icon(ui.painter(), ir, row.icon, if row.dim { DIM_ICON_OPACITY } else { 1.0 });
x += 21.0;
}
let col =
if row.selected { crate::theme::TabAccent::current(ui.ctx()).ink } else { row.color.unwrap_or(if row.dim { t.text_dim } else { t.text }) };
let label_display = if row.name { crate::i18n::tr_name(row.label) } else { crate::i18n::tr_dyn(row.label) };
let font = if row.selected { crate::fonts::semibold(t.font_label) } else { FontId::proportional(t.font_label) };
// The label stops before the badges and the card's edge; a longer name ends in an ellipsis
// and its full text is in the tooltip.
let badges_width = row.badges.len() as f32 * 15.0;
let room = (r.right() - 4.0 - badges_width - x).max(0.0);
let mut job = egui::text::LayoutJob::simple(label_display.to_string(), font, col, room);
job.wrap.max_rows = 1;
job.wrap.break_anywhere = true;
job.wrap.overflow_character = Some('\u{2026}');
let galley = ui.painter().layout_job(job);
let lw = galley.size().x;
let elided = galley.elided;
crate::scenario::publish_rect(&format!("row_label:{}", row.label), Rect::from_min_size(pos2(x, cy - galley.size().y / 2.0), galley.size()));
ui.painter().with_clip_rect(ui.painter().clip_rect().intersect(r)).galley(pos2(x, cy - galley.size().y / 2.0), galley, col);
let mut bx = (x + lw + 6.0).min(r.right() - 16.0);
let mut bx = (x + lw + 6.0 + action_width).min(r.right() - 16.0);
for b in row.badges {
let br = Rect::from_center_size(pos2(bx + 6.0, cy), vec2(12.0, 12.0));
badge(ui.painter(), br, b, t.text_dim);
bx += 15.0;
}
if let Some((icon, _)) = row.action {
if hover_on == 4 {
ui.painter().rect_filled(action_r.shrink2(vec2(1.0, 3.0)), t.radius_sm.saturating_sub(1), t.hover);
}
let ir = Rect::from_center_size(action_r.center(), vec2(14.0, 14.0));
icons::paint_icon(ui.painter(), ir, icon, if hover_on == 4 { 1.0 } else { 0.6 });
out.action = resp.clicked() && click_on == 4;
crate::scenario::publish_handle(&format!("action:{}", row.label), action_r.center());
}
crate::scenario::publish_handle(&format!("row:{}", row.label), r.center());
let tip = match hover_on {
1 => Some(if row.fold == Some(true) { crate::i18n::tr("ui.collapse") } else { crate::i18n::tr("ui.expand") }),
2 => Some(if row.eye == Some(true) { crate::i18n::tr("ui.hide") } else { crate::i18n::tr("ui.show") }),
3 => Some(if row.radio == Some(true) { crate::i18n::tr("ui.active_component") } else { crate::i18n::tr("ui.activate") }),
4 => row.action.map(|(_, tip)| crate::i18n::tr_label(tip)),
_ => None,
};
let resp = match tip {
+66 -1
View File
@@ -74,9 +74,23 @@ pub(super) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, component: u64, path:
for index in indices {
let Some(feature) = app.session.doc.features.get(index) else { continue };
let (id, label, icon) = (feature.id, feature.name.clone(), crate::timeline::icon_of(&feature.kind));
let sketch = crate::timeline::TimelineKind::of(&feature.kind).profile_sketch();
// Behind the history marker or suppressed: not built, drawn faint as in the timeline.
let dim = feature.suppressed || app.session.doc.marker.is_some_and(|marker| index >= marker);
let selected = app.session.selection.contains(&Sel::Feature { id });
app.tree.remember(&format!("f:{id}"));
let r = draw_row(ui, ui.id().with(("browser_feature", id)), &Row { depth: depth + 1, icon, label: &label, selected, ..Default::default() });
let action = sketch.map(|_| ("sketch", "Edit Profile Sketch"));
let r = draw_row(
ui,
ui.id().with(("browser_feature", id)),
&Row { depth: depth + 1, icon, label: &label, selected, dim, action, ..Default::default() },
);
if r.action
&& let Some(sketch) = sketch
{
app.edit_sketch(sketch.0);
continue;
}
if let Some(rect) = r.rect {
crate::scenario::publish_handle(&format!("row:browser-feature:{scope}:{id}"), rect.center());
if app.tree.reveal_feature.as_ref().is_some_and(|target| target.id == id && target.path == path) {
@@ -385,4 +399,55 @@ mod tests {
assert!(!item.enabled || item.params.as_ref().unwrap()["feature"] == json!(owner), "{id}: {item:?}");
}
}
/// A feature's browser row has the timeline's actions: its sketch button and menu edit the
/// profile sketch, and the menu suppresses and rolls back; rolled-back rows stay listed.
#[test]
fn browser_feature_row_edits_its_sketch_suppresses_and_rolls_back() {
let mut h = Harness::new();
let sketch = h.app.run("sketch.create", json!({"plane":"XY","name":"Profile"})).unwrap()["sketch"].as_u64().unwrap();
h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[20,15]})).unwrap();
h.app.run("sketch.finish", json!({})).unwrap();
let pad = h.app.run("solid.extrude", json!({"distance":10,"body_name":"Plate"})).unwrap()["feature"].as_u64().unwrap();
let block = h.app.run("solid.box", json!({"length":5,"width":5,"height":5,"body_name":"Block"})).unwrap()["feature"].as_u64().unwrap();
let (pad_name, block_name) = (h.app.session.doc.feature(pad).unwrap().name.clone(), h.app.session.doc.feature(block).unwrap().name.clone());
h.app.tree.expanded.insert("c0/features".into());
h.frames(2);
// Only a feature with a profile sketch gets the button.
assert!(crate::scenario::handle_at(&format!("action:{block_name}")).is_none());
// The button sits right after the name, not at the far edge of a wide browser.
let name = crate::scenario::rect_of(&format!("row_label:{pad_name}")).unwrap();
let button = crate::scenario::handle_at(&format!("action:{pad_name}")).unwrap();
assert!(button.x > name.right() && button.x < name.right() + 20.0, "{name:?} {button:?}");
h.step(&json!({"click": {"handle": format!("action:{pad_name}")}})).unwrap();
h.frames(2);
assert_eq!(h.app.session.active_sketch, Some(sketch), "the button opens the profile sketch");
h.app.finish_sketch();
h.frames(2);
let menu = |h: &Harness, id: u64| crate::context_menu::items(&h.app, &Target::Feature { id });
let edit = menu(&h, pad).into_iter().find(|item| item.id == "ui.editSketch").unwrap();
assert!(edit.enabled && edit.params.as_ref().unwrap()["sketch"] == json!(sketch), "{edit:?}");
assert!(!menu(&h, block).into_iter().find(|item| item.id == "ui.editSketch").unwrap().enabled);
let run = |h: &mut Harness, id: u64, command: &str| {
let item = menu(h, id).into_iter().find(|item| item.id == command).unwrap();
crate::context_menu::run_item(&mut h.app, &item, Pos2::ZERO);
for _ in 0..500 {
if h.app.deferred.is_none() && h.app.deferred_queue.is_empty() {
break;
}
h.frame();
}
h.frames(2);
};
run(&mut h, block, "timeline.suppress");
assert!(h.app.session.doc.feature(block).unwrap().suppressed);
run(&mut h, block, "timeline.suppress");
assert!(!h.app.session.doc.feature(block).unwrap().suppressed, "the second click unsuppresses");
run(&mut h, pad, "timeline.roll_to");
let pad_index = h.app.session.doc.feature_index(pad).unwrap();
assert_eq!(h.app.session.doc.marker, Some(pad_index + 1), "the marker goes right after the feature");
let labels: Vec<_> = drawn_rows().into_iter().map(|(label, ..)| label).collect();
assert!(labels.contains(&block_name), "a rolled-back feature stays listed: {labels:?}");
}
}
+24 -11
View File
@@ -360,17 +360,7 @@ pub fn items(app: &SolveApp, target: &Target) -> Vec<Item> {
Target::Viewport => viewport_items(app),
Target::Body { name } => body_items(app, std::slice::from_ref(name), true),
Target::Sketch { id } => sketch_items(app, *id),
Target::Feature { id } => vec![
act("ui.editFeature", "Edit Feature", "edit").with(json!({"feature":id})).on(app.session.doc.feature(*id).is_some()),
act("ui.rename", "Rename", "rename").with(json!({"feature":id})).on(app.session.doc.feature(*id).is_some()),
act("ui.delete", "Delete", "delete").key("Del").with(json!({"items": [{"type": "feature", "id": id}]})).on(app
.session
.doc
.feature(*id)
.is_some()),
Item::sep(),
act("ui.findTimeline", "Find in Timeline", "rollback").with(json!({"feature":id})).on(app.session.doc.feature(*id).is_some()),
],
Target::Feature { id } => feature_items(app, *id),
Target::Plane { id } => plane_items(app, *id),
Target::OriginPlane { name } => origin_plane_items(app, name),
Target::Component { id } => component_items(app, *id),
@@ -482,6 +472,27 @@ fn feature_and_sketch(app: &SolveApp, f: Option<u64>) -> (Option<u64>, Option<u6
(f, sketch)
}
/// A browser feature row's menu: the timeline's feature actions, so the browser alone is enough
/// to edit, suppress and roll back.
fn feature_items(app: &SolveApp, id: u64) -> Vec<Item> {
let feature = app.session.doc.feature(id);
let exists = feature.is_some();
let sketch = feature.and_then(|f| crate::timeline::TimelineKind::of(&f.kind).profile_sketch());
let suppressed = feature.is_some_and(|f| f.suppressed);
vec![
act("ui.editFeature", "Edit Feature", "edit").with(json!({"feature":id})).on(exists),
act("ui.editSketch", "Edit Profile Sketch", "sketch").with(json!({"sketch": sketch.map(|s| s.0)})).on(sketch.is_some()),
act("ui.rename", "Rename", "rename").with(json!({"feature":id})).on(exists),
act("timeline.suppress", if suppressed { "Unsuppress" } else { "Suppress" }, "suppress")
.with(json!({"feature":id, "suppressed": !suppressed}))
.on(exists),
act("timeline.roll_to", "Roll Back Here", "rollback").with(json!({"feature":id})).on(exists),
act("ui.delete", "Delete", "delete").key("Del").with(json!({"items": [{"type": "feature", "id": id}]})).on(exists),
Item::sep(),
act("ui.findTimeline", "Find in Timeline", "rollback").with(json!({"feature":id})).on(exists),
]
}
/// The canvas menus put Repeat on
/// top, then what fits the selection, our extras after a separator.
fn viewport_items(app: &SolveApp) -> Vec<Item> {
@@ -1460,6 +1471,8 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {
app.start("sketch.create");
}
}
// They recompute the history from the changed feature on: off the frame, as the timeline does.
"timeline.suppress" | "timeline.roll_to" if item.params.is_some() => drop(app.run_heavy(&item.id, p)),
id if item.params.is_some() => {
let _ = app.run(id, p);
}