Pre-Release — API subject to change

Buttons

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.

IconButton XYPad GridPad Piano

IconButton Input

A square push button that renders a Material Symbols icon at its centre. Pass any icon name from the Material Symbols Outlined set as the icon option — the font is already included via the page's <link> tag. Supports momentary (default) and toggle modes. An optional text label is drawn inside the button below the icon.

new IconButton(opts)
Material Symbols font required. Add this to your <head>:
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined&display=block" rel="stylesheet">

Options

OptionTypeDefaultDescription
iconstring'star'Material Symbols icon name, e.g. 'play_arrow', 'volume_up', 'settings'. Full list at fonts.google.com/icons.
sizenumber44Width and height of the button in pixels. Both dimensions are equal.
togglebooleanfalseWhen true the button latches on each click, toggling .state between true and false. When false (default) the button fires once per click and does not latch.
statebooleanfalseInitial toggle state. Only meaningful when toggle: true.
iconSizenumberautoIcon font size in pixels. Defaults to round(size × 0.58).
x, ynumber0, 0Canvas position of the top-left corner.
labelstring''Text caption drawn inside the button below the icon.
onClickfunctionnullonClick({buttonState, label}[, control]) — called on release. buttonState is true on press, false on release; for momentary buttons always false.
disabledbooleanfalseSuppresses all interaction and draws a disabled overlay.
themeobject{}Partial theme override. See Themes.

Properties

PropertyDescription
.stateRead/write. Current toggle state (true/false). Setting programmatically does not fire onClick.
.iconRead/write. Change the displayed icon at any time.
.disabledRead/write. Disables or re-enables the button.

Example

editable — changes update the preview

XYPad Input

A two-axis drag surface. Click or drag to set X and Y values independently. Fires separate callbacks per axis. Y increases upward to match musical convention. Double-click to reset both axes to their initial values.

new XYPad(opts)

Options

OptionTypeDefaultDescription
widthnumber160Panel width in pixels.
heightnumber160Panel height in pixels.
minX / maxXnumber0 / 1Value range for the horizontal axis.
minY / maxYnumber0 / 1Value range for the vertical axis.
valueX / valueYnumbercenterCurrent X and Y position within the pad's range. Read or set at any time to get or move the crosshair programmatically.
scaleXstring'linear''linear' or 'log'. Log requires minX > 0.
scaleYstring'linear''linear' or 'log'. Log requires minY > 0.
crosshairColorstringtheme accentColor of the crosshair dot and lines.
onChangeXfunctionnullonChangeX(x[, control]) — called with the new X value when only X changes.
onChangeYfunctionnullonChangeY(y[, control]) — called with the new Y value when only Y changes.
onChangefunctionnullonChange({x, y}[, control]) — called when either axis changes.
onReleasefunctionnullonRelease({x, y}[, control]) — called on release.
springBackbooleanfalseWhen true, both axes animate back to their initial values after mouse/touch release.
springDurationnumber1.0Seconds for the spring animation to complete.

Example

editable — changes update the preview

Example — spring back to center

editable — changes update the preview

GridPad Input

A 2-D grid of cells with four modes: toggle flips each cell 0 ↔ 1 on click; percent raises or lowers each cell's 0–1 value while the mouse is held; button treats each cell as a momentary key with press/release callbacks and no stored value; colorselect cycles each cell through a list of colours on each click, with each colour mapped to a semantic value. Optional horizontal and vertical grouping draws a bevel separator every N cells. Double-click the label to reset all cells to their initial values.

new GridPad(opts)

Options

OptionTypeDefaultDescription
x, ynumber0Top-left position.
rowsnumber4Number of rows.
colsnumber4Number of columns.
modestring'toggle''toggle' — click to flip 0/1 · 'percent' — hold to raise/lower · 'button' — momentary press · 'colorselect' — click to cycle through colours.
optionsarray[]colorselect mode only. Each entry is either a colour string ('red', '#ff0000') or an object { color, value } where value is the semantic value returned by onChange. When value is omitted it defaults to the colour string.
cellSizenumber20Pixel size of each square cell.
cellGapnumber2Gap in pixels between cells.
hGroupnumber0Draw a bevel separator every N columns. 0 disables.
vGroupnumber0Draw a bevel separator every N rows. 0 disables.
groupGapnumber4Extra pixels added at each group boundary.
valuesarrayall 0Initial 2-D array [[row][col]]. For colorselect, pass indices or semantic values — both are accepted. Ignored in button mode.
ratenumber0.02Percent change per frame while mouse is held (percent mode only).
labelstring''Label drawn below the grid.
themeobject{}Partial theme override. See Themes.
onChangefunctionnullonChange(values[, control]) — called with a 2-D copy of values when any cell changes. In colorselect mode the grid contains the semantic value for each cell.
onReleasefunctionnullonRelease(values[, control]) — toggle/percent: called with the values array on release. Button mode: called with ({r, c}[, control]) — row and column of the released cell.
onPress(row, col)functionnullButton mode only — called with the row and column of the pressed cell.

Interaction — toggle mode

ActionEffect
Click cellFlip value between 0 and 1.

Interaction — percent mode

ActionEffect
Hold left clickRaise value toward 1 at rate per frame.
Hold right clickLower value toward 0 at rate per frame.
Double-click at 0Snap to 1.
Double-click at 1Snap to 0.
Double-click mid-rangeSnap to whichever boundary is closer.

Interaction — button mode

ActionEffect
Press cellCell highlights; onPress(row, col) fires.
ReleaseCell returns to default; onRelease({r, c}) fires.

Interaction — colorselect mode

ActionEffect
Left clickAdvance to the next colour in options, wrapping around.
Right clickStep back to the previous colour.
Double-click labelReset all cells to their initial colour (index 0 by default).

Public API

MemberDescription
values (getter)Returns a deep copy of the 2-D values array. In colorselect mode returns semantic values, not indices.
getValue(r, c)Returns the value at row r, column c. In colorselect mode returns the semantic value of the current colour.
setValue(r, c, v)Sets the value at (r, c). In toggle mode snapped to 0/1; percent clamped 0–1; colorselect accepts an index integer.

Example — toggle mode (step sequencer)

editable — changes update the preview

Example — percent mode (velocity matrix)

editable — changes update the preview

Example — colorselect mode

editable — changes update the preview

Piano Input

An interactive keyboard component that displays chromatic piano keys. Click any key to select a note. Supports highlighting multiple notes for chords or scales. Perfect for music interfaces or note selection.

new PianoPad(opts)

Options

OptionTypeDefaultDescription
firstNotestring'C4'Starting note as a string, e.g., 'C4', 'G#3', 'Eb2'. Uses standard music notation.
noteCountnumber25Number of chromatic notes to display. 25 notes spans two octaves + one note (C4 to C6).
highlightedNotesstring[][]Array of note strings to highlight visually (e.g., ['C4', 'E4', 'G4'] for a C major chord).
widthnumber500Keyboard width in pixels.
heightnumber120Keyboard height in pixels.
onChangefunctionnullonChange({note, midi, octave, state}[, control]) — called when a key's state changes. note is the note string (e.g., 'C#4'), midi is the MIDI number (0-127), octave is the octave number, state is 'on' (pressed), 'off' (released), or 'highlight' (hovered).
onReleasefunctionnullonRelease({note, midi, octave, state}[, control]) — called when the mouse is released from a pressed key. state is always 'off'.

Interaction

Examples

Basic Piano

Simple keyboard with default settings:

Piano with Chord

Highlight notes to show chords or scales: