ButtonSurface04 / 11

Buttons and their state

Connect a button’s appearance to its hit area.

Result

PixiJS · Cyber UI

Press the button directly on the canvas. The form controls its type, dimensions, label, and colors.

Loading canvas…
Example controls
216
56

Preparing example…

ButtonSurface.draw() draws a button from the local point (0, 0). To handle presses, we set up its hit area separately.

import { Graphics, Rectangle } from 'pixi.js';
import { ButtonSurface, CyberPreset, TerminalUi } from '@gamedevland/cyber-ui';

const button = app.stage.addChild(new Graphics());
const t = CyberPreset.palette;
button.position.set(48, 160);
ButtonSurface.draw(button, {
  width: 220, height: 56, variant: 'primary',
  enabled: true, selected: false,
}, t);
TerminalUi.icon(button, 'play', 28, 28, 20, t.background);
button.hitArea = new Rectangle(0, 0, 220, 56);
button.eventMode = 'static';
button.on('pointertap', () => { console.log('Start requested'); });

This is input handling for a regular Pixi project. The SDK uses node.input. Text, keyboard navigation, focus, and the button’s action remain the application’s responsibility.

VariantUse
primary, dangerMain or destructive action
module, iconModule card or icon button
nav, segmentSelected navigation item or segment
switchToggle background
utility, lineBottom line or no background

For nav and segment, the drawing appears when selected: true. To add the toggle thumb, we also call ButtonSurface.toggle(button, 220, 56, selected, t). When state changes, we clear the drawing and update input and the label.

Sources ↗

Cyber UI Toolkit · ButtonSurface↗Variants and visual states.PixiJS · Events↗eventMode, hitArea, and pointertap.