diff --git a/crates/ui-egui/src/chrome/status_bar.rs b/crates/ui-egui/src/chrome/status_bar.rs index e4a9e91d82..1593562503 100644 --- a/crates/ui-egui/src/chrome/status_bar.rs +++ b/crates/ui-egui/src/chrome/status_bar.rs @@ -39,8 +39,6 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) { // An angle between the presets, from the Rotate View tool or `view.rotate`, shows in whole degrees; adding 0.0 // turns the -0 of a small negative angle into 0. let degrees = rotation.round() + 0.0; - let revision = st.map(|d| (d.uid, d.revision)); - let artboards = st.map_or(&[][..], |d| d.doc.artboards.as_slice()); let mut picks = Vec::new(); let shows: Vec> = StatusBarShow::ALL.into_iter().map(|s| Entry::new(s, s.label()).checked(app.ui.status_bar_show == s)).collect(); @@ -95,7 +93,8 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) { let zoom = ZoomControls { zoom: canvas_zoom, document, scaling, print, shown_zoom, has_view: view.is_some(), lang, picked: Outbox::new(&mut picks) }; let _ = MemoView::new("status-bar-zoom", zoom, show_zoom).show(ui); - let navigation = Navigation { has_view: view.is_some(), turned, degrees, cur, revision, artboards, lang, picked: Outbox::new(&mut picks) }; + let artboards = st.map_or_else(Vec::new, |d| d.doc.artboards.iter().map(|a| a.name.as_str()).collect()); + let navigation = Navigation { has_view: view.is_some(), turned, degrees, cur, artboards, lang, picked: Outbox::new(&mut picks) }; let _ = MemoView::new("status-bar-navigation", navigation, show_navigation).show(ui); Divider::vertical().show(ui); // An empty readout shows a dash. @@ -237,10 +236,9 @@ struct Navigation<'a> { degrees: f64, /// The artboard the navigator shows. cur: usize, - /// The active document's uid and revision. - revision: Option<(u64, u64)>, - #[memo_props(covered_by = "revision", reason = "a document's uid and revision change with every edit of it")] - artboards: &'a [vectorcraft_doc::Artboard], + /// The names of the active document's artboards, in order, which the navigator lists. Edits that leave them + /// alone, such as the frames of a drag, replay the controls. + artboards: Vec<&'a str>, #[memo_props(hash = "an interface language: an index into the languages offered")] lang: crate::i18n::Lang, /// What the controls chose in the pass. @@ -291,7 +289,7 @@ fn show_navigation(p: &mut Navigation<'_>, ui: &mut Ui) { p.picked.send(NavigationPick::Artboard(json!(to))); } } - let boards: Vec> = p.artboards.iter().enumerate().map(|(i, a)| Entry::new(i, format!("{} {}", i + 1, a.name))).collect(); + let boards: Vec> = p.artboards.iter().enumerate().map(|(i, name)| Entry::new(i, format!("{} {}", i + 1, name))).collect(); let mut go = None; Field::new(tl!("Artboard")).side(SideLabel::new().kind(LabelKind::Hidden)).show(ui, |ui, _| { // With no document the navigator shows a dash, as the info readout does. @@ -433,6 +431,33 @@ mod tests { assert!(panel.enabled("Next Artboard") || panel.enabled("Previous Artboard"), "the navigator counts the new artboard"); } + /// Edits that leave the artboards' names alone, such as the steps of a drag, replay the Rotation menu and the + /// artboard navigator; renaming an artboard runs them, and the navigator shows the new name. + #[test] + fn edits_that_keep_the_artboard_names_replay_the_navigation_controls() { + let runs = || NAVIGATION_RUNS.with(std::cell::Cell::get); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); + app.view_mut().unwrap().rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(600.0, 400.0)); + app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); + let mut panel = Panel::new(app, status_bar); + panel.room(egui::vec2(1200.0, 300.0)); + panel.frame(); + panel.frame(); + let (before, revision) = (runs(), panel.app().session.active().unwrap().revision); + for _ in 0..10 { + panel.app().run("object.move", json!({"dx": 1, "dy": 0})).unwrap(); + panel.frame(); + } + assert!(panel.app().session.active().unwrap().revision > revision, "each move is an edit of the document"); + assert_eq!(runs(), before, "moves do not run the navigation controls"); + panel.app().run("artboard.rename", json!({"indices": [0], "name": "Front"})).unwrap(); + panel.frame(); + panel.frame(); + assert!(runs() > before, "a rename runs them again"); + assert_eq!(panel.value("Artboard").as_deref(), Some("1 Front"), "and the navigator shows the new name"); + } + /// Scrolling the view moves its center and nothing the navigation controls show, so frames of a wheel pan replay /// them; a new zoom runs only the Zoom field and its presets, not the Rotation menu and the artboard navigator. #[test]