Class rtk.CheckBox

Class Hierarchy

A dual- or tri-state checkbox with optional label. Checkboxes are specially styled buttons, so any attribute from rtk.Button applies here as well.

local cb = rtk.CheckBox{'Synchronize cardinal grammeters'}
container:add(cb)
cb.onchange = function(self)
   app.config.synchronize = self.value
end

CheckBox Type Constants

These constants apply to the type attribute.

rtk.CheckBox.DUALSTATE

'dualstate'

A conventional dual state checkbox (default)

rtk.CheckBox.TRISTATE

'tristate'

A tri-state checkbox with includes checked, unchecked, plus an indeterminate state.

CheckBox State Constants

These constants apply to the value attribute.

rtk.CheckBox.UNCHECKED

'unchecked'

The checkbox is unchecked (off).

rtk.CheckBox.CHECKED

'checked'

The checkbox is checked (on).

rtk.CheckBox.INDETERMINATE

'indeterminate'

The checkbox is neither checked nor unchecked but an indeterminate middle state.

Class API

Synopsis

Attributes
type checkboxtypeconst

read/write

The type of checkbox, whether dual or tri state (default DUALSTATE)

label string or nil

read/write

Optional text label for the checkbox (default nil)

value checkboxstateconst

read/write

The current (or desired if setting) value of the checkbox

Methods
toggle()

Toggle to the next state of the checkbox

Attributes

rtk.CheckBox.type checkboxtypeconst read/write

The type of checkbox, whether dual or tri state (default DUALSTATE).

rtk.CheckBox.label string or nil read/write

Optional text label for the checkbox (default nil).

This attribute may be passed as the first positional argument during initialization. (In other words, rtk.CheckBox{'Foo'} is equivalent to rtk.CheckBox{label='Foo'}.)

rtk.CheckBox.value checkboxstateconst read/write

The current (or desired if setting) value of the checkbox.

The strings 'checked', 'unchecked', and 'indeterminate' also work here and when set with attr() they will be calculated as one of the state constants.

Truthiness is preserved

The checkbox state constants use booleans for UNCHECKED and CHECKED, so truthy evaluations work as you'd intuitively expect:

local cb = rtk.CheckBox()
-- This is safe.
if cb.value then
    log.info('checkbox is checked')
end
-- This is equivalent, and actually recommended from a readability standpoint.
if cb.value == rtk.CheckBox.CHECKED then
    log.info('yep, still checked')
end

Methods

rtk.CheckBox:toggle()

Toggle to the next state of the checkbox.

For a DUALSTATE checkbox, this simply toggles between CHECKED and UNCHECKED. For TRISTATE checkboxes, the INDETERMINATE state will follow CHECKED and then cycle back to UNCHECKED.

The value attribute is updated after this function is called.

Return Values
(rtk.CheckBox)

returns self for method chaining

Event Handlers

See also handlers for rtk.Widget.

Synopsis

Methods
onchange()

Called when the checkbox value changes

rtk.CheckBox:onchange()

Called when the checkbox value changes.

The value attribute reflects the current state.

Return Values
(nil)

Return value has no significance. This is a notification event only.