Label with main screen as parent does not inherit theme font

Description

If you setup a theme (material for example) and initialize it with a custom big font, and create a button, and then a label, if the label has the button as parent, the label is correctly formated with the theme font, but if the label has lv_scr_act() as parent, it’s not correctly formated with theme default font.

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

Simulator

What do you want to achieve?

format labels with theme font

What have you tried so far?

Code to reproduce

    lv_theme_t * th = lv_theme_material_init(200, &opensans60); //<<< my own font
    lv_theme_set_current(th);
    lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);             
    lv_obj_set_pos(btn1, 10, 10);                                    


    /*Add text*/
    lv_obj_t * label2 = lv_label_create(btn1, NULL);                  /*Put on 'btn1'*/
    lv_label_set_text(label2, "Click me");  /*label is formated with opensans60 font*/

    lv_obj_t * label2 = lv_label_create(lv_scr_act(), NULL);   /*Put on main screen*/
    lv_label_set_text(label2, "Click me");  /*label is NOT formated with opensans60 font*/

Have a look at the style inheritance documentation. Does the style for lv_scr_act() have the glass property set to 1?

I’m a bit lost with all those properties. For me, the screen acts as a main container, so it “should” behave like any other container, so when I apply a theme to the system, it should already have all properties set like for any other container.
I’ll read again all the styles and themes related documentation and get back to this thread.

thanks.

It happens because the default screen is already created when you set the theme. And the themes have effect only on the object created after lv_theme_set_current().

You do one of the followings:

    lv_theme_t * th = lv_theme_material_init(200,&lv_font_roboto_28); //<<< my own font
    lv_theme_set_current(th);

    /*Set the style manually*/
    lv_obj_set_style(lv_scr_act(), th->style.scr);
    
   /*Or create a new screen*/  
   lv_obj_t * scr = lv_obj_create(NULL, NULL);
   lv_scr_load(scr);