// Copyright (c) 2026 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT // Gamepad/keyboard-only for now -- no mouse support exists in the input // system yet. Something else (e.g. a future Menu widget) is responsible // for moving `highlighted` between multiple buttons; a Button only knows // how to fire onSelect() when ACCEPT is pressed while it's the highlighted // one. class Button extends UIElement { init() { this.background = new Rectangle(); this.background.width = 120; this.background.height = 32; this.background.color = Button.COLOR_NORMAL; this.add(this.background); this.label = new Label(); this.label.x = 8; this.label.y = 8; this.add(this.label); this.highlighted = false; this.onSelect = null; } get text() { return this.label.text; } set text(value) { this.label.text = value; } setHighlighted(highlighted) { this.highlighted = highlighted; this.background.color = highlighted ? Button.COLOR_HIGHLIGHTED : Button.COLOR_NORMAL; } update() { this.updateChildren(); if(this.highlighted && Input.pressed(InputBind.ACCEPT) && this.onSelect) { this.onSelect(); } } } Button.COLOR_NORMAL = { r: 255, g: 255, b: 255, a: 255 }; Button.COLOR_HIGHLIGHTED = { r: 255, g: 0, b: 0, a: 255 }; module.exports = Button;