Checkbox (lv_checkbox)
The Checkbox Widget is created from a "tick box" and a label. When the Checkbox is clicked the tick box is toggled.
Overview
The Checkbox Widget is created from a "tick box" and a label. When the Checkbox is clicked the tick box is toggled.
Parts and Styles
LV_PART_MAINBackground of Checkbox and it uses the text and the typical background style properties.pad_columnadjusts spacing between tickbox and labelLV_PART_INDICATORThe "tick box" is a square that uses the typical background style properties. By default, its size is equal to the height of the main part's font. Padding properties make the tick box larger in the respective directions.
The Checkbox is added to the default group (if one is set).
Usage
Text
The text can be modified with
lv_checkbox_set_text(cb, "New text") and will be
dynamically allocated.
To set static text, use lv_checkbox_set_text_static(cb, txt). This
way, only a pointer to txt will be stored. The provided text buffer must remain
available for the lifetime of the Checkbox.
Check, uncheck, disable
You can programmatically check, un-check, and disable the Checkbox by using the common state add/clear function:
lv_obj_add_state(cb, LV_STATE_CHECKED); /* Make Checkbox checked */
lv_obj_remove_state(cb, LV_STATE_CHECKED); /* Make Checkbox unchecked */
lv_obj_add_state(cb, LV_STATE_CHECKED); /* Make Checkbox checked */
lv_obj_add_state(cb, LV_STATE_DISABLED); /* Make Checkbox disabled */To find out whether the Checkbox is checked use
lv_obj_has_state(cb, LV_STATE_CHECKED).
Events
LV_EVENT_VALUE_CHANGEDSent when Checkbox is toggled.
Keys
The following Keys are processed by Checkbox:
LV_KEY_RIGHT/UPGo to CHECKED state if Checkbox is enabledLV_KEY_LEFT/DOWNGo to non-CHECKED state if Checkbox is enabledLV_KEY_ENTERClicks the Checkbox and toggles its value.
Note that, as usual, the state of LV_KEY_ENTER is translated to
LV_EVENT_PRESSED/PRESSING/RELEASED etc.
Further Reading
Learn more about Keys.
Examples
Simple Checkboxes
Checkboxes as radio buttons
API
How is this guide?
Last updated on