1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00
lvgl/docs/widgets/core/switch.md
2021-05-03 11:13:43 +02:00

1.5 KiB

.. include:: /header.rst 
:github_url: |github_link_base|/widgets/switch.md

Switch (lv_switch)

Overview

The Switch can be used to turn on/off something. It looks like a little slider.

Parts and Styles

The Switch uses the the following parts:

  • LV_SWITCH_PART_BG: main part
  • LV_SWITCH_PART_INDIC: the indicator (virtual part)
  • LV_SWITCH_PART_KNOB: the knob (virtual part)

The parts and style works the same as in case of Slider. Read its documentation for a details description.

##Usage

Change state

The state of the Switch can be changed by clicking on it or by lv_switch_on(switch, LV_ANIM_ON/OFF), lv_switch_off(switch, LV_ANIM_ON/OFF) or lv_switch_toggle(switch, LV_ANOM_ON/OFF) functions

Animation time

The time of animations, when the switch changes state, can be adjusted with lv_switch_set_anim_time(switch, anim_time).

Events

Besides the Generic events the following Special events are sent by the Switch:

  • LV_EVENT_VALUE_CHANGED Sent when the switch changes state.

Keys

  • LV_KEY_UP, LV_KEY_RIGHT Turn on the slider
  • LV_KEY_DOWN, LV_KEY_LEFT Turn off the slider

Learn more about Keys.

Example


.. include:: /lv_examples/src/lv_ex_widgets/lv_ex_switch/index.rst

API


.. doxygenfile:: lv_switch.h
  :project: lvgl