Slider (lv_slider)
The Slider Widget looks like a Bar (lv_bar) supplemented with a knob. The knob can be dragged to set the Slider's value.
Overview
The Slider Widget looks like a Bar (lv_bar) supplemented with a knob. The knob can be dragged to set the Slider's value. Like Bar, a Slider can be vertical or horizontal.
Parts and Styles
LV_PART_MAINThe background of the Slider. 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 Slider; also uses the typical background style properties.LV_PART_KNOBA rectangle (or circle) drawn at the current value; also uses the typical background style properties to describe the knob(s). By default, the knob is round (radius-style can modify this) with side length equal to the smaller dimension of the Slider. The knob can be made larger with thepaddingvalues. Padding values can be asymmetric as well.
Usage
Value, range and orientation
Once a Slider is created, it has:
- value == 0
- default range of [0..100],
- horizontal orientation, with
- default width of approximately 2 inches (according to configured value of
LV_DPI_DEF), - default height of approximately 1/10 inch (according to configured value of
LV_DPI_DEF).
To set different values use:
-
lv_slider_set_value(slider, new_value, LV_ANIM_ON/OFF)(animation time is set by the styles'anim_timeproperty); -
for orientation, width and height, simply set width and height properties;
-
lv_slider_set_orientation(slider, orientation)to override orientation caused bywidthandheight. Valid values fororientationare:
The default drawing direction is from left to right in horizontal orientation and bottom to top in vertical orientation. If the minimum value is set to be greater than the maximum value (e.g. [100..0]), the drawing direction is reversed.
Modes
The Slider can be in one of the following modes:
LV_SLIDER_MODE_NORMALA normal Slider as described above (default)LV_SLIDER_SYMMETRICALDraw the indicator from the zero value to current value. Requires negative minimum range and positive maximum range.LV_SLIDER_RANGEAllows setting the start value as well bylv_bar_set_start_value(slider, new_value, LV_ANIM_ON/OFF). The start value must always be smaller than the end value.
The mode can be changed with lv_slider_set_mode(slider, LV_SLIDER_MODE_...)
Knob-only mode
Normally, the Slider can be adjusted either by dragging the knob, or by
clicking on the Slider bar. In the latter case the knob moves to the
point clicked and the Slider value changes accordingly. In some cases it is
desirable to set the Slider to react on dragging the knob only. This
feature is enabled by adding the LV_OBJ_FLAG_ADV_HITTEST flag:
lv_obj_add_flag(slider, LV_OBJ_FLAG_ADV_HITTEST).
Any extended click area (set by lv_obj_set_ext_click_area(slider, value))
increases the knob's click area.
Data binding
To get familiar with observers, subjects, and data bindings in general, visit the Observer page.
This method of subscribing to an integer Subject affects a Slider Widget's integer value directly. Note that this is a two-way binding (Subject <===> Widget), so an end user's direct interaction with the Slider Widget updates the Subject's value and vice versa.
It supports integer and float subjects.
Events
LV_EVENT_VALUE_CHANGEDSent while the Slider is being dragged or changed with keys. The event is sent continuously while the Slider is being dragged.LV_EVENT_RELEASEDSent once when Slider is released.
Keys
LV_KEY_UP/RIGHTIncrement Slider's value by 1.LV_KEY_DOWN/LEFTDecrement Slider's value by 1.
Further Reading
Learn more about Keys.
Examples
Simple Slider
Slider with custom style
Slider with extended drawer
Slider with opposite direction
API
How is this guide?
Last updated on