Reputation: 662
I have a simple lvgl example which runs on an embedded device. It should work like an Overlay on top of an existing image. In this case, I only want to render the text of the label thus the label and the screen should have a transparent background.
My approach is to set
lv_obj_set_style_bg_opa(screen, LV_OPA_TRANSP, 0);
on the screen and
lv_style_set_bg_opa(&label_style, LV_OPA_TRANSP);
on the label.
This does not render anything (I get a fully transparent window with no content). Removing the lv_obj_set_style_bg_opa(screen, LV_OPA_TRANSP, 0);
will result in having a green screen with a red label having a transparent background.
#include "lvgl/lvgl.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
static const char * getenv_default(const char * name, const char * dflt)
{
return getenv(name) ?: dflt;
}
static lv_obj_t * example_label;
int main(void)
{
lv_init();
const char * device = getenv_default("LV_LINUX_FBDEV_DEVICE", "/dev/fb0");
lv_display_t * disp = lv_linux_fbdev_create();
lv_linux_fbdev_set_file(disp, device);
lv_obj_t * screen = lv_obj_create(NULL);
lv_screen_load(screen);
//lv_obj_set_style_bg_opa(screen, LV_OPA_TRANSP, 0);
lv_obj_set_style_bg_color(screen, lv_color_make(0, 255, 0), 0);
static lv_style_t label_style;
lv_style_init(&label_style);
lv_style_set_text_color(&label_style, lv_color_hex(0xFF0000));
lv_style_set_bg_opa(&label_style, LV_OPA_TRANSP);
lv_style_set_bg_color(&label_style, lv_color_hex(0x0000FF));
lv_style_set_text_font(&label_style, &lv_font_montserrat_32);
example_label = lv_label_create(screen);
lv_label_set_text(example_label, "Hello World");
lv_obj_add_style(example_label, &label_style, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_align(example_label, LV_ALIGN_BOTTOM_MID, 0, 0);
while(1) {
lv_timer_handler();
usleep(5000);
}
return 0;
}
In lv_conf.h
I've been playing around with
#define LV_COLOR_DEPTH 32
#define LV_USE_LINUX_FBDEV 1
#if LV_USE_LINUX_FBDEV
#define LV_LINUX_FBDEV_BSD 0
//#define LV_LINUX_FBDEV_RENDER_MODE LV_DISPLAY_RENDER_MODE_DIRECT
#define LV_LINUX_FBDEV_RENDER_MODE LV_DISPLAY_RENDER_MODE_FULL
//#define LV_LINUX_FBDEV_BUFFER_COUNT 1
#define LV_LINUX_FBDEV_BUFFER_COUNT 2
#define LV_LINUX_FBDEV_BUFFER_SIZE 60
#endif
It seems like there was an LV_COLOR_SCREEN_TRANSP
option at some point but but yet no more.
I'm using the lvgl linux port from https://github.com/lvgl/lv_port_linux and tried v9.0 and master.
I also managed to get the same example working in QT via framebuffer so the device (hardware and software) definitely supports this.
Upvotes: 0
Views: 373
Reputation: 662
It seems like setting lv_display_set_color_format(NULL, LV_COLOR_FORMAT_ARGB8888);
right after lv_screen_load(screen);
does the job. So no special settings in lv_conf.h
are needed.
Upvotes: 0