← All scene elements
SCENE ELEMENT / 02

Button

Touch and mouse input with local actions and MQTT output.

LIVE WEB PLAYER

See it respond.

The same raylib runtime, compiled to WebAssembly. Load this example, inject MQTT messages and watch its published events.

Loading WebAssembly…
MQTT I/O
Waiting for runtime…

The browser requires a user action before the scene is loaded. Click Load demo scene first. MQTT is emulated and never leaves this page. Shaders are disabled in the web build; GPIO is hardware-only.

Mouse/touch button. Publishes press/release states, can execute actions, and can be used directly in interactive_dialog.choice_input_ids.

Configuration

FieldDescription
typebutton
textLabel
texture, pressed_textureOptional normal/pressed image assets
font, font_sizeTTF asset and pixel size
text_color, pressed_text_colorLabel colours
bg_color, pressed_bg_colorFill colours
border_color, pressed_border_colorBorder colours
border_thicknessBorder width
on_press, on_releaseAction chains

Copy-and-paste JSON

json
{
  "type": "button",
  "id": "choice_a",
  "pos": [120, 700],
  "size": [760, 80],
  "text": "A. Ask about the alibi",
  "font": "Technology.ttf",
  "font_size": 30,
  "text_color": "#FFFFFFFF",
  "bg_color": "#203050FF",
  "pressed_bg_color": "#406090FF",
  "border_color": "#58A6FFFF",
  "pressed_border_color": "#FFFFFFFF",
  "border_thickness": 2,
  "on_press": "status_text.set('A selected')",
  "layer": 3
}

MQTT

text
Published topic: ergs/rpi01/status/choice_a/click
Press payload:   ON
Release payload: OFF

ergs/rpi01/visible/choice_a              OFF