Slider (lv_slider)

Overview

The Slider object looks like a Bar supplemented with a knob. The knob can be dragged to set a value. The Slider also can be vertical or horizontal.

Value and range

To set an initial value use lv_slider_set_value(slider, new_value, LV_ANIM_ON/OFF). lv_slider_set_anim_time(slider, anim_time) sets the animation time in milliseconds.

To specify the range (min, max values) the lv_slider_set_range(slider, min , max) can be used.

Symmetrical

The slider can be drawn symmetrical to zero (drawn from zero, left to right), if it’s enabled with lv_slider_set_sym(slider, true)

Knob placement

The knob can be placed in two ways:

  • inside the background

  • on the edges on min/max values

Use the lv_slider_set_knob_in(slider, true/false) to choose between the modes. (knob_in = false is the default)

Styles

You can modify the slider’s styles with lv_slider_set_style(slider, LV_SLIDER_STYLE_..., &style).

  • LV_SLIDER_STYLE_BG Style of the background. All style.body properties are used. The padding values make the knob larger than the background. (negative value makes is larger)

  • LV_SLIDER_STYLE_INDIC Style of the indicator. All style.body properties are used. The padding values make the indicator smaller than the background.

  • LV_SLIDER_STYLE_KNOB Style of the knob. All style.body properties are used except padding.

Events

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

  • LV_EVENT_VALUE_CHANGED Sent while the slider is being dragged or changed with keys.

Keys

  • LV_KEY_UP, LV_KEY_RIGHT Increment the slider’s value by 1

  • LV_KEY_DOWN, LV_KEY_LEFT Decrement the slider’s value by 1

Learn more about Keys.

Example

C

Slider with custo mstyle

Slider example in LittlevGL

code

Set value with slider

Set value with slider in LittlevGL

code

MicroPython

Slider with custo mstyle

Slider example in LittlevGL with MicroPython

code

Set value with slider

Set value with slider in LittlevGL with MicroPython

code

API

Typedefs

typedef uint8_t lv_slider_style_t

Enums

enum [anonymous]

Built-in styles of slider

Values:

enumerator LV_SLIDER_STYLE_BG
enumerator LV_SLIDER_STYLE_INDIC

Slider background style.

enumerator LV_SLIDER_STYLE_KNOB

Slider indicator (filled area) style.

Functions

lv_obj_t *lv_slider_create(lv_obj_t *par, const lv_obj_t *copy)

Create a slider objects

Return

pointer to the created slider

Parameters
  • par: pointer to an object, it will be the parent of the new slider

  • copy: pointer to a slider object, if not NULL then the new object will be copied from it

void lv_slider_set_value(lv_obj_t *slider, int16_t value, lv_anim_enable_t anim)

Set a new value on the slider

Parameters
  • slider: pointer to a slider object

  • value: new value

  • anim: LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately

void lv_slider_set_range(lv_obj_t *slider, int16_t min, int16_t max)

Set minimum and the maximum values of a bar

Parameters
  • slider: pointer to the slider object

  • min: minimum value

  • max: maximum value

void lv_slider_set_anim_time(lv_obj_t *slider, uint16_t anim_time)

Make the slider symmetric to zero. The indicator will grow from zero instead of the minimum position.

Parameters
  • slider: pointer to a slider object

  • en: true: enable disable symmetric behavior; false: disable

void lv_slider_set_sym(lv_obj_t *slider, bool en)

Set the animation time of the slider

Parameters
  • slider: pointer to a bar object

  • anim_time: the animation time in milliseconds.

void lv_slider_set_knob_in(lv_obj_t *slider, bool in)

Set the ‘knob in’ attribute of a slider

Parameters
  • slider: pointer to slider object

  • in: true: the knob is drawn always in the slider; false: the knob can be out on the edges

void lv_slider_set_style(lv_obj_t *slider, lv_slider_style_t type, const lv_style_t *style)

Set a style of a slider

Parameters
  • slider: pointer to a slider object

  • type: which style should be set

  • style: pointer to a style

int16_t lv_slider_get_value(const lv_obj_t *slider)

Get the value of a slider

Return

the value of the slider

Parameters
  • slider: pointer to a slider object

int16_t lv_slider_get_min_value(const lv_obj_t *slider)

Get the minimum value of a slider

Return

the minimum value of the slider

Parameters
  • slider: pointer to a slider object

int16_t lv_slider_get_max_value(const lv_obj_t *slider)

Get the maximum value of a slider

Return

the maximum value of the slider

Parameters
  • slider: pointer to a slider object

bool lv_slider_is_dragged(const lv_obj_t *slider)

Give the slider is being dragged or not

Return

true: drag in progress false: not dragged

Parameters
  • slider: pointer to a slider object

uint16_t lv_slider_get_anim_time(lv_obj_t *slider)

Get the animation time of the slider

Return

the animation time in milliseconds.

Parameters
  • slider: pointer to a slider object

bool lv_slider_get_sym(lv_obj_t *slider)

Get whether the slider is symmetric or not.

Return

true: symmetric is enabled; false: disable

Parameters
  • slider: pointer to a bar object

bool lv_slider_get_knob_in(const lv_obj_t *slider)

Get the ‘knob in’ attribute of a slider

Return

true: the knob is drawn always in the slider; false: the knob can be out on the edges

Parameters
  • slider: pointer to slider object

const lv_style_t *lv_slider_get_style(const lv_obj_t *slider, lv_slider_style_t type)

Get a style of a slider

Return

style pointer to a style

Parameters
  • slider: pointer to a slider object

  • type: which style should be get

struct lv_slider_ext_t

Public Members

lv_bar_ext_t bar
const lv_style_t *style_knob
int16_t drag_value
uint8_t knob_in