# Bar (lv_bar) (/widgets/bar)



Overview [#overview]

The Bar Widget has a background and an indicator. The length of the
indicator against the background indicates the Bar's current value.

Both the start and end values of the Bar can be set. Changing the start value to a
value other than the minimum value in its range adjusts the start position of the indicator.

Parts and Styles [#parts-and-styles]

* <ApiLink name="LV_PART_MAIN" /> The Bar's background.  It uses the [typical
  background style properties](/common-widget-features/styles/overview). Adding padding makes the indicator
  smaller or larger. The `anim_time` style property sets the
  animation time if the values set with <ApiLink name="LV_ANIM_ON" />.
* <ApiLink name="LV_PART_INDICATOR" /> The Bar's indicator; also uses the [typical
  background style properties](/common-widget-features/styles/overview).

Usage [#usage]

Orientation and size [#orientation-and-size]

* for orientation, width and height, simply set width and height style properties;
* <ApiLink name="lv_bar_set_orientation" display="lv_bar_set_orientation(bar, orientation)" /> to override orientation
  caused by `width` and `height`.  Valid values for `orientation` are:

  * <ApiLink name="LV_BAR_ORIENTATION_AUTO" />
  * <ApiLink name="LV_BAR_ORIENTATION_HORIZONTAL" />
  * <ApiLink name="LV_BAR_ORIENTATION_VERTICAL" />

Value and range [#value-and-range]

A new value can be set with
<ApiLink name="lv_bar_set_value" display="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 <ApiLink name="lv_bar_set_range" display="lv_bar_set_range(bar, min, max)" />. The default range is
0..100, and the default drawing direction is from left to right in horizontal mode and
bottom to top in vertical mode. If the minimum value is greater than the maximum value, like
100..0, the drawing direction is reversed.

The new value in <ApiLink name="lv_bar_set_value" /> can be set with or without an
animation depending on the last parameter (`LV_ANIM_ON/OFF`).

Modes [#modes]

The Bar can be one of the following modes:

* <ApiLink name="LV_BAR_MODE_NORMAL" /> A normal Bar as described above
* <ApiLink name="LV_BAR_MODE_SYMMETRICAL" /> Draws indicator from zero value to current value. Requires a negative
  minimum value and positive maximum value, e.g. \[-100..100].
* <ApiLink name="LV_BAR_MODE_RANGE" /> Allows setting the start value as well with
  <ApiLink name="lv_bar_set_start_value" display="lv_bar_set_start_value(bar, new_value, LV_ANIM_ON/OFF)" />. The start
  value must be smaller than the end value.

Data binding [#data-binding]

To get familiar with observers, subjects, and data bindings in general visit the
[Observer](/main-modules/observer/observer) page.

This method of subscribing to an integer Subject affects a Bar Widget's integer
value directly.  Note that this is a one-way binding (Subject ==> Widget) so when
the subject changes the Bar will be updated too.

It supports integer and float subjects.

* <ApiLink name="lv_bar_bind_value" display="lv_bar_bind_value(bar, &subject)" />

Events [#events]

No special events are sent by Bar Widgets.

<Callout type="info" title="Further Reading">
  Learn more about [Events](/common-widget-features/events) emitted by all Widgets.

  Learn more about [events](/common-widget-features/events).
</Callout>

Keys [#keys]

No *Keys* are processed by Bar Widgets.

<Callout type="info" title="Further Reading">
  Learn more about [Keys](/main-modules/indev/keypad).
</Callout>

Examples [#examples]

Simple Bar [#simple-bar]

<LvglExample name="lv_example_bar_1" path="widgets/bar/lv_example_bar_1" />

Styling a bar [#styling-a-bar]

<LvglExample name="lv_example_bar_2" path="widgets/bar/lv_example_bar_2" />

Temperature meter [#temperature-meter]

<LvglExample name="lv_example_bar_3" path="widgets/bar/lv_example_bar_3" />

Stripe pattern and range value [#stripe-pattern-and-range-value]

<LvglExample name="lv_example_bar_4" path="widgets/bar/lv_example_bar_4" />

Bar with LTR and RTL base direction [#bar-with-ltr-and-rtl-base-direction]

<LvglExample name="lv_example_bar_5" path="widgets/bar/lv_example_bar_5" />

Custom drawer to show the current value [#custom-drawer-to-show-the-current-value]

<LvglExample name="lv_example_bar_6" path="widgets/bar/lv_example_bar_6" />

Bar with opposite direction [#bar-with-opposite-direction]

<LvglExample name="lv_example_bar_7" path="widgets/bar/lv_example_bar_7" />

API [#api]
