fix(imgfont) add user_data argument to callback (#3630)

This commit is contained in:
Amir Gonnen
2022-08-27 16:31:33 +03:00
committed by GitHub
parent 00d92f152b
commit 75fabab38a
3 changed files with 11 additions and 6 deletions

View File

@@ -6,10 +6,12 @@
LV_IMG_DECLARE(emoji_F617) LV_IMG_DECLARE(emoji_F617)
static bool get_imgfont_path(const lv_font_t * font, void * img_src, static bool get_imgfont_path(const lv_font_t * font, void * img_src,
uint16_t len, uint32_t unicode, uint32_t unicode_next) uint16_t len, uint32_t unicode, uint32_t unicode_next,
void * user_data)
{ {
LV_UNUSED(font); LV_UNUSED(font);
LV_UNUSED(unicode_next); LV_UNUSED(unicode_next);
LV_UNUSED(user_data);
LV_ASSERT_NULL(img_src); LV_ASSERT_NULL(img_src);
if(unicode == 0xF617) { if(unicode == 0xF617) {
@@ -29,7 +31,7 @@ static bool get_imgfont_path(const lv_font_t * font, void * img_src,
*/ */
void lv_example_imgfont_1(void) void lv_example_imgfont_1(void)
{ {
lv_font_t * imgfont = lv_imgfont_create(80, get_imgfont_path); lv_font_t * imgfont = lv_imgfont_create(80, get_imgfont_path, NULL);
if(imgfont == NULL) { if(imgfont == NULL) {
LV_LOG_ERROR("imgfont init error"); LV_LOG_ERROR("imgfont init error");
} }

View File

@@ -20,6 +20,7 @@
typedef struct { typedef struct {
lv_font_t * font; lv_font_t * font;
lv_get_imgfont_path_cb_t path_cb; lv_get_imgfont_path_cb_t path_cb;
void * user_data;
char path[LV_IMGFONT_PATH_MAX_LEN]; char path[LV_IMGFONT_PATH_MAX_LEN];
} imgfont_dsc_t; } imgfont_dsc_t;
@@ -45,7 +46,7 @@ static bool imgfont_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_t *
/********************** /**********************
* GLOBAL FUNCTIONS * GLOBAL FUNCTIONS
**********************/ **********************/
lv_font_t * lv_imgfont_create(uint16_t height, lv_get_imgfont_path_cb_t path_cb) lv_font_t * lv_imgfont_create(uint16_t height, lv_get_imgfont_path_cb_t path_cb, void * user_data)
{ {
LV_ASSERT_MSG(LV_IMGFONT_PATH_MAX_LEN > sizeof(lv_img_dsc_t), LV_ASSERT_MSG(LV_IMGFONT_PATH_MAX_LEN > sizeof(lv_img_dsc_t),
"LV_IMGFONT_PATH_MAX_LEN must be greater than sizeof(lv_img_dsc_t)"); "LV_IMGFONT_PATH_MAX_LEN must be greater than sizeof(lv_img_dsc_t)");
@@ -57,6 +58,7 @@ lv_font_t * lv_imgfont_create(uint16_t height, lv_get_imgfont_path_cb_t path_cb)
dsc->font = (lv_font_t *)(((char *)dsc) + sizeof(imgfont_dsc_t)); dsc->font = (lv_font_t *)(((char *)dsc) + sizeof(imgfont_dsc_t));
dsc->path_cb = path_cb; dsc->path_cb = path_cb;
dsc->user_data = user_data;
lv_font_t * font = dsc->font; lv_font_t * font = dsc->font;
font->dsc = dsc; font->dsc = dsc;
@@ -102,7 +104,7 @@ static bool imgfont_get_glyph_dsc(const lv_font_t * font, lv_font_glyph_dsc_t *
LV_ASSERT_NULL(dsc); LV_ASSERT_NULL(dsc);
if(dsc->path_cb == NULL) return false; if(dsc->path_cb == NULL) return false;
if(!dsc->path_cb(dsc->font, dsc->path, LV_IMGFONT_PATH_MAX_LEN, unicode, unicode_next)) { if(!dsc->path_cb(dsc->font, dsc->path, LV_IMGFONT_PATH_MAX_LEN, unicode, unicode_next, dsc->user_data)) {
return false; return false;
} }

View File

@@ -27,7 +27,8 @@ extern "C" {
/* gets the image path name of this character */ /* gets the image path name of this character */
typedef bool (*lv_get_imgfont_path_cb_t)(const lv_font_t * font, void * img_src, typedef bool (*lv_get_imgfont_path_cb_t)(const lv_font_t * font, void * img_src,
uint16_t len, uint32_t unicode, uint32_t unicode_next); uint16_t len, uint32_t unicode, uint32_t unicode_next,
void * user_data);
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
@@ -39,7 +40,7 @@ typedef bool (*lv_get_imgfont_path_cb_t)(const lv_font_t * font, void * img_src,
* @param path_cb a function to get the image path name of character. * @param path_cb a function to get the image path name of character.
* @return pointer to the new imgfont or NULL if create error. * @return pointer to the new imgfont or NULL if create error.
*/ */
lv_font_t * lv_imgfont_create(uint16_t height, lv_get_imgfont_path_cb_t path_cb); lv_font_t * lv_imgfont_create(uint16_t height, lv_get_imgfont_path_cb_t path_cb, void * user_data);
/** /**
* Destroy a image font that has been created. * Destroy a image font that has been created.