acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
switch.md (1746B)
1 ```eval_rst 2 .. include:: /header.rst 3 :github_url: |github_link_base|/widgets/core/switch.md 4 ``` 5 6 # Switch (lv_switch) 7 8 ## Overview 9 10 The Switch looks like a little slider and can be used to turn something on and off. 11 12 13 ## Parts and Styles 14 - `LV_PART_MAIN` The background of the switch uses all the typical background style properties. `padding` makes the indicator smaller in the respective direction. 15 - `LV_PART_INDICATOR` The indicator that shows the current state of the switch. Also uses all the typical background style properties. 16 - `LV_PART_KNOB` A rectangle (or circle) drawn at left or right side of the indicator. Also uses all the typical background properties to describe the knob(s). By default, the knob is square (with an optional corner radius) with side length equal to the smaller side of the slider. The knob can be made larger with the `padding` values. Padding values can be asymmetric too. 17 18 ## Usage 19 20 ### Change state 21 The switch uses the standard `LV_STATE_CHECKED` state. 22 23 To get the current state of the switch (with `true` being on), use `lv_obj_has_state(switch, LV_STATE_CHECKED)`. 24 25 Call `lv_obj_add_state(switch, LV_STATE_CHECKED)` to turn it on, or `lv_obj_clear_state(switch, LV_STATE_CHECKED)` to turn it off. 26 27 28 ## Events 29 - `LV_EVENT_VALUE_CHANGED` Sent when the switch changes state. 30 31 See the events of the [Base object](/widgets/obj) too. 32 33 Learn more about [Events](/overview/event). 34 35 ## Keys 36 - `LV_KEY_UP/RIGHT` Turns on the slider 37 - `LV_KEY_DOWN/LEFT` Turns off the slider 38 - `LV_KEY_ENTER` Toggles the switch 39 40 Learn more about [Keys](/overview/indev). 41 42 ## Example 43 44 ```eval_rst 45 46 .. include:: ../../../examples/widgets/switch/index.rst 47 48 ``` 49 50 ## API 51 52 ```eval_rst 53 54 .. doxygenfile:: lv_switch.h 55 :project: lvgl 56 57 ```