Bar (lv_bar)

Overview

The ‘Bar’ objects have got two main parts:

  1. a background which is the object itself.

  2. an indicator which shape is similar to the background but its width/height can be adjusted.

The orientation of the bar can be vertical or horizontal according to the width/height ratio. Logically, on horizontal bars, the indicator’s width can be changed. Similarly, on vertical bars, the indicator’s height can be changed.

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.

Symmetrical

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

Styles

To set the style of an Bar object, use lv_bar_set_style(arc, LV_BAR_STYLE_MAIN, &style):

  • LV_BAR_STYLE_BG - is a Base object, therefore, it uses its style elements. Its default style is: lv_style_pretty.

  • LV_BAR_STYLE_INDIC - is similar to the background. It uses the left, right, top and bottom paddings to keeps some space form the edges of the background. Its default style is: lv_style_pretty_color.

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 "lvgl/lvgl.h"

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

MicroPython

Simple Bar

Bar example in LittlevGL with MicroPython

code

bar1 = lv.bar(lv.scr_act())
bar1.set_size(200, 30)
bar1.align(None, lv.ALIGN.CENTER, 0, 0)
bar1.set_anim_time(1000)
bar1.set_value(100, lv.ANIM.ON)

API

Typedefs

typedef uint8_t lv_bar_style_t

Enums

enum [anonymous]

Bar styles.

Values:

enumerator LV_BAR_STYLE_BG
enumerator LV_BAR_STYLE_INDIC

Bar background style.

Functions

LV_EXPORT_CONST_INT(LV_BAR_ANIM_STATE_START)
LV_EXPORT_CONST_INT(LV_BAR_ANIM_STATE_END)
LV_EXPORT_CONST_INT(LV_BAR_ANIM_STATE_INV)
LV_EXPORT_CONST_INT(LV_BAR_ANIM_STATE_NORM)
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_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_sym(lv_obj_t *bar, bool en)

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

Parameters
  • bar: pointer to a bar object

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

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.

void lv_bar_set_style(lv_obj_t *bar, lv_bar_style_t type, const lv_style_t *style)

Set a style of a bar

Parameters
  • bar: pointer to a bar object

  • type: which style should be set

  • style: pointer to a style

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_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

bool lv_bar_get_sym(lv_obj_t *bar)

Get whether the bar is symmetric or not.

Return

true: symmetric is enabled; false: disable

Parameters
  • bar: pointer to a bar object

uint16_t lv_bar_get_anim_time(lv_obj_t *bar)

Get the animation time of the bar

Return

the animation time in milliseconds.

Parameters
  • bar: pointer to a bar object

const lv_style_t *lv_bar_get_style(const lv_obj_t *bar, lv_bar_style_t type)

Get a style of a bar

Return

style pointer to a style

Parameters
  • bar: pointer to a bar object

  • type: which style should be get

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
lv_anim_value_t anim_start
lv_anim_value_t anim_end
lv_anim_value_t anim_state
lv_anim_value_t anim_time
uint8_t sym
const lv_style_t *style_indic