LVGL v8 Imgarray
lvsf_imgarray is a custom widget that SiFli wraps around lvsf_baseimg. It assembles a numeric value from a set of images, like a seven-segment/flip display. It can display the full form of a number — sign + integer digits + decimal point + fractional digits + unit — where each glyph is an image. Give it a set of glyph images (0~9 and the decimal point, unit, and so on), the number of integer/fractional digits, and the indices of the decimal-point and unit glyphs, then feed it a value; it assembles [sign][integer].[fraction][unit] from those images.
Main header: middleware/lvgl/lvsf/gui_widgets/lvsf_imgarray.h
Base class and type definitions: middleware/lvgl/lvsf/gui_widgets/lvsf_baseimg.h
Dependent widget: LVGL img (
LV_USE_IMG)Example project: example/multimedia/lvgl/lvgl_v8_imgarray
Features
Assembles a value from image glyphs, supporting sign, integer digits, decimal point, fractional digits, and unit.
Supports several value modes:
BASEIMG_TYPE_ARRAY_INDEX(the value is the image index),BASEIMG_TYPE_ARRAY_Q248(Q24.8 fixed-point, supports fractions), and so on.Configurable number of integer/fractional digits, and the indices of the decimal point, sign, unit, and empty glyph in the glyph array.
Switches to enable leading-zero and trailing-zero display.
Configurable spacing between images.
Supports three ways to set the source array: memory descriptor array, file path, and single-source sequence frames.
Use Cases
Seven-segment-style numeric readouts (battery, heart rate, temperature, percentage).
Flip/dial numeric displays that need custom glyph images.
Real-time numbers on watch dials and instrument clusters.
Supported Boards
sf32lb52-lcd_n16r8
sf32lb52-lchspi-ulp
Configuration and Initialization
lvsf_imgarray depends on the LVGL img component. In menuconfig, confirm it is enabled:
CONFIG_LV_USE_IMG=y
In the BSP, the LVSF_USE_IMGARRAY macro controls whether this widget is compiled.
Minimum flow to create an object:
#include "lvsf_imgarray.h"
#include "lvsf_baseimg.h"
lv_obj_t *ia = lv_imgarray_create(lv_scr_act());
API Reference
Creation and refresh
Function |
Description |
Parameters / Returns |
|---|---|---|
|
Creates an image array object |
|
|
Refresh timer callback |
|
Source array settings
Function |
Description |
Parameters / Returns |
|---|---|---|
|
Sets the source array (memory descriptors) |
|
|
Sets the source array by file path |
|
|
Sets the sequence-frame image source and index range |
|
Layout and glyph configuration
Function |
Description |
Parameters / Returns |
|---|---|---|
|
Sets the image type |
|
|
Sets the number of integer digits |
|
|
Sets the number of fractional digits |
|
|
Sets the unit image object |
|
|
Sets the decimal-point glyph index |
|
|
Sets the sign glyph index |
|
|
Sets the unit glyph index |
|
|
Sets the empty glyph index |
|
|
Sets leading-zero display |
|
|
Sets trailing-zero display |
|
|
Sets the image spacing |
|
|
Gets the source count |
Returns the source count |
Value settings
Function |
Description |
Parameters / Returns |
|---|---|---|
|
Sets the value (Q24.8 format) |
|
|
Sets the value (integer format) |
|
Typical Usage
The following example displays a measurement like 36.5% (2 integer digits + 1 fractional digit + decimal point + percent-unit):
#include "lvsf_baseimg.h"
#include "lvsf_imgarray.h"
/* glyph_arr: digits 0..9 + "." (index 10) + "%" (index 11) */
extern const lv_img_dsc_t *glyph_arr[12];
void demo_imgarray_init(void)
{
lv_obj_t *ia = lv_imgarray_create(lv_scr_act());
lv_imgarray_set_img_type(ia, BASEIMG_TYPE_ARRAY_Q248); /* Q24.8: supports fractions */
lv_imgarray_set_src_array(ia, glyph_arr, 0, 11); /* Store the glyph array first */
lv_imgarray_set_interval(ia, 2);
lv_imgarray_set_leading_zero(ia, true);
lv_imgarray_set_trailing_zero(ia, true);
lv_imgarray_set_int_num(ia, 2); /* 2 integer digits */
lv_imgarray_set_float_num(ia, 1); /* 1 fractional digit */
lv_imgarray_set_point_idx(ia, 10); /* Decimal point uses index 10 */
lv_imgarray_set_unit_idx(ia, 11); /* Unit uses index 11 */
lv_obj_center(ia);
lv_imgarray_set_value(ia, 365 * 256 / 10); /* 36.5 (Q24.8): shows "36.5%" */
}
Warning
The call order matters: you must first call lv_imgarray_set_src_array() to store the glyph array, and only then call set_int_num() / set_point_idx() / set_unit_idx() and so on — these interfaces create the corresponding image cells and apply the stored array. If the order is reversed, it fails because the array is not ready.
Demo
Run the lvgl_v8_imgarray example to see the result: a decimal with a unit (such as 38.5%) is shown in the center of the screen, assembled from the integer digits, decimal point, fractional digits, and unit images. A timer sweeps the value back and forth between 20.0~80.0%, so the reading keeps changing.
See Also
Source path:
middleware/lvgl/lvsf/gui_widgets/lvsf_imgarray.hExample path:
example/multimedia/lvgl/lvgl_v8_imgarray