sjgc
July 12, 2024, 9:07am
1
Description
I have used LVGL font converter to add a font with one symbol code “\xEF\xF7\x8C” /63372 f78c /
Copied the file to the Font folder, added ‘myfontawesome’
myfontawesome.c (6.1 KB)
to a style. The example below compiles, the button is drawn but with out the custom symbol being shown.
Using Waveahare ESP32 s3 touch 4.3
LVGL 8.4 (with lvgl_port_v8 from waveshare)
Code to reproduce
void lv_example_btn_1(void)
{
LV_FONT_DECLARE(myfontawesome);
#define MY_USB_SYMBOL “\xEF\xF7\x8C”
static lv_style_t style_btn;
lv_style_init(&style_btn);
lv_style_set_text_font(&style_btn,&myfontawesome);
lv_obj_t * label;
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -40);
label = lv_label_create(btn1);
lv_obj_add_style(label, &style_btn, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_label_set_text(label, MY_USB_SYMBOL);
lv_obj_center(label);
}
I also tried adding
#if !defined MY_SYMBOL
#define MY_SYMBOL_ “\xEF\xF7\x8C” /63372 0xF78C /
#endif
to lv_symbol_def.h
What am I missing.
Thank you for any help.
elgerg
July 12, 2024, 9:30am
2
Did you add it to symbol instead of range like I incorrectly did?
Description
I’m struggling to create a single font symbol using the font awesome instructions. I’m sure I’ve done this in the past and it worked fine but there must be something wrong/missing in the instructions.
What MCU/Processor/Board and compiler are you using?
ESP32-S3 with Arduino
What LVGL version are you using?
8.4
What do you want to achieve?
Show a symbol instead of a square box
What have you tried so far?
Following the guide here:
https://docs.lvgl.io/8.4/overview/font.html#add-n…
sjgc
July 12, 2024, 2:24pm
3
Good point, i cannot rember but i thought i added as range so i will have another go. Do you see anything wrong in the code example.
elgerg
July 12, 2024, 2:31pm
4
You should have the following outside of the button example, it should be in the h file if you’re using c or the main ino if Arduino
LV_FONT_DECLARE(myfontawesome);
#define MY_USB_SYMBOL “\xEF\xF7\x8C”
Also when I’ve done mine in the past i directly set the font on the label instead of using a style as I was only using them here and there…
lbl_MainLight_Icon = lv_label_create(ui_Home_Screen);
lv_obj_set_style_text_color(lbl_MainLight_Icon, lv_color_hex(LV_COLOUR_LIGHT_OFF), LV_PART_MAIN);
lv_label_set_text(lbl_MainLight_Icon, LV_SYMBOL_POWER);
lv_obj_set_style_text_font(lbl_MainLight_Icon, &lv_font_montserrat_40, LV_PART_MAIN| LV_STATE_DEFAULT);
lv_obj_align_to(lbl_MainLight_Icon, btn_light, LV_ALIGN_TOP_LEFT, -5, -5);
sjgc
July 12, 2024, 4:47pm
5
Hi
OK checked I did use range. Note using arduino same result no icon displayed
LV_FONT_DECLARE(myfontawesome);
#define MY_USB_SYMBOL “\xEF\xF7\x8C”
void setup()
{
/* lvgl_port_v8 code left out*/
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, 0);
lv_obj_t * label = lv_label_create(btn1);
lv_label_set_text(label, MY_USB_SYMBOL"arrow");
lv_obj_set_style_text_font(label, &myfontawesome, LV_PART_MAIN| LV_STATE_DEFAULT);
lv_obj_align_to(label, btn1, LV_ALIGN_CENTER, 0, 0);
}
Apart from putting myfontawesome in /src/fonts folder is there any where else I need to make declarations.
Although I download FontAwesome5-Solid+Brands+Regular.woff and used this in the font converter, I assume that if my range was not valid then the process would error.
i think f78c
symbol should be represented in utf-8 as \xEF\x9E\x8C sequence