What it does
component_view
Generic data-driven component inspector renderer. Detects the shape
of incoming component data (vec3, quat, color, scalar, array, nested
table) and renders an appropriate zui widget tree. Used by the
editor's entity inspector so every component shows usefully without
needing a hand-written view per component.
Shape detection (most-specific first): colour → quat → vec3 → scalar array → scalar → nested table.
Exports
ComponentView.render(name: string, data: any, opts: RenderOpts?) -> any— render a single component as azuicollapsible. Unwraps{ value = ... }single-key wrappers (e.g. theNamecomponent) and skips internal__type/__opaquemetadata keys.
Types:
RenderOpts = { id_prefix?: string, default_open?: boolean }.
Defaults:
id_prefixdefaults to"cv". Widget ids are<id_prefix>-<name>-….default_opendefaults tofalse.
Usage
local ComponentView = require("@builtin::modules.engine.editor.component_view")
local node = ComponentView.render("Transform", {
position = { x = 0, y = 0, z = 0 },
rotation = { x = 0, y = 0, z = 0, w = 1 },
scale = { x = 1, y = 1, z = 1 },
})
Notes
- Max recursion depth is 8 (
MAX_DEPTH); deeper values render as a<max depth>label. - Max children per table is 80 (
MAX_CHILDREN); excess entries collapse into a... (N more)tail. - Number formatting goes through
JsonUtils.formatNumberfor WASM safety (nostring.format("%.3f")reliance). - Colours use
Z.node("colorSwatch", ...)(display widget) rather thanZ.colorPicker(which opens egui's popup on click). The id suffix-swatchis load-bearing for the swatch path. - Booleans render as disabled checkboxes (read-only inspector).
Discussion
Scoped to this part · feeds back into the world's score.
Sign in to post.sign in
No comments yet. Be the first.