Pre-Release — API subject to change

Panels

Part of the ProControls for p5.js documentation.

New here? See the Getting Started page for HTML setup, script tags, a minimal sketch, and the common options table.

Panel ModalPanel Bevel MessageDialog InputDialog

Panel Container

A clipping container that groups ProControls into a positioned, optionally scrollable surface. Controls added with .add() are positioned relative to the panel's top-left corner — a slider at (10, 10) appears 10px from the panel edge, not the canvas edge. When child controls extend beyond the panel bounds, thin scrollbars appear automatically; the scroll wheel pans the view when no child control is hovered.

Constructor options

OptionTypeDefaultDescription
x, ynumber20, 20Panel top-left position on the canvas.
widthnumber300Panel width in pixels.
heightnumber200Panel height in pixels.
visiblebooleantrueInitial visibility. Set panel.visible = false to hide the panel and suppress all child events.
labelstring''Title shown in a bar at the top of the panel. When set, the scrollable content area starts below the bar and a minimize/maximize button appears on the right side of the bar. No title bar is shown when empty.
minimizedbooleanfalseInitial minimized state. When true the panel starts collapsed to just the title bar.
minimizablebooleantrueWhen false the −/+ toggle button is hidden and the panel cannot be collapsed.
movablebooleantrueWhen false dragging the title bar does not reposition the panel.
resizablebooleanfalseWhen true a resize grip appears in the bottom-right corner; drag it to change the panel's width and height at runtime.
onChangefunctionnullonChange({ fieldName: value, … }[, panel]) — called with a snapshot of all child values whenever any child changes. See onChange / values below.
onReleasefunctionnullonRelease({ fieldName: value, … }[, panel]) — called with the same snapshot on release.
themeobject{}Partial theme override. See Themes.

Methods & properties

NameDescription
.add(control)Attach a ProControl to the panel. The control is removed from the global registry and managed by the panel from that point on. Returns the control so you can capture it: const s = pnl.add(new AnalogSlider(…)).
.onChangeCallback fired as onChange(snapshot[, panel]) whenever any child changes. Can be set at construction or assigned later.
.onReleaseCallback fired as onRelease(snapshot[, panel]) when the user releases any child control. Can be set at construction or assigned later.
.valuesRead-only getter. Returns a fresh { fieldName: value, … } snapshot of every child control's current value — same object shape as the onChange and onRelease arguments. Useful for polling the panel state without setting up a callback.
.visibleGet/set panel visibility. When set to false the panel and all children stop drawing and receiving events.
.minimizedGet/set minimized state. When true the panel collapses to only the title bar; the small −/+ button in the title bar also toggles this.
.minimizableRead/write. Hides the toggle button and disables collapse when false.
.movableRead/write. Prevents title-bar dragging when false.
.resizableRead/write. When true, a grip appears in the bottom-right corner allowing the user to drag-resize the panel.
.scrollX / .scrollYCurrent scroll offset in pixels. Read or write to programmatically scroll the panel.
.clone()Returns a new Panel with identical options and a deep copy of all child controls. The copy is positioned to the right of the original (or below if it would overflow the canvas). Each cloned child is independent — changing values on the copy does not affect the original.

onChange / onRelease / values

When onChange or onRelease are set, the panel listens to every child control and fires the respective callback — with a single snapshot object — on change or release. The same object is always available via panel.values.

Field names are derived from each control's label option with spaces and punctuation stripped (e.g. "Low Cut"LowCut). Controls without a label are named by class and a per-class counter: the first unlabelled AnalogSlider becomes AnalogSlider1, the second AnalogSlider2, and so on. MultiSlider and MultiDial follow the same rule — the slider/dial keys within their own values object also have spaces and punctuation stripped from the label.

Values per control type:

ControlValue in snapshot
AnalogSlider, Dialnumber
SwitchCurrent state label string (e.g. "On")
Selector, SliderSelectorSelected option string
MultiSlider, MultiDial{ name: value, … } object
GridPad2-D array of cell values
TagSelectorArray of selected tag strings
RangeSlider{ low, high }
XYPad{ x, y }
IconButtonboolean state
Markup, Menu, VUMeter, LEDMeter, ADSRDisplayomitted

Note: set any per-control onChange callbacks before calling panel.add(). Callbacks assigned after add() will work for the individual control but the panel notification will wrap the value that was set at add-time.

Scrolling

Scrollbars appear automatically when children extend beyond the panel boundaries. The scroll wheel scrolls the panel when the pointer is over the panel but not over a focused child control. If a child control (e.g. a Dial) is hovered, the scroll wheel is forwarded to that child instead. You can also drag the scrollbar thumbs directly.

Example — onChange

Example — grouped controls

Example — scrollable content


ModalPanel Container

A promise-based modal dialog that blocks all other controls while open. Add any ProControls to it with .add(), then call await modal.show() from an async function to display it. The canvas dims and all other control events are suspended until the user clicks Save (resolves with a values snapshot) or Cancel (resolves with null). Options can be re-supplied to show() to change the title or size on each invocation.

new ModalPanel(opts)

Constructor options

OptionTypeDefaultDescription
labelstring''Title shown in the header bar of the dialog.
widthnumber380Dialog width in pixels. Height is computed automatically from the controls added.
x, ynumbercenteredDialog position. When omitted the dialog is centered on the canvas each time show() is called.

Methods & properties

