History: show the origin and bodies at the top (#6490) (#6495)

* claim: #6490

* feat(history): show the origin and bodies at the top (#6490)
This commit is contained in:
Lars Jansen
2026-10-27 07:46:25 +00:00
committed by GitHub
parent 76879f8b39
commit 5fc23436ca
9 changed files with 227 additions and 4 deletions
@@ -0,0 +1,30 @@
{
"en": {
"prefs.history_origin_bodies": "Show origin and bodies at the top",
"prefs.history_origin_bodies_note": "The History on the left or under the browser starts with the active component's Bodies folder and the Origin, with their eyes and menus as in the browser. The History at the bottom is unchanged."
},
"ja": {
"prefs.history_origin_bodies": "原点とボディを先頭に表示",
"prefs.history_origin_bodies_note": "左側またはブラウザー下の履歴の先頭に、アクティブなコンポーネントのボディフォルダーと原点を、ブラウザーと同じ表示切り替えとメニュー付きで表示します。下部の履歴は変わりません。"
},
"zh": {
"prefs.history_origin_bodies": "在顶部显示原点和实体",
"prefs.history_origin_bodies_note": "左侧或浏览器下方的历史以活动组件的实体文件夹和原点开头,并带有与浏览器相同的显示切换和菜单。底部的历史保持不变。"
},
"ar": {
"prefs.history_origin_bodies": "إظهار الأصل والأجسام في الأعلى",
"prefs.history_origin_bodies_note": "يبدأ السجل على اليسار أو تحت المستعرض بمجلد الأجسام للمكوّن النشط وبالأصل، مع أيقونات الإظهار والقوائم كما في المستعرض. لا يتغير السجل في الأسفل."
},
"he": {
"prefs.history_origin_bodies": "הצגת הראשית והגופים למעלה",
"prefs.history_origin_bodies_note": "ההיסטוריה משמאל או מתחת לדפדפן מתחילה בתיקיית הגופים של הרכיב הפעיל ובראשית, עם סמלי העין והתפריטים כמו בדפדפן. ההיסטוריה למטה לא משתנה."
},
"de": {
"prefs.history_origin_bodies": "Ursprung und Körper oben zeigen",
"prefs.history_origin_bodies_note": "Der Verlauf links oder unter dem Browser beginnt mit dem Körper-Ordner der aktiven Komponente und dem Ursprung, mit Augen und Menüs wie im Browser. Der Verlauf unten bleibt unverändert."
},
"ko": {
"prefs.history_origin_bodies": "원점과 바디를 맨 위에 표시",
"prefs.history_origin_bodies_note": "왼쪽 또는 브라우저 아래의 히스토리가 활성 구성 요소의 바디 폴더와 원점으로 시작하며, 브라우저처럼 표시 아이콘과 메뉴가 있습니다. 아래쪽 히스토리는 바뀌지 않습니다."
}
}
+45 -1
View File
@@ -130,6 +130,9 @@ pub struct TreeState {
pub timeline_reveal: Option<u64>,
/// The Edit Canvas / Calibrate panel.
pub canvas_panel: Option<CanvasPanel>,
/// The bodies a row at the top of the history lights this frame (`history_rows`), for the
/// browser, drawn after it, to keep.
history_hover: Vec<String>,
/// A Section Analysis hidden with its eye in the Analysis folder: its plane (origin,
/// normal), so the eye can bring it back (#822).
pub hidden_section: Option<(solidcraft_engine::geom::Vec3, solidcraft_engine::geom::Vec3)>,
@@ -1218,12 +1221,53 @@ fn rows_scrolling(app: &mut SolveApp, ui: &mut egui::Ui, acts: &mut Actions, shr
app.tree.cache = Some(cache);
}
/// The Bodies folder and the Origin at the top of the vertical History (Preferences › Interface:
/// Show origin and bodies at the top, #6490): the browser's own rows, with their eyes, selection,
/// menus and fold state. The bodies are the active component's, in the placement being edited,
/// as that component's folder in the browser lists them. The rows stay out of the browser's row
/// order, automation list and reveal, which the browser keeps for its own rows.
pub(crate) fn history_rows(app: &mut SolveApp, ui: &mut egui::Ui) {
prepare_model(app);
let mut acts = Actions { lit: Lit::of(app), ..Default::default() };
let reveal = app.tree.reveal.take();
let order = app.tree.order_len;
let drawn = DRAWN.with(|d| d.borrow().len());
let component = app.session.active_component;
let path = (component != 0)
.then(|| app.session.active_occurrence_path.clone().unwrap_or_else(|| app.session.doc.first_path(component)))
.filter(|path| !path.is_empty());
// The Bodies folder as the browser draws it for that component or placement (`browser_cache`).
let mut cache = app.tree.cache.take().unwrap_or_default();
cache.prepare(app);
let bodies = cache.folder(app, component, path.as_deref(), "bodies");
app.tree.cache = Some(cache);
ui.scope(|ui| {
ui.spacing_mut().item_spacing.y = 0.0;
folder_rows_at(app, ui, component, path.as_deref(), "bodies", 0, &mut acts, &bodies);
origin_rows(app, ui, 0, &acts);
});
app.tree.reveal = reveal;
// The browser's own rows reuse these order slots (`TreeState::remember`).
app.tree.order_len = order;
DRAWN.with(|d| d.borrow_mut().truncate(drawn));
app.viewport.hover_bodies = acts.hover_bodies.clone();
app.tree.history_hover = acts.hover_bodies;
if let Some(d) = acts.drop {
apply_drop(app, d);
}
if let Some((at, target)) = acts.menu {
crate::context_menu::open_for(app, at, target);
}
}
fn finish_browser(app: &mut SolveApp, ui: &mut egui::Ui, mut acts: Actions) {
app.tree.order.truncate(app.tree.order_len);
if !acts.hovered {
acts.hover_bodies.clear();
}
app.viewport.hover_bodies = acts.hover_bodies;
// The history's rows, drawn before the browser, light bodies too (`history_rows`).
let history = std::mem::take(&mut app.tree.history_hover);
app.viewport.hover_bodies = if acts.hover_bodies.is_empty() { history } else { acts.hover_bodies };
if let Some(d) = acts.drop {
apply_drop(app, d);
}
+3 -1
View File
@@ -326,7 +326,9 @@ mod tests {
let pending: BTreeMap<String, Messages> = serde_json::from_str(&std::fs::read_to_string(entry.path()).unwrap()).unwrap();
for (locale, messages) in pending {
for (id, text) in messages {
assert_eq!(Locale::for_language(&locale).text(&id), text, "{locale}: {id}");
// The catalogs hand right-to-left text out in display order (`crate::bidi`);
// pending files hold it in reading order, as the catalogs do (#7527).
assert_eq!(Locale::for_language(&locale).text(&id), crate::bidi::visual_template(&text), "{locale}: {id}");
}
}
}
+3
View File
@@ -654,6 +654,9 @@ preference_settings! {
timeline_left_browser_collapsed: bool = false, PAGE_INTERFACE;
/// Whether the History at the left lists a sketch under the feature built from it.
history_sketches: HistorySketches = HistorySketches::default(), PAGE_INTERFACE;
/// The vertical history (left, or under the browser) starts with the active component's Bodies
/// folder and the Origin, as the browser shows them (#6490). The bottom strip is unchanged.
timeline_origin_bodies: bool = false, PAGE_INTERFACE;
/// Width of the browser sidebar, which
/// the user drags wider or narrower at its right edge.
browser_width: f32 = DEFAULT_BROWSER_WIDTH, PAGE_INTERFACE;
+9
View File
@@ -95,6 +95,15 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {
}
});
});
// Only the history on the left or under the browser has room for these rows.
ui_kit::row(ui, "", |ui| {
ui.add_enabled_ui(app.preferences.timeline_left, |ui| {
let check = ui_kit::checkbox(ui, app.tr("prefs.history_origin_bodies"), &mut app.preferences.timeline_origin_bodies)
.on_hover_text(app.tr("prefs.history_origin_bodies_note"))
.on_disabled_hover_text(app.tr("prefs.history_origin_bodies_note"));
crate::scenario::publish_target("prefs:history_origin_bodies", check.rect);
});
});
ui_kit::row(ui, app.tr("prefs.browser"), |ui| {
ui.add_enabled_ui(app.ui.layout == crate::shell::LayoutMode::Floating, |ui| {
let mut selected = usize::from(app.preferences.browser_float);
+108 -1
View File
@@ -1007,6 +1007,17 @@ struct Rows<'a> {
fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui, names: bool) {
let t = Tokens::get();
// Show origin and bodies at the top (#6490): the browser's Bodies folder and Origin rows lead
// the history when it is wide enough for names. They are not places in the history: nothing
// drags or drops among them, and the features start below them.
let features_top = (names && app.preferences.timeline_origin_bodies).then(|| {
crate::browser::history_rows(app, ui);
ui.add_space(t.space_3);
t.secondary_hline(ui.painter(), ui.max_rect().x_range(), ui.cursor().top(), t.border);
ui.add_space(t.space_3);
ui.cursor().top()
});
let among_features = |y: f32| features_top.is_none_or(|top| y >= top);
ui.spacing_mut().item_spacing.y = if names { t.space_2 } else { t.space_4 };
let features: Vec<_> = app
.session
@@ -1142,6 +1153,7 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui, names: bool) {
}
// The marker dropped where it already is needs no bar: the marker shows the spot.
if let (Some(active), Some(pointer)) = (drag.as_ref(), pointer)
&& among_features(pointer.y)
&& let Some(slot) = nearest_vertical_slot(&slots, pointer.y)
&& !(matches!(active, Drag::Marker) && slot.position == marker.min(n))
{
@@ -1170,7 +1182,7 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui, names: bool) {
}
if ui.input(|input| input.pointer.any_released())
&& let Some(active) = drag.take()
&& let Some(pointer) = pointer
&& let Some(pointer) = pointer.filter(|pointer| among_features(pointer.y))
&& let Some(slot) = nearest_vertical_slot(&slots, pointer.y)
{
match active {
@@ -1887,6 +1899,101 @@ mod tests {
assert_eq!(harness.app.session.selection, vec![solidcraft_engine::Sel::Feature { id: base }]);
}
/// The handle `name` drawn inside the vertical history (the browser publishes the same names).
fn in_history(name: &str) -> Option<egui::Pos2> {
let card = crate::scenario::rect_of("history:vertical")?;
crate::scenario::handles(name).into_iter().filter(|(n, _)| n == name).map(|(_, at)| at).find(|at| card.contains(*at))
}
/// Show origin and bodies at the top (#6490): off by default; on, the vertical history starts
/// with the active component's Bodies folder and the Origin, the browser's rows with their
/// folds, eyes, selection and menus; they take no drops; too narrow for names, it leaves them out.
#[test]
fn origin_and_bodies_lead_the_vertical_history_when_asked() {
let mut h = Harness::new();
h.app.preferences.timeline_left = true;
h.app.preferences.timeline_left_width = 240.0;
h.app.run("solid.box", json!({"length": 10, "width": 10, "height": 10, "name": "First", "body_name": "Block"})).unwrap();
h.app
.run("solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [20, 0, 0], "operation": "new_body", "name": "Second", "body_name": "Other"}))
.unwrap();
h.frames(4);
assert!(in_history("row:Origin").is_none() && in_history("row:Bodies").is_none(), "off by default");
h.call("ui.prefs", json!({"timeline_origin_bodies": true}));
h.frames(3);
let bodies = in_history("row:Bodies").expect("the Bodies folder");
let origin = in_history("row:Origin").expect("the Origin");
let first = handle_at("timeline:First").unwrap();
assert!(bodies.y < origin.y && origin.y < first.y, "Bodies, Origin, then the features");
assert!(in_history("row:Block").is_some() && in_history("row:Other").is_some(), "the Bodies folder starts open, as in the browser");
assert!(in_history("row:XY").is_none(), "the Origin starts closed, as in the browser");
// The fold is the browser's: opening it here opens it there.
h.call("ui.click", json!({"x": origin.x, "y": origin.y}));
h.frames(2);
assert!(crate::browser::is_open(&h.app, "origin", false));
let xy = in_history("row:XY").expect("the origin planes");
let eye = in_history("eye:XY").unwrap();
h.call("ui.click", json!({"x": eye.x, "y": eye.y}));
h.frames(2);
assert!(h.app.session.visibility.hidden_origin.iter().any(|p| p == "XY"), "the plane's eye hides it");
let eye = in_history("eye:Block").unwrap();
h.call("ui.click", json!({"x": eye.x, "y": eye.y}));
h.frames(2);
assert!(h.app.session.visibility.hidden_bodies.iter().any(|b| b == "Block"), "the body's eye hides it");
h.call("ui.click", json!({"x": xy.x, "y": xy.y, "button": "right"}));
h.frames(2);
assert_eq!(h.app.menu.target, crate::context_menu::Target::OriginPlane { name: "XY".into() }, "the plane's own menu");
crate::context_menu::close(&mut h.app);
h.frames(2);
let other = in_history("row:Other").unwrap();
h.call("ui.click", json!({"x": other.x, "y": other.y}));
h.frames(2);
assert_eq!(h.app.session.selection, vec![solidcraft_engine::Sel::Body { name: "Other".into() }]);
// Neither the marker nor a feature drops among these rows.
let order = |h: &Harness| h.app.session.doc.features.iter().map(|f| f.name.clone()).collect::<Vec<_>>();
let before = order(&h);
h.step(&json!({"drag": [{"handle": "timeline:rollback"}, [origin.x, origin.y]]})).unwrap();
assert_eq!(h.app.session.doc.marker, None, "the marker stays at the end");
h.step(&json!({"drag": [{"handle": "timeline:Second"}, [bodies.x, bodies.y]]})).unwrap();
assert_eq!(order(&h), before, "the feature keeps its place");
let first = handle_at("timeline:First").unwrap();
h.step(&json!({"drag": [{"handle": "timeline:Second"}, [first.x, first.y - 8.0]]})).unwrap();
assert_eq!(order(&h), vec!["Second".to_string(), "First".to_string()], "the first feature's top is still a place");
// Under the browser too; not in the icons-only width, nor in the bottom strip.
h.app.preferences.timeline_under_browser = true;
h.frames(4);
assert!(in_history("row:Origin").is_some());
h.app.preferences.timeline_under_browser = false;
h.app.preferences.timeline_left_width = crate::ui_kit::history_width(false);
h.frames(4);
assert!(in_history("row:Origin").is_none(), "no room for the rows without names");
h.app.preferences.timeline_left = false;
h.frames(4);
assert_eq!(crate::scenario::handles("row:Origin").into_iter().filter(|(n, _)| n == "row:Origin").count(), 1, "only the browser's");
}
/// In a design with components, the Bodies folder is the active component's, in the
/// placement being edited, as the browser lists it under that placement.
#[test]
fn the_history_lists_the_active_components_bodies() {
let mut h = Harness::new();
h.app.preferences.timeline_left = true;
h.app.preferences.timeline_left_width = 240.0;
h.app.preferences.timeline_origin_bodies = true;
h.app.run("solid.box", json!({"length": 10, "width": 10, "height": 10, "body_name": "RootBlock"})).unwrap();
h.app.run("component.create", json!({"name": "Part"})).unwrap();
h.app.run("solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [20, 0, 0], "body_name": "Inside"})).unwrap();
h.frames(4);
assert!(in_history("row:Inside").is_some() && in_history("row:RootBlock").is_none(), "the active component's bodies");
assert!(in_history("row:Origin").is_some());
h.app.run("component.activate", json!({"component": "root"})).unwrap();
h.frames(4);
assert!(in_history("row:RootBlock").is_some() && in_history("row:Inside").is_none(), "the root's own bodies");
}
#[test]
fn rollback_bar_above_last_feature_can_be_dragged_to_the_end() {
let mut harness = Harness::new();
@@ -0,0 +1,22 @@
[
{"note": "#6490: Show origin and bodies at the top. The History on the left starts with the Bodies folder and the Origin, the browser's own rows; their folds and eyes work there. The browser is hidden so every row handle below is the History's."},
{"call": "engine.execute", "params": {"command": "solid.box", "params": {"length": 10, "width": 10, "height": 10, "body_name": "Block"}}},
{"call": "ui.set", "params": {"showBrowser": false}},
{"call": "engine.execute", "params": {"command": "view.history_layout", "params": {"dock": "left"}}},
{"frames": 3},
{"note": "Off by default: the History lists only the features."},
{"expect": {"hidden_handles": ["row:Bodies", "row:Origin"]}},
{"call": "ui.prefs", "params": {"timeline_origin_bodies": true}},
{"frames": 3},
{"expect": {"shown_handles": ["row:Bodies", "row:Block", "row:Origin"], "hidden_handles": ["row:XY"]}},
{"click": {"handle": "row:Origin"}},
{"frames": 2},
{"expect": {"shown_handles": ["row:XY", "row:XZ", "row:YZ", "eye:XY"]}},
{"click": {"handle": "eye:Block"}},
{"frames": 2},
{"expect": {"hidden": ["Block"]}},
{"note": "The History at the bottom is unchanged."},
{"call": "engine.execute", "params": {"command": "view.history_layout", "params": {"dock": "bottom"}}},
{"frames": 3},
{"expect": {"hidden_handles": ["row:Bodies", "row:Origin"]}}
]
+6
View File
@@ -129,6 +129,12 @@ General › **Show text under ribbon icons** is a separate, saved option for eit
layout. Turn it off for shorter icon-only command buttons; tooltips, section names
and command menus remain available.
Interface › Layout › **Show origin and bodies at the top** (off by default) puts the active
component's Bodies folder and the Origin (planes, axes and point) at the top of the History when
it sits on the left or under the browser and is wide enough for names. They are the browser's own
rows: the same eyes, folds and right-click menus, so one list is enough for single-part work. The
History at the bottom is unchanged.
### Colour themes
Interface › **Theme** lists Dark, Light and System (follows the operating system), the built-in
File diff suppressed because one or more lines are too long