1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

fix conflicts

This commit is contained in:
Gabor Kiss-Vamosi 2019-02-25 06:59:31 +01:00
commit 663b8d6c89
11 changed files with 372 additions and 323 deletions

View File

@ -90,7 +90,11 @@
#define USE_LV_GROUP 1 /*1: Enable object groups (for keyboards)*/
#define USE_LV_GPU 1 /*1: Enable GPU interface*/
#define USE_LV_FILESYSTEM 1 /*1: Enable file system (might be required for images*/
<<<<<<< HEAD
#define USE_LV_I18N 1 /*1: Enable InternationalizatioN (multi-language) support*/
=======
#define USE_LV_I18N 0 /*1: Enable InternationalizatioN (multi-language) support*/
>>>>>>> i18n
/*Compiler settings*/
#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to `lv_tick_inc` function */

256
lv_core/lv_i18n.c Normal file
View File

@ -0,0 +1,256 @@
/**
* @file lv_i18n.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_i18n.h"
#if USE_LV_I18N
#include "lv_obj.h"
#include "../lv_misc/lv_gc.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static const void * lv_i18n_get_text_core(const lv_i18n_trans_t * trans, const char * msg_id);
/**********************
* STATIC VARIABLES
**********************/
static const lv_i18n_lang_pack_t * languages;
static const lv_i18n_lang_t * local_lang;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Set the languages for internationalization
* @param langs pointer to the array of languages. (Last element has to be `NULL`)
* @return 0: no error; < 0: error
*/
int lv_i18n_init(const lv_i18n_lang_pack_t * langs)
{
if(langs == NULL) {
LV_LOG_WARN("lv_i18n_init: `langs` can't be NULL");
return -1;
}
if(langs[0] == NULL) {
LV_LOG_WARN("lv_i18n_init: `langs` need to contain at least one translation");
return -1;
}
languages = langs;
local_lang = langs[0]; /*Automatically select the first language*/
return 0;
}
/**
* Change the localization (language)
* @param lang_code name of the translation to use. E.g. "en_GB"
* @return 0: no error; < 0: error
*/
int lv_i18n_set_local(const char * lang_code)
{
if(languages == NULL) {
LV_LOG_WARN("lv_i18n_set_local: The languages are not set with lv_i18n_init() yet");
return -1;
}
uint16_t i;
for(i = 0; languages[i] != NULL; i++) {
if(strcmp(languages[i]->name, lang_code) == 0) break; /*A language has found*/
}
/*The language wasn't found*/
if(languages[i] == NULL) {
LV_LOG_WARN("lv_i18n_set_local: The selected language doesn't found");
return -1;
}
local_lang = languages[i];
LV_LOG_INFO("lv_i18n_set_local: new local selected")
return 0;
}
/**
* Get the translation from a message ID
* @param msg_id message ID
* @return the translation of `msg_id` on the set local
*/
const void * lv_i18n_get_text(const char * msg_id)
{
if(local_lang == NULL) {
LV_LOG_WARN("lv_i18n_get_text: No language selected");
return msg_id;
}
const lv_i18n_lang_t * lang = local_lang;
if(lang->simple == NULL) {
if(lang == languages[0]) {
LV_LOG_WARN("lv_i18n_get_text: No translations are specified even on the default language.");
return msg_id;
} else {
LV_LOG_WARN("lv_i18n_get_text: No translations are specified on the current local. Fallback to the default language");
lang = languages[0];
}
if(lang->simple == NULL) {
LV_LOG_WARN("lv_i18n_get_text: No translations are specified even on the default language.");
return msg_id;
}
}
/*Find the translation*/
const void * txt = lv_i18n_get_text_core(lang->simple, msg_id);
if(txt == NULL) {
if(lang == languages[0]) {
LV_LOG_WARN("lv_i18n_get_text: No translation found even on the default language");
return msg_id;
} else {
LV_LOG_WARN("lv_i18n_get_text: No translation found on this language. Fallback to the default language");
lang = languages[0];
}
}
/*Try again with the default language*/
if(lang->simple == NULL) {
LV_LOG_WARN("lv_i18n_get_text: No translations are specified even on the default language.");
return msg_id;
}
txt = lv_i18n_get_text_core(lang->simple, msg_id);
if(txt == NULL) {
LV_LOG_WARN("lv_i18n_get_text: No translation found even on the default language");
return msg_id;
}
return txt;
}
/**
* Get the translation from a message ID and apply the language's plural rule to get correct form
* @param msg_id message ID
* @param num an integer to select the correct plural form
* @return the translation of `msg_id` on the set local
*/
const void * lv_i18n_get_text_plural(const char * msg_id, int32_t num)
{
if(local_lang == NULL) {
LV_LOG_WARN("lv_i18n_get_text_plural: No language selected");
return msg_id;
}
const lv_i18n_lang_t * lang = local_lang;
if(lang->plurals == NULL || lang->plural_rule == NULL) {
if(lang == languages[0]) {
LV_LOG_WARN("lv_i18n_get_text_plural: No plurals or plural rule has defined even on the default language");
return msg_id;
} else {
LV_LOG_WARN("lv_i18n_get_text_plural: o plurals or plural rule has defined for the language. Fallback to the default language");
lang = languages[0];
}
if(lang->plurals == NULL) {
LV_LOG_WARN("lv_i18n_get_text_plural: o plurals or plural rule has defined even on the default language");
return msg_id;
}
}
lv_i18n_plural_type_t ptype = lang->plural_rule(num);
if(lang->plurals[ptype] == NULL) {
if(lang == languages[0]) {
LV_LOG_WARN("lv_i18n_get_text_plural: No translations of the required plural form even on the default language.");
return msg_id;
} else {
LV_LOG_WARN("lv_i18n_get_text_plural:No translations of the required plural form for the language. Fallback to the default language");
lang = languages[0];
}
}
/*Find the translation*/
const void * txt = lv_i18n_get_text_core(lang->plurals[ptype], msg_id);
if(txt == NULL) {
if(lang == languages[0]) {
LV_LOG_WARN("lv_i18n_get_text_plural: No translation found even on the default language");
return msg_id;
} else {
LV_LOG_WARN("lv_i18n_get_text_plural: No translation found on this language. Fallback to the default language");
lang = languages[0];
}
}
/*Try again with the default language*/
if(lang->plurals == NULL || lang->plural_rule == NULL) {
LV_LOG_WARN("lv_i18n_get_text_plural: No plurals or plural rule has defined even on the default language");
return msg_id;
}
ptype = lang->plural_rule(num);
if(lang->plurals[ptype] == NULL) {
LV_LOG_WARN("lv_i18n_get_text_plural: No translations of the required plural form even on the default language.");
return msg_id;
}
txt = lv_i18n_get_text_core(lang->plurals[ptype], msg_id);
if(txt == NULL) {
LV_LOG_WARN("lv_i18n_get_text_plural: No translation found even on the default language");
return msg_id;
}
return txt;
}
/**
* Get the name of the currently used localization.
* @return name of the currently used localization. E.g. "en_GB"
*/
const void * lv_i18n_get_current_local(void)
{
if(local_lang) return local_lang->name;
else return NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
static const void * lv_i18n_get_text_core(const lv_i18n_trans_t * trans, const char * msg_id)
{
uint16_t i;
for(i = 0; trans[i].msg_id != NULL; i++) {
if(strcmp(trans[i].msg_id, msg_id) == 0) {
/*The msg_id has found. Check the translation*/
if(trans[i].txt_trans) return trans[i].txt_trans;
}
}
LV_LOG_TRACE("lv_i18n_get_text_core: `msg_id` wasn't found");
return NULL;
}
#endif /*USE_LV_I18N*/

108
lv_core/lv_i18n.h Normal file
View File

@ -0,0 +1,108 @@
/**
* @file lv_lang.h
*
*/
#ifndef LV_I18N_H
#define LV_I18N_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#if USE_LV_I18N
#include <stdint.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef enum {
LV_I18N_PLURAL_TYPE_ZERO,
LV_I18N_PLURAL_TYPE_ONE,
LV_I18N_PLURAL_TYPE_TWO,
LV_I18N_PLURAL_TYPE_FEW,
LV_I18N_PLURAL_TYPE_MANY,
LV_I18N_PLURAL_TYPE_OTHER,
_LV_I18N_PLURAL_TYPE_NUM,
}lv_i18n_plural_type_t;
typedef struct {
const char * msg_id;
const char * txt_trans;
}lv_i18n_trans_t;
typedef struct {
const char * name; /*E.g. "en_GB"*/
const lv_i18n_trans_t * simple; /*Translations of simple texts where no plurals are used*/
const lv_i18n_trans_t * plurals[_LV_I18N_PLURAL_TYPE_NUM]; /*Translations of the plural forms*/
uint8_t (*plural_rule)(int32_t num); /*Function pointer to get the correct plural form for a number*/
}lv_i18n_lang_t;
typedef const lv_i18n_lang_t * lv_i18n_lang_pack_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Set the languages for internationalization
* @param langs pointer to the array of languages. (Last element has to be `NULL`)
* @return 0: no error; < 0: error
*/
int lv_i18n_init(const lv_i18n_lang_pack_t * langs);
/**
* Change the localization (language)
* @param lang_code name of the translation to use. E.g. "en_GB"
* @return 0: no error; < 0: error
*/
int lv_i18n_set_local(const char * lang_code);
/**
* Get the translation from a message ID
* @param msg_id message ID
* @return the translation of `msg_id` on the set local
*/
const void * lv_i18n_get_text(const char * msg_id);
/**
* Get the translation from a message ID and apply the language's plural rule to get correct form
* @param msg_id message ID
* @param num an integer to select the correct plural form
* @return the translation of `msg_id` on the set local
*/
const void * lv_i18n_get_text_plural(const char * msg_id, int32_t num);
/**
* Get the name of the currently used localization.
* @return name of the currently used localization. E.g. "en_GB"
*/
const void * lv_i18n_get_current_local(void);
/**********************
* MACROS
**********************/
#endif /*USE_LV_I18N*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_LANG_H*/

