Builtin Library
README.md
meter
Peak-style level meter built on canvas. Renders either a continuous
fill or N segmented LED rects, plus an optional peak indicator line.
Read-only — no interaction props. Peak-hold state lives in
ui.widgetState(id, ...) when an id is supplied; without one, the
meter still renders but the peak indicator is skipped.
Exports
meter(value: number?, opts: Opts?) -> any— build the meter canvas node. Returned directly by the module.
Types:
Style = { width?, height?, background?, fillColor?, warnColor?, clipColor?, offColor? }Opts = { id?, orientation?, segments?, warnThreshold?, clipThreshold?, peakHoldMs?, peak?, width?, height?, background?, fillColor?, warnColor?, clipColor?, offColor?, style? }
Usage
local meter = require("@builtin::modules.zui.widget.meter")
local widget = meter(state.master_l, {
id = "master-meter-l",
orientation = "horizontal",
style = { width = 220, height = 8,
fillColor = "#3cc864", warnColor = "#dcc83c",
clipColor = "#dc463c", background = "#101214" },
})
Notes
valueis clamped to[0, 1.5]so out-of-range inputs paint into the clip-coloured band without spilling outside the canvas.- Peak hold defaults to 1500ms then decays at 1.5/sec — matches the
deleted Rust
render_meteralgorithm. - Pass
opts.peakto override the computed peak — useful for ganged-channel meters where a single source value drives multiple visuals. - Vertical default is 12×160; horizontal flips to 160×12.