Class: Checkbox

Checkbox()

new Checkbox()

An interactive UI element that represents a boolean state (checked/unchecked).
Source:

Extends

  • BaseUIElement

Methods

(protected) _drawSelf(context, engine)

Specific drawing logic for the Checkbox. Called by BaseUIElement.render after visibility and context checks.
Parameters:
Name Type Description
context CanvasRenderingContext2D The rendering context.
engine
Source:

setChecked(checked, triggerCallbackopt)

Sets the checked state of the checkbox.
Parameters:
Name Type Attributes Default Description
checked boolean The new checked state.
triggerCallback boolean <optional>
false Whether to trigger the onClick callback.
Source:

toggle()

Toggles the checked state of the checkbox. Also triggers the onClick callback.
Source:

update(deltaTime, engine, mousePos)

Updates the checkbox's state based on mouse input.
Parameters:
Name Type Description
deltaTime number The time elapsed since the last frame.
engine
mousePos Object Current canvas-relative mouse position.
Source:

Checkbox(options)

new Checkbox(options)

Creates an instance of Checkbox.
Parameters:
Name Type Description
options object Configuration options for the checkbox.
Properties
Name Type Attributes Default Description
x number <optional>
0 The x-coordinate of the checkbox (top-left of the box).
y number <optional>
0 The y-coordinate of the checkbox (top-left of the box).
label string <optional>
'' Text label to display next to the checkbox.
isChecked boolean <optional>
false Initial checked state.
boxSize number <optional>
16 The size (width and height) of the checkbox square.
labelOffset number <optional>
5 Space between the checkbox and the label text.
font string <optional>
'16px sans-serif' Font for the label.
textColor string <optional>
'white' Color for the label text.
boxColor string <optional>
'white' Color of the checkbox border/box.
checkColor string <optional>
'dodgerblue' Color of the checkmark or fill when checked.
hoverBoxColor string <optional>
null Optional: Color of the box when hovered (if you implement hover visual state).
disabledColor string <optional>
'gray' Color for box and text when disabled.
disabledCheckColor string <optional>
'darkgray' Color for the checkmark when disabled and checked.
onClick function <optional>
Callback function when the checkbox is clicked (state toggled).
visible boolean <optional>
true Whether the checkbox is visible.
enabled boolean <optional>
true Whether the checkbox is enabled.
id string <optional>
Optional ID.
width number <optional>
Optional: Explicit width for the entire clickable area (box + label).
height number <optional>
Optional: Explicit height for the entire clickable area.
Source:

Methods

(protected) _drawSelf(context, engine)

Specific drawing logic for the Checkbox. Called by BaseUIElement.render after visibility and context checks.
Parameters:
Name Type Description
context CanvasRenderingContext2D The rendering context.
engine
Source:

setChecked(checked, triggerCallbackopt)

Sets the checked state of the checkbox.
Parameters:
Name Type Attributes Default Description
checked boolean The new checked state.
triggerCallback boolean <optional>
false Whether to trigger the onClick callback.
Source:

toggle()

Toggles the checked state of the checkbox. Also triggers the onClick callback.
Source:

update(deltaTime, engine, mousePos)

Updates the checkbox's state based on mouse input.
Parameters:
Name Type Description
deltaTime number The time elapsed since the last frame.
engine
mousePos Object Current canvas-relative mouse position.
Source: