Dynamic display of fonts

Description

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

xr872

What LVGL version are you using?

8.2.0

What do you want to achieve?

1.I have two font files, one containing “abc” and one containing “def”.
2.Use create_label() to create a label,now it only display “abc”
3.Use load_font(),it’s still just showing “abc”
4. What should I do to display “abcdef”

What have you tried so far?

I try to use lv_refr_now(lv_disp_t * disp) and _lv_inv_area(lv_disp_t * disp, const lv_area_t * area_p), but none of them worked

Code to reproduce

/*You code here*/
LV_FONT_DECLARE(font_abc);
LV_FONT_DECLARE(font_def);

void create_label(lv_obj_t *parent)
{
	lv_obj_t *label = lv_label_create(parent);
	lv_label_set_text(label, "abcdef");
	lv_obj_set_style_text_font(label, &font_abc, 0);
}

void load_font()
{
	lv_font_t *f = &font_abc;
	f->fallback = (const lv_font_t *)&font_def;
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

as we know, one object has only one font type. if u want to display all two font types , it is necessary to creat two object.

https://docs.lvgl.io/master/overview/font.html#use-font-fallback

Hello, it seems to me that the fallback font is only used when there are no symbols/glyphs for a character in a font. Say you have two fonts with the following glyphs:

Font 1: ABCDEFG
Font 2: ABCDEFGHIJKL (fallback font!)

Now let’s say you want to set a label to say “HELLO”
it will recognize that font 1 does not have the H and L, so it uses the H and L from the fallback font.
Result would be: HELLO .

I’m not sure what you want to achieve with this code here, could you explain?
I think you need to load the font first, including the fallback, and then try to put text in a label.

When I set a label, the fallback for Font 1 is NULL. Maybe later, I’ll download Font 2 from the Internet, at which point I’ll set the Font1->fallback = Font 2.

At this point, how do we make the Font that is not in Font 1 appear without recreate the label?

:fish_cake:ahhhhh

What? Did you manage to figure anything out?

When I set a label, the fallback for Font 1 is NULL. Maybe later, I’ll download Font 2 from the Internet, at which point I’ll set the Font1->fallback = Font 2.

At this point, how do we make the Font that is not in Font 1 appear without recreate the label?

Can someone help me?

Hello,

I am currently unable to test this out, but try the following:

Set the font:
lv_style_set_text_font(&my_style, &some_font); /*Set a different font*/
followed by
lv_obj_invalidate(my_label);

I am not sure about the style here, you might have to use some sort of default style or current style. Was unable to find anything on that.

1 Like

Thank u very much,it’s worked.

1 Like

Great to hear. Make sure to mark the correct answer as the solution so other people know where to look :grin: