Repository navigation
feat(rune-kit): Canvas and ZoomPan, a zoom/pan/fit pane for any content - #2180
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #720.
What
Adds a
rune_kit::zoom_panmodule, exportingCanvasandZoomPan: a zoom/pan pane for arbitrary content (a tree, a diagram, a chart), not only images.ZoomPanis the app-owned state.Fit/Heldenum: it fits the content until a hand touches it and refits on resize only until then. A touched view survives a resize.scale()gives the effective scale andfitted()whether it is still fitting.to_content/to_viewportmap pane points through the transform, andcontent_rect()gives where the content draws.fit,zoom_at,zoom_byandpan_bychange the view. Pan clamping is the image preview'sclamp_axis.Canvas::new(lens, content_size, el)andCanvas::scaled(lens, content_size, |scale| el)draw the content.El::scaleabout its top-left (origin(0, 0)) in a clipped, focusable pane..key,.label,.padding,.min_scale(0.25),.max_scale(8),.grows.scaledbuilds the content for the scale of the build it is in, so detail can drop out as soon as a resize changes the fit.+/=and-/_zoom by √2 and0fits, bare or with ⌘/Ctrl. A press focuses the pane.zoom_pan/gesture.rs,stepreturnsEffects).changelog/unreleased/2026-11-25-kit-zoom-pan-canvas.md.image_zoomis unchanged.Testing
Not compiled or run: there was no Rust toolchain in the environment where this was written. Unit tests are in
crates/rune-kit/src/zoom_pan/tests.rsand cover:min_scalebounding the fit and leaving the content pannable;fitrestoring fitting;to_content/to_viewportround-tripping;The expected values were worked out by hand and the API calls checked against
rune's sources.scripts/file-size.shpasses and the hygiene grep is clean.Please run before merging:
Closes #720