Create Invisible Containers/Objects


Create invisible containers/objects

What MCU/Processor/Board and compiler are you using?

Custom ESP32 with SSD1306: Mono 64x48 landscape

What LVGL version are you using?


What do you want to achieve?

I’d like to be able to divide my screen into sections and then center labels inside those sections of the screen.

What have you tried so far?

I was able to achieve this with objects but it would be nice if there were no borders as my screen area is very limited.

Code to reproduce

// Get the current screen and wipe all child objects
    lv_obj_t *scr = lv_scr_act();

    // Divide the screen in half
    lv_obj_t *leftPlug = lv_obj_create(scr, NULL);
    lv_obj_set_size(leftPlug, 32, 48);
    lv_obj_t *rightPlug = lv_obj_create(scr, leftPlug);
    lv_obj_set_pos(rightPlug, 32, 0);

    // Create left plug symbols centered on the left side
    // Check state and display result, use dummy values for now
    lv_obj_t *leftTitle = lv_label_create(leftPlug, NULL);
    lv_obj_align(leftTitle, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);

    // Create right plug symbols centered on the right side
    // Check state and display result, use dummy values for now
    lv_obj_t *rightTitle = lv_label_create(rightPlug, NULL);
    lv_label_set_text(rightTitle, "R\n" LV_SYMBOL_CLOSE "\n");
    lv_obj_align(rightTitle, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);

It should be possible to do this by setting the bg_opa property of the objects’ styles to LV_OPA_TRANSP. You may have to do the same for border_opa as well.

1 Like

you could used CONT to split the screen,and set the boder’s widght of style to 0

lv_obj_t* cont_topleft;
lv_obj_t* cont_bottomleft;
lv_obj_t* cont_topright;
lv_obj_t* cont_bottomright;
lv_obj_t* cont_table[] = { &cont_topleft ,&cont_topright ,&cont_bottomleft,&cont_bottomright };
void create_label_cente(lv_obj_t* parent)
    lv_obj_t* txt_label = lv_label_create(parent, NULL);
    lv_label_set_text(txt_label, "text");
    lv_obj_align(txt_label, parent, LV_ALIGN_CENTER, 0, 0);
void screen_spit(void)

    for (uint8_t i = 0; i < 4; i++)
        cont_table[i] = lv_cont_create(lv_scr_act(), NULL);
  /*      lv_obj_set_style_local_border_width(cont_table[i],LV_OBJ_PART_MAIN,LV_STATE_DEFAULT,0);
        lv_obj_set_style_local_bg_opa(cont_table[i], LV_OBJ_PART_MAIN, LV_STATE_DEFAULT,0);*/
        lv_obj_set_size(cont_table[i], 100, 100);
        lv_obj_align(cont_table[i], NULL, align_table[i], 0, 0);


1 Like

Maybe I’m not understanding something here: why initialize cont_table with references to the global pointers, just to overwrite them?

1 Like

Because the argument is passed as a pointer, another easy way to understand it is to use structures, such as

typedef struct
	const void* src_img;
img_table_t img_table[]={&main_page,&menu,&notebinding,&noteduty,&hardwarecheck,&examready,&examing,&examend};

1 Like