NameDescription
.add(control)Adds a ProControl to the modal. The control is detached from the global registry and managed by the modal. Returns the control for chaining. Call this at setup time, not inside show().
.show(opts?)Opens the modal and returns a Promise. Optionally pass { label, width, x, y } to override constructor values for this invocation. The promise resolves with a { name: value, … } snapshot when Save is clicked, or null when Cancel is clicked. Must be called with await from an async function.
.isOpenRead-only boolean. true while the dialog is visible. Use this to guard against opening a modal that is already showing.

Values snapshot

When the user clicks Save, show() resolves with an object keyed by each child control's name. Value types follow the same rules as Panel.values: sliders return a number, switches return their state string, XYPad returns { x, y }, and so on. Controls without a name are included under an auto-generated key. Display-only controls (Markup, VUMeter, LEDMeter, ADSRDisplay, Menu) are omitted.

Async requirement

Note: show() returns a Promise. The await keyword only works inside an async function. p5.js event handlers (mousePressed, keyPressed, etc.) support async — just declare them async function mousePressed() { … }. The sketch's draw() loop continues running normally while the modal is open, so animations and meters keep updating behind the backdrop.

Example

editable — click the canvas to open the modal

Re-opening with different options


Bevel Cosmetic

A decorative separator line that draws a bevel edge across the canvas or a parent Panel. Pass x to draw a vertical bevel; pass y to draw a horizontal bevel. Both can be passed together. Values are pixels from the top-left of the container, or a percentage string such as '50%' resolved against the canvas width/height or the parent Panel's content area. Three visual styles are available.

new Bevel(opts)

Options

OptionTypeDefaultDescription
xnumber | stringPosition of a vertical bevel line. Pixels from the left edge, or a percent string ('50%'). Omit to skip the vertical line.
ynumber | stringPosition of a horizontal bevel line. Pixels from the top edge, or a percent string ('50%'). Omit to skip the horizontal line.
stylestring'thin''thin' — 2px edge (1px dark shadow + 1px light highlight). 'deep' — 4px edge (2px darker shadow + 2px thin bevel), for a heavier inset look. 'color' — 2px edge using the current theme's accent color.
labelstring''Optional text centered on the bevel line. The background behind the text is filled with the panel color to cut the line, making the label appear to sit on the bevel. On a vertical bevel (x) the text is rotated 90°.
themeobject{}Partial theme override. The 'color' style uses theme.capIndicator; labels use theme.scaleText and theme.panel.

Notes

Example

editable — changes update the preview

Inside a Panel

editable — changes update the preview

MessageDialog Container

A self-sizing, movable dialog that displays a formatted text message and optional action buttons. The message string is word-wrapped to fit the dialog width. Buttons are arranged in a single row at the bottom; if multiple buttons are provided the dialog widens automatically to fit them all on one line. Drag the title bar to reposition.

new MessageDialog(opts)

Options

OptionTypeDefaultDescription
messagestring''The text to display. Use \n for explicit line breaks. Long lines are wrapped automatically to fit the dialog width.
buttonsstring[][]Button labels shown in a row at the bottom of the dialog. Omit or pass an empty array for a message-only dialog.
x, ynumber20, 20Canvas position.
widthnumberautoDialog width. Defaults to at least 220 px or wide enough to fit all buttons on one row, whichever is larger.
labelstring''Title bar text. When set a styled title bar is shown at the top and the dialog can be repositioned by dragging it.
movablebooleantrueWhen false the dialog cannot be dragged.
onButtonfunctionnullonButton(index, label[, control]) — called when a button is clicked.
disabledbooleanfalseDisables interaction and renders a translucent overlay.
themeobject{}Partial theme override. See Themes.

Properties

PropertyDescription
.messageRead/write. Reassigning triggers a layout rebuild on the next draw so the dialog resizes to fit the new text.
.buttonsRead/write. Reassigning the array rebuilds the button row on the next draw.
.movableRead/write. Toggle whether the dialog can be dragged at runtime.

Example

editable — changes update the preview

InputDialog Container

Extends MessageDialog with a single-line text input field between the message and the buttons. Clicking the input field captures keyboard events for typing, cursor movement, and editing. The cursor blinks and the text scrolls horizontally when the value overflows the field width. Pressing Enter fires onSubmit; clicking outside the field removes focus.

new InputDialog(opts)

Options

OptionTypeDefaultDescription
messagestring''Instructional text above the input. Supports \n and auto word-wraps.
inputValuestring''Initial text in the input field.
inputPlaceholderstring''Greyed hint text shown when the field is empty and unfocused.
buttonsstring[][]Button labels in a row at the bottom.
x, ynumber20, 20Canvas position.
widthnumberautoDialog width. Defaults to at least 220 px or wide enough to fit all buttons.
labelstring''Title bar text. When set the dialog can be dragged.
movablebooleantrueWhen false the dialog cannot be dragged.
onButtonfunctionnullonButton(index, label, value[, control]) — called when a button is clicked. value is the current input field text.
onSubmitfunctionnullonSubmit(value[, control]) — called with the current input text when Enter is pressed.
disabledbooleanfalseDisables all interaction.
themeobject{}Partial theme override. See Themes.

Properties

PropertyDescription
.inputValueRead/write. The current text in the field. Reassign to change it programmatically.
.inputPlaceholderRead/write. Hint text shown when the field is empty and unfocused.
.messageRead/write. Reassigning triggers a layout rebuild on the next draw.
.buttonsRead/write. Reassigning rebuilds the button row on the next draw.

Keyboard interaction

KeyEffect
Printable charactersInserted at the cursor position.
Backspace / DeleteRemoves the character before / after the cursor.
/ Moves the cursor one character.
Home / EndJumps to the start or end of the text.
EnterFires onSubmit(value[, control]).

Example

editable — changes update the preview