Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
6
sdk/lib/lvgl/examples/others/imgfont/index.rst
Normal file
6
sdk/lib/lvgl/examples/others/imgfont/index.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
Use emojis in a text.
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/imgfont/lv_example_imgfont_1
|
||||
:language: c
|
||||
|
||||
38
sdk/lib/lvgl/examples/others/imgfont/lv_example_imgfont.h
Normal file
38
sdk/lib/lvgl/examples/others/imgfont/lv_example_imgfont.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file lv_example_imgfont.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_IMGFONT_H
|
||||
#define LV_EXAMPLE_IMGFONT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_imgfont_1(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_IMGFONT_H*/
|
||||
63
sdk/lib/lvgl/examples/others/imgfont/lv_example_imgfont_1.c
Normal file
63
sdk/lib/lvgl/examples/others/imgfont/lv_example_imgfont_1.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "../../lv_examples.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if LV_BUILD_EXAMPLES
|
||||
#if LV_USE_IMGFONT
|
||||
|
||||
LV_IMG_DECLARE(emoji_F617)
|
||||
static bool get_imgfont_path(const lv_font_t * font, void * img_src,
|
||||
uint16_t len, uint32_t unicode, uint32_t unicode_next,
|
||||
lv_coord_t * offset_y, void * user_data)
|
||||
{
|
||||
LV_UNUSED(font);
|
||||
LV_UNUSED(unicode_next);
|
||||
LV_UNUSED(offset_y);
|
||||
LV_UNUSED(user_data);
|
||||
LV_ASSERT_NULL(img_src);
|
||||
|
||||
if(unicode < 0xF000) return false;
|
||||
|
||||
if(unicode == 0xF617) {
|
||||
memcpy(img_src, &emoji_F617, sizeof(lv_img_dsc_t));
|
||||
}
|
||||
else {
|
||||
char * path = (char *)img_src;
|
||||
#if LV_USE_FFMPEG
|
||||
lv_snprintf(path, len, "%s/%04X.png", "lvgl/examples/assets/emoji", unicode);
|
||||
#elif LV_USE_PNG
|
||||
lv_snprintf(path, len, "%s/%04X.png", "A:lvgl/examples/assets/emoji", unicode);
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* draw img in label or span obj
|
||||
*/
|
||||
void lv_example_imgfont_1(void)
|
||||
{
|
||||
lv_font_t * imgfont = lv_imgfont_create(80, get_imgfont_path, NULL);
|
||||
if(imgfont == NULL) {
|
||||
LV_LOG_ERROR("imgfont init error");
|
||||
return;
|
||||
}
|
||||
|
||||
imgfont->fallback = LV_FONT_DEFAULT;
|
||||
|
||||
lv_obj_t * label1 = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(label1, "12\uF600\uF617AB");
|
||||
lv_obj_set_style_text_font(label1, imgfont, LV_PART_MAIN);
|
||||
lv_obj_center(label1);
|
||||
}
|
||||
#else
|
||||
|
||||
void lv_example_imgfont_1(void)
|
||||
{
|
||||
lv_obj_t * label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(label, "imgfont is not installed");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
41
sdk/lib/lvgl/examples/others/imgfont/lv_example_imgfont_1.py
Normal file
41
sdk/lib/lvgl/examples/others/imgfont/lv_example_imgfont_1.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import fs_driver
|
||||
import sys
|
||||
|
||||
# set LV_USE_FFMPEG to True if it is enabled in lv_conf.h
|
||||
LV_USE_FFMPEG = True
|
||||
LV_FONT_DEFAULT = lv.font_montserrat_14
|
||||
|
||||
fs_drv = lv.fs_drv_t()
|
||||
fs_driver.fs_register(fs_drv, 'A')
|
||||
|
||||
# get the directory in which the script is running
|
||||
try:
|
||||
script_path = __file__[:__file__.rfind('/')] if __file__.find('/') >= 0 else '.'
|
||||
except NameError:
|
||||
script_path = ''
|
||||
|
||||
def get_imgfont_path(font, img_src, length, unicode, unicode_next, offset_y, user_data) :
|
||||
if unicode < 0xf600:
|
||||
return
|
||||
if LV_USE_FFMPEG:
|
||||
path = bytes(script_path + "/../../assets/emoji/{:04X}.png".format(unicode) + "\0","ascii")
|
||||
else:
|
||||
path = bytes("A:"+ script_path + "/../../assets/emoji/{:04X}.png".format(unicode) + "\0","ascii")
|
||||
# print("image path: ",path)
|
||||
img_src.__dereference__(length)[0:len(path)] = path
|
||||
return True
|
||||
|
||||
#
|
||||
# draw img in label or span obj
|
||||
#
|
||||
imgfont = lv.imgfont_create(80, get_imgfont_path, None)
|
||||
if imgfont == None:
|
||||
print("imgfont init error")
|
||||
sys.exit(1)
|
||||
|
||||
imgfont.fallback = LV_FONT_DEFAULT
|
||||
|
||||
label1 = lv.label(lv.scr_act())
|
||||
label1.set_text("12\uF600\uF617AB")
|
||||
label1.set_style_text_font(imgfont, lv.PART.MAIN)
|
||||
label1.center()
|
||||
Reference in New Issue
Block a user