diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-27 16:11:29 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-27 16:11:29 +0100 |
| commit | d465654e42ff6f7dfc52884d93c85143fdd8336e (patch) | |
| tree | 6dd0249104d0ce2a9e69d3b48fb1b3c5f9b2adba /crates/wipfel/src/app.rs | |
| parent | acd22ac3f2740d075806845805a5b26490ca4c3b (diff) | |
web: always redraw when the canvas CSS size changes
The ResizeObserver only re-fit the image; with user_moved set (after
any manual pan/zoom) it did nothing, so the canvas backing store kept
its old dimensions and the browser stretched the stale bitmap —
visible distortion on sidebar collapse and window resize. The
observer now always bumps the redraw tick (backing store resyncs in
the draw effect, compass included) and re-fits additionally when the
view has not been moved by hand.
Diffstat (limited to 'crates/wipfel/src/app.rs')
| -rw-r--r-- | crates/wipfel/src/app.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/crates/wipfel/src/app.rs b/crates/wipfel/src/app.rs index a4921ee..d2a66cb 100644 --- a/crates/wipfel/src/app.rs +++ b/crates/wipfel/src/app.rs @@ -246,14 +246,18 @@ pub fn app() -> Html { // Keep the fit correct even when layout was not ready at load time: // a ResizeObserver fires once with the element's initial size right - // after it starts observing, then on every later resize. Auto-fit - // whenever the user has not panned or zoomed by hand since the last - // image load — this is what makes the very first image appear. + // after it starts observing, then on every later resize (window + // resize, sidebar collapse, ...). Always bump the redraw tick so the + // canvas backing store tracks its CSS size — otherwise the browser + // stretches the stale bitmap — and additionally re-fit whenever the + // user has not panned or zoomed by hand since the last image load + // (this is also what makes the very first image appear). { let canvas_ref = canvas_ref.clone(); let fit = fit.clone(); let bitmap = bitmap.clone(); let user_moved = user_moved.clone(); + let tick = tick.clone(); use_effect_with((*bitmap).is_some(), move |has_image| { let observer = if *has_image { canvas_ref @@ -261,8 +265,10 @@ pub fn app() -> Html { .and_then(|c| { let fit2 = fit.clone(); let um = user_moved.clone(); + let tick2 = tick.clone(); let closure = wasm_bindgen::closure::Closure::wrap(Box::new( move |_entries: js_sys::Array, _obs: web_sys::ResizeObserver| { + tick2.set(*tick2 + 1); if !*um.borrow() { fit2.emit(MouseEvent::new("fit").unwrap()); } |
