Skip to content

PixelUI.CheckBox

Extends: PixelUI.Widget

A checkbox widget with support for checked, unchecked, and indeterminate states. Provides visual feedback and change callbacks.

Properties

NameTypeDescription
labelstringLabel text displayed next to the checkbox
checkedbooleanWhether the checkbox is checked
indeterminatebooleanWhether the checkbox is in an indeterminate state
allowIndeterminatebooleanWhether the indeterminate state is allowed
focusBgPixelUI.Color?Background color when focused
focusFgPixelUI.Color?Foreground color when focused
onChangefun(self:PixelUI.CheckBox,

Methods

new

lua
new()

_notifyChange

lua
_notifyChange()

_setState

lua
_setState()

setLabel

lua
setLabel()

setOnChange

lua
setOnChange()

setAllowIndeterminate

lua
setAllowIndeterminate()

setChecked

lua
setChecked()

isChecked

lua
isChecked()

setIndeterminate

lua
setIndeterminate()

isIndeterminate

lua
isIndeterminate()

toggle

lua
toggle()

_activate

lua
_activate()

draw

lua
draw()

handleEvent

lua
handleEvent()

Examples

Basic
lua
local pixelui = require("pixelui")
local app = pixelui.app()

-- Simple checkbox
local checkbox = app:checkbox({
    x = 2, y = 2,
    label = "Enable feature",
    checked = false,
    onChange = function(self, checked)
        -- Handle state change
    end
})
app.root:addChild(checkbox)

app:run()
Advanced
lua
local pixelui = require("pixelui")
local app = pixelui.app()

-- Checkbox with indeterminate state and focus styling
local parentCheck = app:checkbox({
    x = 2, y = 2,
    label = "Select All",
    checked = false,
    allowIndeterminate = true,
    focusBg = colors.blue,
    focusFg = colors.white
})

local child1 = app:checkbox({ x = 4, y = 4, label = "Option 1" })
local child2 = app:checkbox({ x = 4, y = 6, label = "Option 2" })

-- Sync parent state with children
local function updateParent()
    local c1, c2 = child1.checked, child2.checked
    if c1 and c2 then
        parentCheck:setChecked(true)
        parentCheck:setIndeterminate(false)
    elseif not c1 and not c2 then
        parentCheck:setChecked(false)
        parentCheck:setIndeterminate(false)
    else
        parentCheck:setIndeterminate(true)
    end
end

child1.onChange = function() updateParent() end
child2.onChange = function() updateParent() end

app.root:addChild(parentCheck)
app.root:addChild(child1)
app.root:addChild(child2)

app:run()

Released under the MIT License.