// Copyright (c) 2026 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT // A single label showing "Y "/"N " + the caller's text -- no background, // matching the old widget exactly. Toggling itself (checked) is driven // externally, typically by a Menu handing it LEFT/RIGHT via // directionInput() while this checkbox is the highlighted item. class Checkbox extends UIElement { init() { this.label = new Label(); this.add(this.label); this._text = ''; this._checked = false; this.highlighted = false; this._refresh(); } get text() { return this._text; } set text(value) { this._text = value; this._refresh(); } get checked() { return this._checked; } set checked(value) { this._checked = value; this._refresh(); } toggle() { this.checked = !this.checked; } setHighlighted(highlighted) { this.highlighted = highlighted; this.label.color = highlighted ? Checkbox.COLOR_HIGHLIGHTED : Checkbox.COLOR_NORMAL; } // Menu direction-input opt-out hook: LEFT/RIGHT toggles and consumes // the input; UP/DOWN falls through to default cursor movement. directionInput(dx, dy) { if(dx === 0) return false; this.toggle(); return true; } _refresh() { this.label.text = (this._checked ? 'Y ' : 'N ') + this._text; } } Checkbox.COLOR_NORMAL = { r: 255, g: 255, b: 255, a: 255 }; Checkbox.COLOR_HIGHLIGHTED = { r: 255, g: 0, b: 0, a: 255 }; module.exports = Checkbox;