Image (ls_image_t)
Draws a converted image descriptor, optionally rotated around a pivot. An A8 source is a mask you tint, so one asset serves any color.
ls_image.hSource header · lvgl/lvgl_safels_error_code_t ls_image_create(ls_screen_t * screen, ls_image_t * image);Pixel data is described by an ls_image_dsc_t, which is what the image converter
generates for you (see Assets):
typedef struct {
ls_frame_buffer_color_t color_format; /* one of ls_image_color_format_t */
int32_t width;
int32_t height;
int32_t stride; /* bytes per row */
const void * data; /* pixel data */
} ls_image_dsc_t;Supported formats (ls_image_color_format_t):
| Format | Use it for |
|---|---|
LS_IMAGE_COLOR_FORMAT_RGB565 | Opaque 16-bit images - cheapest to blit |
LS_IMAGE_COLOR_FORMAT_ARGB8888 | Full color with per-pixel alpha |
LS_IMAGE_COLOR_FORMAT_A8 | An alpha-only mask tinted with the widget's a8_color - one asset, any color |
Note: RGB888 and RGB565 image sources are not yet supported in the preview. Use
ARGB8888orA8.
| Field | Type | Description |
|---|---|---|
x, y | uint32_t | Top-left position |
src | const ls_image_dsc_t * | Image source descriptor |
opa | uint8_t | Opacity (0..255) |
a8_color | ls_color_t | Tint color, used only for A8 sources |
pivot_x, pivot_y | int32_t | Rotation pivot, relative to the image's top-left |
rotation | int32_t | Rotation angle in degrees |
There is no width/height: the size comes from src.
Defaults after create: opaque, no rotation, black a8_color, src is NULL.
An image without a src makes ls_render() fail for the whole frame.
extern const ls_image_dsc_t my_logo; /*generated by the image converter*/
static ls_image_t logo;
if(ls_image_create(&screen, &logo) != LS_ERROR_CODE_OK) return 1;
logo.x = 20;
logo.y = 20;
logo.src = &my_logo; /*without a src, ls_render() fails*/
/*An A8 source is a mask: one asset, tinted to whatever color you want.*/
extern const ls_image_dsc_t my_icon_a8;
static ls_image_t needle;
if(ls_image_create(&screen, &needle) != LS_ERROR_CODE_OK) return 1;
needle.x = 200;
needle.y = 20;
needle.src = &my_icon_a8;
needle.a8_color = LS_COLOR_HEX(0x3d8bfd);
needle.pivot_x = 16; /*relative to the image's top-left*/
needle.pivot_y = 16;
needle.rotation = 45;Last updated on
Button (ls_button_t)
A filled rectangle whose color and opacity are chosen by its state. Ten states, each with its own color field, and five of them start transparent.
Image Button (ls_image_button_t)
The same state machine as a button, but each state shows a different image. Every state you can reach needs a source.