Checkbox
A box the player can check and uncheck, with an optional label. The whole row is the hit area, and it grows on touch and console so it is easy to hit with a thumb or a gamepad. It comes in the same sizes as the other controls, and a row is as tall as a Button of its size.


Lucy.Stack.new({
gap = "Space2",
children = {
Lucy.Checkbox.new({
label = "Mute music",
onCheckedChange = function(checked)
app.state:set("settings.music", if checked then 0 else 80)
end,
}),
Lucy.Checkbox.new({ label = "Light show", checked = true }),
Lucy.Checkbox.new({ label = "Show my dance combo", checked = true }),
},
Parent = parent,
})
Props
| Prop | Type | Default | State key | What it does |
|---|---|---|---|---|
checked | boolean | false | yes | Whether the box is checked |
label | string | "" | yes | Text beside the box |
children | table | Anything after the label in its slot, such as a “NEW” badge. They take the label’s look and fade when disabled | ||
disabled | boolean | false | yes | Greys it out and ignores clicks |
size | "sm" | "md" | "lg" | "xl" | "md" | yes | The box, the tick, the label’s text and the row’s height, as a Button of the same size |
visible | boolean | true | yes | Shows or hides it |
onCheckedChange | function | Called with (checked, handle) when it changes |
It also takes the props every component takes.
Methods
| Name | What it does |
|---|---|
checkbox:toggle() | Checks it if unchecked, unchecks it if checked |
Examples
Keep a ref and a checkbox in step. Writing the ref checks the box, and checking the box writes the ref:


local muted = Lucy.ref(false)
Lucy.Checkbox.new({ label = "Mute the crowd", checked = muted, Parent = settings })
muted(true) -- the box is now checked
Read it from app state by id:


Lucy.Checkbox.new({ id = "rules", label = "I agree to the club rules", Parent = welcome })
if app.state:get("ui.rules.checked") then
enterLobby()
end
A checkbox comes in the same sizes as the other controls, and each size is as tall as a Button of that size, so it lines up beside them. Go a size up where it sits next to big buttons, such as a “don’t show this again” beside a large ENTER THE CLUB:


Lucy.Stack.new({
gap = "Space3",
children = {
Lucy.Checkbox.new({ label = "Small", size = "sm", checked = true }),
Lucy.Checkbox.new({ label = "Medium", size = "md", checked = true }),
Lucy.Checkbox.new({ label = "Large", size = "lg", checked = true }),
Lucy.Checkbox.new({ label = "Extra large", size = "xl", checked = true }),
},
Parent = parent,
})
Preview
In Studio, from the command bar: Lucy.Preview.show("Checkbox").