Checkbox

Use the checkbox() function to add a checkbox control to your scene.

const isRed = checkbox("Is red?");

update(() => {
    sphere(32)
        .color(isRed.value() ? "red" : "cyan");
});

Initial value

Set the optional initial value. By default, the initial value is false.

// Sets initial value to true
checkbox("Is red?", true);

Callback

You can provide a callback function that gets called whenever the checkbox value changes.

checkbox("Is red?", null, (value) => {
    console.log("Checkbox value changed to:", value);
});

Returns the Checkbox object:


Checkbox

Example usage:
checkboxObject.setValue(true);
const isChecked = checkboxObject.value();
field
container: HTMLDivElement
The container that contains the label and the input checkbox
Example
checkboxObject.container.style.borderColor = "teal";
field
checkbox: HTMLInputElement
The input checkbox element
Example
checkboxObject.checkbox.style.backgroundColor = "yellow";
field
label: HTMLLabelElement | null
The label element for the checkbox
Example
if (checkboxObject.label) {
    checkboxObject.label.textContent = "Visible";
}
method
value(): boolean
Returns whether the checkbox is checked
Example
const isChecked = checkboxObject.value();
method
setValue(value: boolean): void
Sets the checked state of the checkbox
Example
checkboxObject.setValue(false);