Can't apply a style

:frowning: i everybody,
I’m trying to apply a style but it doesn’t work… What did I do wrong??
this is my code:

//style def
  static lv_style_t* stylTitle;
  lv_style_init(stylTitle);
//define the text and apply style
  lv_style_set_text_font(stylTitle,LV_FONT_MONTSERRAT_10);
  lv_label_set_text(label, BoatName.c_str());  // set label text
  lv_obj_add_style(label,stylTitle,0);
  lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 20);      // Center but 20 from the top

Without style, everything works fine, with style, the display is blinking white (nothing on it, just white blinking)

Display :WT32-SC01_V3.3
ESP32 Wronder (programmed as Expressif ESP32 DEVmodule
LVGL V8.3.11
IDE VS-platformIO

I’ve tried this but can’t compile in LVGL V8.3.11??

  static lv_style_t* stylTitle;
  lv_style_init(stylTitle);
  lv_style_set_text_font(stylTitle,LV_STATE_DEFAULT,&LV_FONT_MONTSERRAT_10);

LV_STATE_DEFAULT,&LV_FONT_MONTSERRAT_10 is not correct for the compiler. the function lv_style_set_text_font() seems to have only 2 arguments and not 3…

I’m stuck on character sizes since yesterday.:-(everything is working fine if I use lcd.setTextSize(3) and lcd.println() but it’s not a proper way to do it…
Thank you for your help.

Hello,

This bit:

  static lv_style_t* stylTitle;
  lv_style_init(stylTitle);
  lv_style_set_text_font(stylTitle,LV_STATE_DEFAULT,&LV_FONT_MONTSERRAT_10);

should be

  static lv_style_t stylTitle;
  lv_style_init(&stylTitle);
  lv_style_set_text_font(&stylTitle, LV_FONT_MONTSERRAT_10);

I am not sure if you need to use the font’s address. so perhaps it should be &LV_FONT_MONTSERRAT_10 here.
Let me know if it works!

Hi Tinus,
Thank you for your time and your answer…
Unfortunately, it doesn’t work (I’ve tried before and try again) but same result.

 //style def
  static lv_style_t stylTitle;
  lv_style_init(&stylTitle);
  lv_style_set_text_font(&stylTitle,LV_FONT_MONTSERRAT_10);
  lv_obj_t *label = lv_label_create(lv_scr_act()); // full screen as the parent
  lv_label_set_text(label, BoatName.c_str());  // set label text
  lv_obj_add_style(label,&stylTitle,0);
  lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 20);      // Center but 20 from the top

give exactly the same result. full white blinking display…

This is working but can’t increase the title:

 //style def
  //static lv_style_t stylTitle;
  //lv_style_init(&stylTitle);
  //lv_style_set_text_font(&stylTitle,LV_FONT_MONTSERRAT_10);
  lv_obj_t *label = lv_label_create(lv_scr_act()); // full screen as the parent
  lv_label_set_text(label, BoatName.c_str());  // set label text
  //lv_obj_add_style(label,&stylTitle,0);
  lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 20);      // Center but 20 from the top

I probably did something wrong but I can’t ffind what :frowning:

and &LV_FONT_MONTSERRAT_10 doesn’t compile :cry:

If you have another idea, just let me know and I will try again.
Thank you Tinus.

lv_style_set_text_font(&stylTitle,&lv_font_montserrat_10);

change to the lower case font name.

1 Like

Hi Trident,
Thank you for your time and your answer.
Unfortunately,
lv_style_set_text_font(&stylTitle,&lv_font_montserrat_10);
doesn’t compile neither…

The error is:
src/main.cpp:80:38: error: ‘lv_font_montserrat_10’ was not declared in this scope
lv_style_set_text_font(&stylTitle,&lv_font_montserrat_10);

in the library, the font are declared in block letters so, it doesn’t work and this is not a surprise but I tried anyway…

Thank you Trident.

in the lv_conf.h

#define LV_FONT_MONTSERRAT_10     1
1 Like

Trident, BRAVO,
it’s working with:

  static lv_style_t stylTitle;
  lv_style_init(&stylTitle);
  lv_style_set_text_font(&stylTitle,&lv_font_montserrat_26);
  lv_obj_t *label = lv_label_create(lv_scr_act()); // full screen as the parent
  lv_label_set_text(label, BoatName.c_str());  // set label text
  lv_obj_add_style(label,&stylTitle,0);
  lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 20);      // Center but 20 from the top

You was right, in lower case with &…
Thank you so much Trident. and yes, need to modify the lv_conf.h.

Fantastic Trident. :slight_smile:
Thank you soooooo much.