2021-04-12 18:19:04 +02:00
# Bar (lv_bar)
## Overview
2022-03-21 18:25:51 +08:00
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.
2021-04-12 18:19:04 +02:00
Vertical bars can be created if the width of the object is smaller than its height.
2021-06-09 15:10:35 +02:00
Not only the end, but also the start value of the bar can be set, which changes the start position of the indicator.
2021-04-12 18:19:04 +02:00
## Parts and Styles
2021-04-30 10:02:03 +02:00
- `LV_PART_MAIN` The background of the bar and it uses the typical background style properties. Adding padding makes the indicator smaller or larger. The `anim_time` style property sets the animation time if the values set with `LV_ANIM_ON` .
2021-08-26 10:52:39 +02:00
- `LV_PART_INDICATOR` The indicator itself; also uses all the typical background properties.
2022-03-21 18:25:51 +08:00
2021-04-12 18:19:04 +02:00
## 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)` .
2021-11-29 10:59:44 -05:00
The default range is 0..100.
2021-04-12 18:19:04 +02:00
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` ).
### Modes
2021-08-26 10:52:39 +02:00
The bar can be one of the following modes:
2021-04-30 10:02:03 +02:00
- `LV_BAR_MODE_NORMAL` A normal bar as described above
2022-01-22 09:17:13 -06:00
- `LV_BAR_MODE_SYMMETRICAL` Draw the indicator from the zero value to current value. Requires a negative minimum range and positive maximum range.
- `LV_BAR_MODE_RANGE` Allows setting the start value too by `lv_bar_set_start_value(bar, new_value, LV_ANIM_ON/OFF)` . The start value always has to be smaller than the end value.
2021-04-12 18:19:04 +02:00
## Events
2021-07-07 16:18:56 +02:00
- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for the following parts:
- `LV_BAR_DRAW_PART_INDICATOR` The indicator of the bar
2022-03-21 18:25:51 +08:00
- `part` : `LV_PART_INDICATOR`
2021-07-07 16:18:56 +02:00
- `draw_area` : area of the indicator
- `rect_dsc`
2022-03-21 18:25:51 +08:00
2021-07-07 16:18:56 +02:00
See the events of the [Base object ](/widgets/obj ) too.
2021-04-12 18:19:04 +02:00
Learn more about [Events ](/overview/event ).
## Keys
No *Keys* are processed by the object type.
Learn more about [Keys ](/overview/indev ).
## Example
```eval_rst
2022-08-15 09:27:00 -04:00
.. include:: ../../examples/widgets/bar/index.rst
2021-04-12 18:19:04 +02:00
```
## API
```eval_rst
.. doxygenfile:: lv_bar.h
:project: lvgl
```