DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Layout: Go Back and Go Forward wait for the view to be fitted
Marco Arnulfoa0790bcb55e4
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 721e46469..31362868c 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -284,6 +284,10 @@ fn note_jump(app: &mut DesignApp, to: bool) {/// Whether Layout ▸ Go Back (`step` < 0) or Go Forward has a page to go to from the view as it is.pub fn can_go_through_history(app: &DesignApp, step: isize) -> bool {let Some(st) = app.session.active().filter(|st| !st.editing_parents) else { return false };+ // A view still waiting to be fitted is refitted next frame, which would replace the destination.+ if !app.view().is_some_and(|v| v.fitted) {+ return false;+ }let ids = page_ids(&st.doc);let Some(mut h) = app.page_history().cloned() else { return false };if let Some((id, offset)) = page_in_view(app) {@@ -295,6 +299,9 @@ pub fn can_go_through_history(app: &DesignApp, step: isize) -> bool {/// Layout ▸ Go Back (`step` < 0) or Go Forward: show the page viewed before or after this one, where/// the view was on it (zoom kept).pub fn go_through_history(app: &mut DesignApp, step: isize) {+ if !app.view().is_some_and(|v| v.fitted) {+ return;+ }note_jump(app, false);let Some(ids) = app.session.active().filter(|st| !st.editing_parents).map(|st| page_ids(&st.doc)) else { return };let Some((id, offset)) = app.page_history_mut().and_then(|h| h.go(step, |id| ids.contains(&id))) else { return };diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex d6bd7cfec..8c0b3af46 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -4289,6 +4289,33 @@ mod tests {assert_eq!(page(&app), 4, "Go Back returns to the page before Next Page");}+ #[test]+ fn go_back_waits_for_the_view_to_be_fitted() {+ let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.session.execute("file.new", &json!({"pages": 7, "facingPages": true})).unwrap();+ let ctx = egui::Context::default();+ let frame = |app: &mut crate::DesignApp| {+ let input =+ egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1400.0, 900.0))), ..Default::default() };+ let mut out = ctx.run_ui(input, |ui| {+ app.logic(&ui.ctx().clone());+ app.ui(ui);+ });+ out.textures_delta.clear();+ };+ frame(&mut app);+ frame(&mut app);+ app.run("view.goToPage", json!({"page": 5})).unwrap();+ frame(&mut app);+ assert!(menu_enabled(&app, "view.goBack"));+ // Leaving parent pages through the Pages panel: the canvas refits on the next frame.+ app.view_mut().unwrap().fitted = false;+ assert!(!menu_enabled(&app, "view.goBack"), "the refit would replace where Go Back went");+ crate::canvas::go_through_history(&mut app, -1);+ frame(&mut app);+ assert!(menu_enabled(&app, "view.goBack"), "the unfitted Go Back used no history entry");+ }+#[test]fn next_spread_at_the_last_spread_is_no_jump() {let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());