acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_imgfont_1.c (1302B)

      1 #include "../../lv_examples.h"
      2 #include <stdio.h>
      3 
      4 #if LV_BUILD_EXAMPLES
      5 #if LV_USE_IMGFONT
      6 
      7 LV_IMG_DECLARE(emoji_F617)
      8 static bool get_imgfont_path(const lv_font_t * font, void * img_src,
      9                              uint16_t len, uint32_t unicode, uint32_t unicode_next)
     10 {
     11     LV_UNUSED(font);
     12     LV_UNUSED(unicode_next);
     13     LV_ASSERT_NULL(img_src);
     14 
     15     if(unicode == 0xF617) {
     16         memcpy(img_src, &emoji_F617, sizeof(lv_img_dsc_t));
     17     }
     18     else {
     19         char * path = (char *)img_src;
     20         snprintf(path, len, "%s/%04X.%s", "A:lvgl/examples/assets/emoji", unicode, "png");
     21         path[len - 1] = '\0';
     22     }
     23 
     24     return true;
     25 }
     26 
     27 /**
     28  * draw img in label or span obj
     29  */
     30 void lv_example_imgfont_1(void)
     31 {
     32     lv_font_t * imgfont = lv_imgfont_create(80, get_imgfont_path);
     33     if(imgfont == NULL) {
     34         LV_LOG_ERROR("imgfont init error");
     35     }
     36 
     37     imgfont->fallback = LV_FONT_DEFAULT;
     38 
     39     lv_obj_t * label1 = lv_label_create(lv_scr_act());
     40     lv_label_set_text(label1, "12\uF600\uF617AB");
     41     lv_obj_set_style_text_font(label1, imgfont, LV_PART_MAIN);
     42     lv_obj_center(label1);
     43 }
     44 #else
     45 
     46 void lv_example_imgfont_1(void)
     47 {
     48     lv_obj_t * label = lv_label_create(lv_scr_act());
     49     lv_label_set_text(label, "imgfont is not installed");
     50     lv_obj_center(label);
     51 }
     52 
     53 #endif
     54 #endif