LVGL v8 Imgbar
lvsf_imgbar is a custom progress-bar widget that SiFli wraps around LVGL img. It crops a foreground image according to a value, acting like a progress bar filled with an image. Create a foreground lv_img, hand it to the imgbar (lv_imgbar_set_img_fg sizes the imgbar to the image), choose the fill direction, set the value range, and then drive the value.
Main header: middleware/lvgl/lvsf/gui_widgets/lvsf_imgbar.h
Value-range setting: middleware/lvgl/lvsf/gui_widgets/lvsf_obj_ext.h (
lv_obj_set_range_value)Dependent widget: LVGL img (
LV_USE_IMG)Example project: example/multimedia/lvgl/lvgl_v8_imgbar
Features
Crops a foreground image by value to implement an image-filled progress bar.
Supports four fill directions: left-to-right, right-to-left, top-to-bottom, and bottom-to-top.
Supports two modes: bar (BAR) and switch (SWITCH).
Supports drag-and-release to change the progress, and animation on progress changes.
Supports three image layers: background, foreground, and indicator.
Supports a user callback on progress changes.
Use Cases
Image-filled battery, volume, and brightness bars.
Progress indicators with custom texture/gradient fills.
Draggable sliding switches and sliders.
Progress bars with an indicator knob.
Supported Boards
sf32lb52-lcd_n16r8
sf32lb52-lchspi-ulp
Configuration and Initialization
lvsf_imgbar depends on the LVGL img component. In menuconfig, confirm it is enabled:
CONFIG_LV_USE_IMG=y
In the BSP, the LVSF_USE_IMGBAR macro controls whether this widget is compiled.
Minimum flow to create an object:
#include "lvsf_imgbar.h"
lv_obj_t *imgbar = lv_imgbar_create(lv_scr_act());
API Reference
Enumerations and callback types
Type |
Value |
Description |
|---|---|---|
|
|
Left to right |
|
Right to left |
|
|
Top to bottom |
|
|
Bottom to top |
|
|
|
Bar mode |
|
Switch mode |
|
|
|
Progress-change processing callback; |
Creation and refresh
Function |
Description |
Parameters / Returns |
|---|---|---|
|
Creates an image bar object |
|
|
Refresh timer callback |
|
Direction, mode, and interaction
Function |
Description |
Parameters / Returns |
|---|---|---|
|
Sets the fill direction |
|
|
Enables/disables dragging |
|
|
Sets the display mode |
|
|
Sets the progress-change callback |
|
Value settings
Function |
Description |
Parameters / Returns |
|---|---|---|
|
Sets the progress value (Q24.8 format) |
|
|
Sets the progress value (integer format) |
|
Images and indicator
Function |
Description |
Parameters / Returns |
|---|---|---|
|
Sets the foreground image |
|
|
Sets the background image |
|
|
Sets the indicator image |
|
|
Gets the background image |
Returns the background image object pointer |
|
Gets the indicator image |
Returns the indicator image object pointer |
|
Sets the indicator offset |
|
|
Sets the indicator X offset |
|
|
Sets the indicator Y offset |
|
Typical Usage
#include "lvsf_imgbar.h"
#include "lvsf_obj_ext.h" /* lv_obj_set_range_value */
lv_obj_t *imgbar = lv_imgbar_create(parent);
lv_obj_clear_flag(imgbar, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_t *fg = lv_img_create(imgbar);
lv_img_set_src(fg, &fg_img_dsc); /* Foreground image */
lv_obj_refr_size(fg);
lv_imgbar_set_img_fg(imgbar, fg); /* Size the imgbar to the foreground image */
/* Handle the internal container: clear padding/border, disable scrolling, pin the foreground to the top-left */
lv_obj_t *fg_box = lv_obj_get_parent(fg);
lv_obj_set_style_pad_all(fg_box, 0, 0);
lv_obj_set_style_border_width(fg_box, 0, 0);
lv_obj_clear_flag(fg_box, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_pos(fg, 0, 0);
lv_imgbar_set_dir(imgbar, BAR_DIR_LEFT_TO_RIGTH);
lv_obj_set_range_value(imgbar, 0, 100);
lv_imgbar_set_value(imgbar, 60); /* Value -> crop width: 60 reveals 60% of the foreground */
Warning
lv_imgbar_set_img_fg() wraps the foreground in an internal container (the new parent of the foreground). By default this container has padding and is scrollable, which pushes the foreground out of the visible area. Obtain it with lv_obj_get_parent(fg), clear its padding/border, disable scrolling, and pin the foreground to (0,0); only then does the fill sit flush against the edge.
Demo
Run the lvgl_v8_imgbar example to see the result: a gray track is shown in the center of the screen with a blue fill bar on top. A timer drives the value back and forth between 0~100, so the blue fill repeatedly grows from left to right until it covers the bar, then shrinks back.
See Also
Source path:
middleware/lvgl/lvsf/gui_widgets/lvsf_imgbar.hExample path:
example/multimedia/lvgl/lvgl_v8_imgbar