Bar (lv_bar)

Overview

The bar object has a background and an indicator on it. The width of the indicator is set according to the current value of the bar.

Vertical bars can be created if the width of the object is smaller than its height.

Not only end, but the start value of the bar can be set which changes the start position of the indicator.

Parts and Styles

The Bar's main part is called LV_BAR_PART_BG and it uses the typical background style properties.

LV_BAR_PART_INDIC is a virtual part which also uses all the typical background properties. By default the indicator maximal size is the same as the background's size but setting positive padding values in LV_BAR_PART_BG will make the indicator smaller. (negative values will make it larger) If the value style property is used on the indicator the alignment will be calculated based on the current size of the indicator. For example a center aligned value is always shown in the middle of the indicator regardless it's current size.

Usage

Value and range

A new value can be set by lv_bar_set_value(bar, new_value, LV_ANIM_ON/OFF). The value is interpreted in a range (minimum and maximum values) which can be modified with lv_bar_set_range(bar, min, max). The default range is 1..100.

The new value in lv_bar_set_value can be set with or without an animation depending on the last parameter (LV_ANIM_ON/OFF). The time of the animation can be adjusted by lv_bar_set_anim_time(bar, 100). The time is in milliseconds unit.

It's also possible to set the start value of the bar using lv_bar_set_start_value(bar, new_value, LV_ANIM_ON/OFF)

Modes

The bar can be drawn symmetrical to zero (drawn from zero, left to right), if it's enabled with lv_bar_set_type(bar, LV_BAR_TYPE_SYMMETRICAL).

Events

Only the Generic events are sent by the object type.

Learn more about Events.

Keys

No Keys are processed by the object type.

Learn more about Keys.

Example

C

Simple Bar

Bar example in LittlevGL

code

#include "../../../lv_examples.h"
#if LV_USE_BAR

void lv_ex_bar_1(void)
{
    lv_obj_t * bar1 = lv_bar_create(lv_scr_act(), NULL);
    lv_obj_set_size(bar1, 200, 20);
    lv_obj_align(bar1, NULL, LV_ALIGN_CENTER, 0, 0);
    lv_bar_set_anim_time(bar1, 2000);
    lv_bar_set_value(bar1, 100, LV_ANIM_ON);
}

#endif

MicroPython

No examples yet.

API

Typedefs

typedef uint8_t lv_bar_type_t
typedef uint8_t lv_bar_part_t

Enums

enum [anonymous]

Values:

enumerator LV_BAR_TYPE_NORMAL
enumerator LV_BAR_TYPE_SYMMETRICAL
enumerator LV_BAR_TYPE_CUSTOM
enum [anonymous]

Bar parts

Values:

enumerator LV_BAR_PART_BG
enumerator LV_BAR_PART_INDIC

Bar background style.

enumerator _LV_BAR_PART_VIRTUAL_LAST

Bar fill area style.

Functions

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

Create a bar objects

Return

pointer to the created bar

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

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

void lv_bar_set_value(lv_obj_t *bar, int16_t value, lv_anim_enable_t anim)

Set a new value on the bar

Parameters
  • bar: pointer to a bar object

  • value: new value

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

void lv_bar_set_start_value(lv_obj_t *bar, int16_t start_value, lv_anim_enable_t anim)

Set a new start value on the bar

Parameters
  • bar: pointer to a bar object

  • value: new start value

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

void lv_bar_set_range(lv_obj_t *bar, int16_t min, int16_t max)

Set minimum and the maximum values of a bar

Parameters
  • bar: pointer to the bar object

  • min: minimum value

  • max: maximum value

void lv_bar_set_type(lv_obj_t *bar, lv_bar_type_t type)

Set the type of bar.

Parameters
  • bar: pointer to bar object

  • type: bar type

void lv_bar_set_anim_time(lv_obj_t *bar, uint16_t anim_time)

Set the animation time of the bar

Parameters
  • bar: pointer to a bar object

  • anim_time: the animation time in milliseconds.

int16_t lv_bar_get_value(const lv_obj_t *bar)

Get the value of a bar

Return

the value of the bar

Parameters
  • bar: pointer to a bar object

int16_t lv_bar_get_start_value(const lv_obj_t *bar)

Get the start value of a bar

Return

the start value of the bar

Parameters
  • bar: pointer to a bar object

int16_t lv_bar_get_min_value(const lv_obj_t *bar)

Get the minimum value of a bar

Return

the minimum value of the bar

Parameters
  • bar: pointer to a bar object

int16_t lv_bar_get_max_value(const lv_obj_t *bar)

Get the maximum value of a bar

Return

the maximum value of the bar

Parameters
  • bar: pointer to a bar object

lv_bar_type_t lv_bar_get_type(lv_obj_t *bar)

Get the type of bar.

Return

bar type

Parameters
  • bar: pointer to bar object

uint16_t lv_bar_get_anim_time(const lv_obj_t *bar)

Get the animation time of the bar

Return

the animation time in milliseconds.

Parameters
  • bar: pointer to a bar object

struct lv_bar_anim_t

Public Members

lv_obj_t *bar
lv_anim_value_t anim_start
lv_anim_value_t anim_end
lv_anim_value_t anim_state
struct lv_bar_ext_t
#include <lv_bar.h>

Data of bar

Public Members

int16_t cur_value
int16_t min_value
int16_t max_value
int16_t start_value
lv_area_t indic_area
lv_anim_value_t anim_time
lv_bar_anim_t cur_value_anim
lv_bar_anim_t start_value_anim
uint8_t type
lv_style_list_t style_indic