// Copyright (c) 2026 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT var Button = require('./Button.js'); var Menu = require('./Menu.js'); var Settings = require('./Settings.js'); // No render() override -- UIElement's base render() auto-renders whatever // was added() here, in add-order: background first, labels, then the // menu (and its two buttons) on top of it. class TestUIElement extends UIElement { init() { this.background = new Rectangle(); this.background.width = 220; this.background.height = 128; this.background.color = { r: 255, g: 0, b: 0, a: 255 }; this.add(this.background); this.label = new Label(); this.label.text = 'Hello World!'; this.label.x = 8; this.label.y = 8; this.add(this.label); this.label2 = new Label(); this.label2.text = 'Second label!'; this.label2.x = 8; this.label2.y = 24; this.add(this.label2); // A navigable 2-item Menu -- UP/DOWN moves the highlighted cursor // between the buttons, ACCEPT fires whichever one is highlighted. this.menu = new Menu(); this.add(this.menu); this.helloButton = new Button(); this.helloButton.text = 'Say hello'; this.helloButton.x = 8; this.helloButton.y = 48; this.helloButton.onSelect = () => Console.print('Hello!'); this.menu.addItem(this.helloButton); this.settingsButton = new Button(); this.settingsButton.text = 'Open settings'; this.settingsButton.x = 8; this.settingsButton.y = 84; this.settingsButton.onSelect = () => new Settings().open(); this.menu.addItem(this.settingsButton); this.menu.open(); } } module.exports = TestUIElement;