Builtin Library
README.md
scene
Pan/zoom 2D viewport. Wraps egui::containers::Scene (added 0.34).
Children render inside a transformed coordinate space — mouse-wheel
zooms, primary-drag pans (right-click stays free for context menus).
Transform state persists in egui's per-id temp data, so pan/zoom
carries across frames without caller plumbing.
Exports
scene(opts: SceneOpts?) -> any— build a pan/zoom 2D viewport widget. The module returns this function directly.
Types:
SceneOpts = { id: string?, props: { [string]: any }?, style: { [string]: any }?, children: { any }?, zoomRange: { number }?, initialPan: { x: number, y: number }?, initialZoom: number?, onTransformChange: string?, focusable: boolean? }
Usage
local scene = require("@builtin::modules.zui.widget.scene")
scene({
zoomRange = { 0.25, 4.0 },
onTransformChange = "graph:moved",
children = {
Z.canvas({ commands = drawNodes(state) }),
Z.area({ id = "node-1", pos = nodePos[1] }, { ... }),
},
})
Notes
zoomRangedefaults to[0.25, 4.0](overriding egui's default of0.0..=1.0so wheel-zoom works in both directions).initialPanandinitialZoomonly apply on the first frame; once the user pans or zooms the persisted rect takes over.onTransformChangepayload is a comma-separated string"panX,panY,zoom"— UiValue is scalar-only. Parse withstring.split(value, ","). Falls back to<id>-transformwhen not set.- Pan is primary-button only — right-click stays free for
Z.contextMenuhandlers on inner widgets.