Bar (lv_bar)
The Bar Widget has a background and an indicator. The length of the indicator against the background indicates the Bar's current value.
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
LV_PART_MAINThe Bar's background. It uses the typical background style properties. Adding padding makes the indicator smaller or larger. Theanim_timestyle property sets the animation time if the values set withLV_ANIM_ON.LV_PART_INDICATORThe Bar's indicator; also uses the typical background style properties.
Usage
Orientation and size
-
for orientation, width and height, simply set width and height style properties;
-
lv_bar_set_orientation(bar, orientation)to override orientation caused bywidthandheight. Valid values fororientationare:
Value and range
A new value can be set with
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
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 lv_bar_set_value can be set with or without an
animation depending on the last parameter (LV_ANIM_ON/OFF).
Modes
The Bar can be one of the following modes:
LV_BAR_MODE_NORMALA normal Bar as described aboveLV_BAR_MODE_SYMMETRICALDraws indicator from zero value to current value. Requires a negative minimum value and positive maximum value, e.g. [-100..100].LV_BAR_MODE_RANGEAllows setting the start value as well withlv_bar_set_start_value(bar, new_value, LV_ANIM_ON/OFF). The start value must be smaller than the end value.
Data binding
To get familiar with observers, subjects, and data bindings in general visit the 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.
Events
No special events are sent by Bar Widgets.
Keys
No Keys are processed by Bar Widgets.
Further Reading
Learn more about Keys.
Examples
Simple Bar
Styling a bar
Temperature meter
Stripe pattern and range value
Bar with LTR and RTL base direction
Custom drawer to show the current value
Bar with opposite direction
API
How is this guide?
Last updated on
Arc Label (lv_arclabel)
The Arc Label is a specialized widget designed to display text along an arc. It allows for flexible text placement and styling, making it suitable for applications where text needs to follow a curv...
Button (lv_button)
Buttons have no new features compared to the base widget. They are useful for semantic purposes and have slightly different default settings.