View File

@ -1,117 +0,0 @@
/**
* @file lv_lang.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_lang.h"
#if USE_LV_MULTI_LANG
#include "lv_obj.h"
#include "../lv_misc/lv_gc.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void lang_set_core(lv_obj_t * obj);
/**********************
* STATIC VARIABLES
**********************/
static uint8_t lang_act = 0;
static const void * (*get_txt)(uint16_t);
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Change the language
* @param lang_id the id of the
*/
void lv_lang_set(uint8_t lang_id)
{
lang_act = lang_id;
lv_obj_t * i;
LL_READ(LV_GC_ROOT(_lv_scr_ll), i) {
i->signal_func(i, LV_SIGNAL_LANG_CHG, NULL);
lang_set_core(i);
}
lang_set_core(lv_scr_act(NULL));
}
/**
* Set a function to get the texts of the set languages from a `txt_id`
* @param fp a function pointer to get the texts
*/
void lv_lang_set_text_func(const void * (*fp)(uint16_t))
{
get_txt = fp;
}
/**
* Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language
* @param txt_id an ID of the text to get
* @return the `txt_id` txt on the set language
*/
const void * lv_lang_get_text(uint16_t txt_id)
{
if(get_txt == NULL) {
LV_LOG_WARN("lv_lang_get_text: text_func is not specified");
return NULL; /*No text_get function specified */
}
if(txt_id == LV_LANG_TXT_ID_NONE) {
LV_LOG_WARN("lv_lang_get_text: attempts to get invalid text ID");
return NULL; /*Invalid txt_id*/
}
return get_txt(txt_id);
}
/**
* Return with ID of the currently selected language
* @return pointer to the active screen object (loaded by 'lv_scr_load()')
*/
uint8_t lv_lang_act(void)
{
return lang_act;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Change the language of the children. (Called recursively)
* @param obj pointer to an object
*/
static void lang_set_core(lv_obj_t * obj)
{
lv_obj_t * i;
LL_READ(obj->child_ll, i) {
i->signal_func(i, LV_SIGNAL_LANG_CHG, NULL);
lang_set_core(i);
}
}
#endif /*USE_LV_MULTI_LANG*/

View File

@ -1,74 +0,0 @@
/**
* @file lv_lang.h
*
*/
#ifndef LV_LANG_H
#define LV_LANG_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
#if USE_LV_MULTI_LANG
#include <stdint.h>
/*********************
* DEFINES
*********************/
#define LV_LANG_TXT_ID_NONE 0xFFFF /*Used to not assign any text IDs for a multi-language object.*/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Change the language
* @param lang_id the id of the
*/
void lv_lang_set(uint8_t lang_id);
/**
* Set a function to get the texts of the set languages from a `txt_id`
* @param fp a function pointer to get the texts
*/
void lv_lang_set_text_func(const void * (*fp)(uint16_t));
/**
* Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language
* @param txt_id an ID of the text to get
* @return the `txt_id` txt on the set language
*/
const void * lv_lang_get_text(uint16_t txt_id);
/**
* Return with ID of the currently selected language
* @return pointer to the active screen object (loaded by 'lv_scr_load()')
*/
uint8_t lv_lang_act(void);
/**********************
* MACROS
**********************/
#endif /*USE_LV_MULTI_LANG*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_LANG_H*/

View File

@ -80,7 +80,6 @@ enum
LV_SIGNAL_PARENT_SIZE_CHG,
LV_SIGNAL_STYLE_CHG,
LV_SIGNAL_REFR_EXT_SIZE,
LV_SIGNAL_LANG_CHG,
LV_SIGNAL_GET_TYPE,
_LV_SIGNAL_FEEDBACK_SECTION_START,

View File

@ -14,7 +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_core/lv_i18n.h"
#include "../lv_themes/lv_theme.h"
#include "../lv_misc/lv_fs.h"
#include "../lv_misc/lv_ufs.h"
@ -78,9 +78,6 @@ lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy)
ext->w = lv_obj_get_width(new_img);
ext->h = lv_obj_get_height(new_img);
ext->auto_size = 1;
#if USE_LV_MULTI_LANG
ext->lang_txt_id = LV_LANG_TXT_ID_NONE;
#endif
/*Init the new object*/
lv_obj_set_signal_func(new_img, lv_img_signal);
@ -206,22 +203,6 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img)
lv_obj_invalidate(img);
}
#if USE_LV_MULTI_LANG
/**
* Set an ID which means a the same source but in different languages
* @param img pointer to an image object
* @param src_id ID of the source
*/
void lv_img_set_src_id(lv_obj_t * img, uint32_t src_id)
{
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
ext->lang_txt_id = src_id;
/*Apply the new language*/
img->signal_func(img, LV_SIGNAL_LANG_CHG, NULL);
}
#endif
/**
* Enable the auto size feature.
* If enabled the object size will be same as the picture size.
@ -266,19 +247,6 @@ const char * lv_img_get_file_name(const lv_obj_t * img)
else return "";
}
#if USE_LV_MULTI_LANG
/**
* Get the source ID of the image. (Used by the multi-language feature)
* @param img pointer to an image
* @return ID of the source
*/
uint16_t lv_img_get_src_id(lv_obj_t * img)
{
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
return ext->lang_txt_id;
}
#endif
/**
* Get the auto size enable attribute
* @param img pointer to an image
@ -382,17 +350,6 @@ 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;

View File

@ -43,9 +43,6 @@ 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`*/
@ -74,15 +71,6 @@ 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);
#if USE_LV_MULTI_LANG
/**
* 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_id(lv_obj_t * img, uint32_t txt_id);
#endif
/**
* Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0.
* Use 'lv_img_set_src()' instead.
@ -142,15 +130,6 @@ const void * lv_img_get_src(lv_obj_t * img);
*/
const char * lv_img_get_file_name(const lv_obj_t * img);
#if USE_LV_MULTI_LANG
/**
* Get the source ID of the image. (Used by the multi-language feature)
* @param img pointer to an image
* @return ID of the source
*/
uint16_t lv_img_get_src_id(lv_obj_t * img);
#endif
/**
* Get the auto size enable attribute
* @param img pointer to an image

View File

@ -11,7 +11,7 @@
#include "../lv_core/lv_obj.h"
#include "../lv_core/lv_group.h"
#include "../lv_core/lv_lang.h"
#include "../lv_core/lv_i18n.h"
#include "../lv_draw/lv_draw.h"
#include "../lv_misc/lv_color.h"
#include "../lv_misc/lv_math.h"
@ -91,9 +91,6 @@ lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy)
ext->anim_speed = LV_LABEL_SCROLL_SPEED;
ext->offset.x = 0;
ext->offset.y = 0;
#if USE_LV_MULTI_LANG
ext->lang_txt_id = LV_LANG_TXT_ID_NONE;
#endif
lv_obj_set_design_func(new_label, lv_label_design);
lv_obj_set_signal_func(new_label, lv_label_signal);
@ -237,22 +234,6 @@ void lv_label_set_static_text(lv_obj_t * label, const char * text)
lv_label_refr_text(label);
}
#if USE_LV_MULTI_LANG
/**
*Set a text ID which refers a the same text but in a different languages
* @param label pointer to a label object
* @param txt_id ID of the text
*/
void lv_label_set_text_id(lv_obj_t * label, uint32_t txt_id)
{
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
ext->lang_txt_id = txt_id;
/*Apply the new language*/
label->signal_func(label, LV_SIGNAL_LANG_CHG, NULL);
}
#endif
/**
* Set the behavior of the label with longer text then the object size
* @param label pointer to a label object
@ -365,19 +346,6 @@ char * lv_label_get_text(const lv_obj_t * label)
return ext->text;
}
#if USE_LV_MULTI_LANG
/**
* Get the text ID of the label. (Used by the multi-language feature)
* @param label pointer to a label object
* @return ID of the text
*/
uint16_t lv_label_get_text_id(lv_obj_t * label)
{
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
return ext->lang_txt_id;
}
#endif
/**
* Get the long mode of a label
* @param label pointer to a label object
@ -753,17 +721,6 @@ static lv_res_t lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param
label->ext_size = LV_MATH_MAX(label->ext_size, style->body.padding.hor);
label->ext_size = LV_MATH_MAX(label->ext_size, style->body.padding.ver);
}
} 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_txt = lv_lang_get_text(ext->lang_txt_id);
if(lang_txt) {
lv_label_set_text(label, lang_txt);
} else {
LV_LOG_WARN("lv_lang_get_text return NULL for a label's text");
}
}
#endif
} else if(sign == LV_SIGNAL_GET_TYPE) {
lv_obj_type_t * buf = param;
uint8_t i;

View File

@ -69,9 +69,6 @@ typedef struct
char dot_tmp[LV_LABEL_DOT_NUM * 4 + 1]; /*Store the character which are replaced by dots (Handled by the library)*/
#endif
#if USE_LV_MULTI_LANG
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*/
lv_point_t offset; /*Text draw position offset*/
@ -123,15 +120,6 @@ 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
*/
#if USE_LV_MULTI_LANG
void lv_label_set_text_id(lv_obj_t * label, uint32_t txt_id);
#endif
/**
* Set the behavior of the label with longer text then the object size
* @param label pointer to a label object
@ -188,15 +176,6 @@ static inline void lv_label_set_style(lv_obj_t *label, lv_style_t *style)
*/
char * lv_label_get_text(const lv_obj_t * label);
#if USE_LV_MULTI_LANG
/**
* Get the text ID of the label. (Used by the multi-language feature)
* @param label pointer to a label object
* @return ID of the text
*/
uint16_t lv_label_get_text_id(lv_obj_t * label);
#endif
/**
* Get the long mode of a label
* @param label pointer to a label object

3
lvgl.h
View File

@ -23,7 +23,8 @@ extern "C" {
#include "lv_core/lv_obj.h"
#include "lv_core/lv_group.h"
#include "lv_core/lv_lang.h"
#include "lv_core/lv_i18n.h"
#include "lv_core/lv_refr.h"
#include "lv_core/lv_disp.h"