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.

Edit on GitHub

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

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:

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:

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_CHANGED Sent while the Slider is being dragged or changed with keys. The event is sent continuously while the Slider is being dragged.
  • LV_EVENT_RELEASED Sent once when Slider is released.

Further Reading

Learn more about Events emitted by all Widgets.

Learn more about events.

Keys

  • LV_KEY_UP/RIGHT Increment Slider's value by 1.
  • LV_KEY_DOWN/LEFT Decrement 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

On this page