Complete Font Example

I’m working Teensy 4.1 on Arduino. I’d like to see just one complete example of how to use a font (I’m so embarrassed to ask something so basic!) I’ve done the online font converter, which creates the font just fine. I see many examples that say:

lv_style_copy(&font_test_style, &lv_style_plain);
font_test_style.text.font = &Arial_75;

But the compiler complains “error: ‘lv_style_plain’ was not declared in this scope”
and “error: ‘struct lv_style_t’ has no member named ‘text’”

Looks like I need to #include something? The examples are SO good, and I’ve made excellent progress so far, but I can’t find a single complete example of how to use a font – what to #include, how to declare, etc. Just an example that creates a label in a new font and nothing more. Thanks in advance… --BE

I think you have to declare font before creating the style likeLV_FONT_DECLARE(Arial_75); and then lv_style_set_text_font(&text_style, LV_STATE_DEFAULT, &Arial_75);

Thanks Paul. I had already done
(in global space). I added
lv_style_set_text_font(&font_test_style, LV_STATE_DEFAULT, &Arial_75);
The compiler accepts that, but I still get exactly the same errors. There must be an lv_example that changes the font (e.g., there’s all that Montserrat definition), but I can’t find it (I don’t have WinGrep.)

I assume you first have created the style and initialized it? static lv_style_t text_style;

The example you are referencing is for version 6 and older. What version of LVGL are you using?

If you are using v7 or newer this is the correct way to do it:

    static lv_style_t style;
    lv_style_set_text_font(&style, LV_STATE_DEFAULT, &Arial_75);

Try just this and see if you get the same error.

THANKS!! That enabled me to get it working. But nothing happened until I applied the style to the label with (found buried deep in a “styles” example) :

lv_obj_add_style(TempoLabel, LV_LABEL_PART_MAIN, &TempoLabelStyle);

The styles subject is pretty intense – I’m excited about learning more; it’s clearly designed to be flexible and powerful. And same goes for lvgl on a bigger level – allows embedding powerful graphics in a minimal system (i.e., boots immediately.) But I have a job to get done, so (again) a complete working example would have saved me precious time. Would it help others to post my final working code? I’d have to sanitize it a bit…

1 Like

It would be super helpful if you were willing to post your final working code.