Switch (lv_switch)
Switch Widgets look like little sliders and are used to display, and optionally modify, a value that can be "on" or "off".
Overview
Switch Widgets look like little sliders and are used to display, and optionally modify, a value that can be "on" or "off".
By default, a Switch is oriented horizontally. Its orientation will be vertical
if you set width < height.
Parts and Styles
LV_PART_MAINSwitch's background; uses the typical background style properties.paddingmakes the indicator smaller in the respective direction.LV_PART_INDICATORThe indicator that shows the current state of the Switch; also uses the typical background style properties.LV_PART_KNOBA rectangle (or circle) drawn at the left or right side of the indicator; also uses the typical background style properties to modify the knob's appearance. By default, the knob is round (radius-style can modify this) with diameter slightly smaller than the smaller side of the slider. The knob can be made larger with thepaddingvalues. Padding values can be asymmetric as well.
Usage
Change state
The Switch uses the standard LV_STATE_CHECKED state.
To get the current state of the Switch (with true being ON), use
lv_obj_has_state(widget, LV_STATE_CHECKED).
Call lv_obj_add_state(widget, LV_STATE_CHECKED) to turn it on, or
lv_obj_remove_state(widget, LV_STATE_CHECKED) to turn it off
programmatically.
Change orientation
With a Switch is created, its default orientation is
LV_SWITCH_ORIENTATION_AUTO, which causes it to be oriented based
on width and height. You can change this behavior using
lv_switch_set_orientation(widget, orientation). Possible values for
orientation are:
Events
LV_EVENT_VALUE_CHANGEDSent when Switch changes state.
Keys
LV_KEY_UP/RIGHTTurns Switch ONLV_KEY_DOWN/LEFTTurns Switch OFFLV_KEY_ENTERToggles the Switch
Further Reading
Learn more about Keys.
Examples
Simple Switch
Switch Orientation
API
How is this guide?
Last updated on