Expand description
Scene — a pan/zoom container that hosts one child widget subtree in an
infinite scrollable/zoomable canvas.
§What it does
Scene applies a translation + uniform-scale transform (a
SceneTransform) to its content’s painting and its pointer input, so
the hosted widgets stay fully interactive while the user pans (drag on empty
background, or middle-drag) and zooms (mouse wheel, anchored on the cursor).
Double-clicking the empty background resets the view, matching egui’s
Scene container. The current visible region is exposed as a scene-space
rect via Scene::scene_rect / Scene::with_scene_rect_cell.
§The content is a first-class framework child
The hosted subtree lives in children
like any other container’s content, laid out in scene space (pinned at
the origin). The pan/zoom is injected through the framework’s
child_transform hook: painting,
hit-testing, event dispatch, focus, and the inspector all map coordinates
through that transform when they descend into the Scene, so the content is
fully interactive and reachable by:
- keyboard focus — Tab traversal and click-to-focus reach widgets inside the Scene, so text fields hosted here accept typing;
- the inspector — hosted widgets appear in the tree at their on-screen (transformed) bounds.
Scene’s own on_event handles only the
background gestures (pan / zoom / double-click reset). It receives a pointer
event exactly when no hosted child consumed it — the framework’s leaf→root
bubble delivers the press to the Scene only after the content declined it —
so a press on empty canvas pans while a press on a hosted button clicks the
button. While a pan is in progress the Scene claims the pointer
exclusively (see claims_pointer_exclusively) so the drag keeps landing on
the Scene regardless of what sits under the moving cursor.
Relationship to other modules: mirrors the builder style of
crate::widgets::ScrollView; the transform math lives in the
[transform] submodule (unit-tested independently); the background-gesture
handling lives in the [events] submodule.
Structs§
- Scene
- A pan/zoom canvas hosting a single content widget subtree.
- Scene
Transform - Translation + uniform scale mapping scene space to Scene-local screen space.
Constants§
- DEFAULT_
ZOOM_ RANGE - Default zoom range, matching egui’s
Scene(0.1..=2.0).