diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index 0b4ad89f5b..f4246b1ee4 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -14,6 +14,7 @@ #error "lv_img: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " #endif +#include "../lv_core/lv_lang.h" #include "../lv_themes/lv_theme.h" #include "../lv_misc/lv_fs.h" #include "../lv_misc/lv_ufs.h" @@ -202,6 +203,24 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img) lv_obj_invalidate(img); } +/** + * Set an ID which means a the same source but on different languages + * @param img pointer to an image object + * @param src_id ID of the source + */ +void lv_img_set_src_multi(lv_obj_t * img, uint32_t txt_id) +{ +#if USE_LV_MULTI_LANG + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + ext->lang_txt_id = txt_id; + + /*Apply the new language*/ + img->signal_func(img, LV_SIGNAL_LANG_CHG, NULL); +#else + LV_LOG_WARN("lv_img_set_src_multi: multiple languages are not enabled. See lv_conf.h USE_LV_MULTI_LANG ") +#endif +} + /** * Enable the auto size feature. * If enabled the object size will be same as the picture size. @@ -350,6 +369,17 @@ static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param) lv_img_set_src(img, ext->src); } + } else if(sign == LV_SIGNAL_LANG_CHG) { +#if USE_LV_MULTI_LANG + if(ext->lang_txt_id != LV_LANG_TXT_ID_NONE) { + const char * lang_src = lv_lang_get_text(ext->lang_txt_id); + if(lang_src) { + lv_img_set_src(img, lang_src); + } else { + LV_LOG_WARN("lv_lang_get_text return NULL for an image's source"); + } + } +#endif } else if(sign == LV_SIGNAL_GET_TYPE) { lv_obj_type_t * buf = param; uint8_t i; diff --git a/lv_objx/lv_img.h b/lv_objx/lv_img.h index 86c2170b94..b1dd08d095 100644 --- a/lv_objx/lv_img.h +++ b/lv_objx/lv_img.h @@ -43,6 +43,9 @@ typedef struct lv_coord_t w; /*Width of the image (Handled by the library)*/ lv_coord_t h; /*Height of the image (Handled by the library)*/ +#if USE_LV_MULTI_LANG + uint16_t lang_txt_id; /*The ID of the image to display. */ +#endif uint8_t src_type :2; /*See: lv_img_src_t*/ uint8_t auto_size :1; /*1: automatically set the object size to the image size*/ uint8_t cf :5; /*Color format from `lv_img_color_format_t`*/ @@ -71,6 +74,14 @@ lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy); */ void lv_img_set_src(lv_obj_t * img, const void * src_img); +/** + * Set an ID which means a the same source but on different languages + * @param img pointer to an image object + * @param src_id ID of the source + */ +void lv_img_set_src_multi(lv_obj_t * img, uint32_t txt_id); + + /** * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0. * Use 'lv_img_set_src()' instead. diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index ab5e8efc31..7be7cd6a20 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -70,7 +70,7 @@ typedef struct #endif #if USE_LV_MULTI_LANG - uint16_t lang_txt_id; /*The ID of the text to to display*/ + uint16_t lang_txt_id; /*The ID of the text to display*/ #endif uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/ uint16_t anim_speed; /*Speed of scroll and roll animation in px/sec unit*/ @@ -123,14 +123,13 @@ void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size */ void lv_label_set_static_text(lv_obj_t * label, const char * text); - - /** *Set a text ID which means a the same text but on different languages * @param label pointer to a label object * @param txt_id ID of the text */ void lv_label_set_text_lang(lv_obj_t * label, uint32_t txt_id); + /** * Set the behavior of the label with longer text then the object size * @param label pointer to a label object