From 75b4ce7ed6375db2a22f3dfb5ea63f669b616e48 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Tue, 17 Nov 2026 19:18:07 -0700 Subject: [PATCH] fix(stage): resizing the Timeline or a dock keeps the artwork where it is on screen (M1) The pan is measured from the canvas centre, so a panel that grew or shrank moved the artwork. A view the artist chose now takes up the centre's move; a view still as Fit in Window left it goes on fitting. Idea from outside PR #424 (Call4han), done for every canvas change rather than only while a dock edge is dragged. Fixes #423 --- src/dock_ui.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/stage.rs | 14 ++++++++++++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/dock_ui.rs b/src/dock_ui.rs index 6e75e7ae..939ed1b1 100644 --- a/src/dock_ui.rs +++ b/src/dock_ui.rs @@ -1410,6 +1410,57 @@ mod tests { app.dock_view.drawn.iter().find(|d| d.over == over).copied() } + /// #423: dragging the Timeline's top edge covers or reveals the stage; the artwork keeps its + /// place on screen and its zoom, during the drag and after the release. A view that is still + /// as Fit in Window left it goes on fitting, and Fit in Window fits again afterwards. + #[test] + fn resizing_the_timeline_keeps_the_artwork_where_it_is_on_screen() { + let origin = |app: &App| { + let size = vec2(app.s.doc.stage.width as f32, app.s.doc.stage.height as f32); + app.stage_cache.canvas.center() + app.view.pan - size * app.view.zoom * 0.5 + }; + let drag_edge = |ctx: &egui::Context, app: &mut App, check: &mut dyn FnMut(&App)| { + let edge = drawn(app, Over::Group(Side::Bottom)).expect("the Timeline dock is drawn").header.center_top(); + frame(ctx, app, pointer(edge, None)); + frame(ctx, app, pointer(edge, Some(true))); + for i in 1..=8 { + frame(ctx, app, pointer(edge - vec2(0.0, i as f32 * 12.0), None)); + check(app); + } + frame(ctx, app, pointer(edge - vec2(0.0, 96.0), Some(false))); + settle(ctx, app); + check(app); + }; + // The artist's own view: 50 %, panned. + let (mut app, ctx) = app(); + settle(&ctx, &mut app); + app.view.zoom = 0.5; + app.view.pan = vec2(73.0, -29.0); + settle(&ctx, &mut app); + let (before, height) = (origin(&app), app.stage_cache.canvas.height()); + drag_edge(&ctx, &mut app, &mut |app| { + assert!((origin(app) - before).length() < 0.5, "the artwork moved: {:?} -> {:?}", before, origin(app)); + assert_eq!(app.view.zoom, 0.5, "the zoom changed"); + }); + assert!(app.stage_cache.canvas.height() < height - 40.0, "the drag must resize the Timeline"); + // Fit in Window still fits and centres. + app.view.fit = true; + settle(&ctx, &mut app); + let size = vec2(app.s.doc.stage.width as f32, app.s.doc.stage.height as f32); + assert_eq!(app.view.pan, egui::Vec2::ZERO); + assert!((origin(&app) + size * app.view.zoom * 0.5 - app.stage_cache.canvas.center()).length() < 0.5); + // And a view left as fitted keeps fitting the smaller or larger canvas. + let fitted = app.view.zoom; + let edge = drawn(&app, Over::Group(Side::Bottom)).expect("the Timeline dock is drawn").header.center_top(); + frame(&ctx, &mut app, pointer(edge, None)); + frame(&ctx, &mut app, pointer(edge, Some(true))); + frame(&ctx, &mut app, pointer(edge + vec2(0.0, 60.0), None)); + frame(&ctx, &mut app, pointer(edge + vec2(0.0, 60.0), Some(false))); + settle(&ctx, &mut app); + assert_eq!(app.view.pan, egui::Vec2::ZERO, "a fitted view stays centred"); + assert!(app.view.zoom > fitted, "a fitted view fits the larger canvas: {} -> {}", fitted, app.view.zoom); + } + #[test] fn tabs_shrink_to_fit_and_short_names_stay_whole() { // They fit: as they are. diff --git a/src/stage.rs b/src/stage.rs index 58223237..794f34bf 100644 --- a/src/stage.rs +++ b/src/stage.rs @@ -60,6 +60,8 @@ pub struct Cache { /// `(ready, needed)` visible tiles this frame. pub ready: (usize, usize), pub canvas: Rect, + /// The stage has been laid out once, so `canvas` is where it really was last frame. + laid_out: bool, pub service: Option, /// Document state of the picture on screen (an edit makes it differ). pub shown_state: Option, @@ -73,7 +75,7 @@ pub struct Cache { impl Default for Cache { fn default() -> Self { - Cache { tiles: Vec::new(), tick: 0, ms: 0.0, ready: (0, 0), canvas: Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0)), service: None, shown_state: None, gpu: Default::default(), drawn_by: None, pattern: None } + Cache { tiles: Vec::new(), tick: 0, ms: 0.0, ready: (0, 0), canvas: Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0)), laid_out: false, service: None, shown_state: None, gpu: Default::default(), drawn_by: None, pattern: None } } } @@ -214,7 +216,8 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { crate::camera_tool::on_tool_change(app); crate::shape_envelope::settle(app); crate::camera_tool::tick(app, ui.ctx(), now); - app.stage_cache.canvas = canvas; + let canvas_was = std::mem::replace(&mut app.stage_cache.canvas, canvas); + let laid_out = std::mem::replace(&mut app.stage_cache.laid_out, true); let resp = ui.allocate_rect(canvas, Sense::click_and_drag()); // The drawing surface: Ctrl+F6 lands here, and screen readers hear the tool in hand. crate::a11y::anchor(ui, crate::a11y::Region::Stage, canvas, &resp); @@ -229,6 +232,13 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { { app.view.fit = true; } + // Otherwise the artist chose this view, and a panel that grows or shrinks (the Timeline's + // top edge, a dock, the rulers, the window) only covers or reveals the stage: the artwork + // stays where it is on screen (#423). The pan is measured from the canvas centre, so it + // takes up the centre's move. + if laid_out && !app.view.fit && canvas_was != canvas && canvas_was.width() > 10.0 && canvas_was.height() > 10.0 { + app.view.pan += canvas_was.center() - canvas.center(); + } if app.view.fit && canvas.width() > 10.0 && canvas.height() > 10.0 { app.view.zoom = ((canvas.width() - 64.0) / size.x).min((canvas.height() - 64.0) / size.y).clamp(0.05, 64.0); app.view.pan = egui::Vec2::ZERO;