feat(ime_pinyin): add API to use Pinyin IME(Chinese input) (#3408)

* feat(pinyin_ime): add API to use Pinyin IME(Chinese input)

1.Low resource usage
2.Support custom thesaurus
3.Support custom styles (Candidate panel, keyboard)
4.Support simple spelling

* fix(ime_pinyin): fix several problems of ime_pinyin

1. Change lv_pinyin_ime to lv_ime_pinyin
2. Add lv_pinyin_ime_set_keyboard interface
3. Add lv_ime_pinyin configuration in Kconfig, src/lv_conf_internal.h

* refactor(ime_pinyin): improve coding specification

* feat(ime_pinyin): add simple Pinyin IME example

* docs(ime_pinyin): Add ime_pinyin documentation

* Delete settings.json

* Update dictionary based on simsun

* Delete lv_font_source_han_sans_normal_16.c

* Update lv_example_ime_pinyin_1.c

* Update ime_pinyin.md

add Chinese translation document

* Update lv_ime_pinyin.c

* Update lv_ime_pinyin.c

* Update lv_ime_pinyin.h

* Update lv_ime_pinyin.c

* Update lv_example_ime_pinyin_1.c

* Update lv_conf_internal.h

* Update lv_ime_pinyin.c

* Update lv_ime_pinyin.c

Co-authored-by: 100askTeam <team100ask@outlook.com>
This commit is contained in:
Yobe Zhou
2022-06-24 20:38:24 +08:00
committed by GitHub
parent 4056a15ecc
commit 92f1f9c0cc
13 changed files with 1241 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
Simple Pinyin IME example
"""""""""""""""""""
.. lv_example:: others/ime/lv_example_ime_pinyin_1
:language: c

View File

@@ -0,0 +1,38 @@
/**
* @file lv_example_ime_pinyin.h
*
*/
#ifndef LV_EX_IME_PINYIN_H
#define LV_EX_IME_PINYIN_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_example_ime_pinyin_1(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_EX_IME_PINYIN_H*/

View File

@@ -0,0 +1,56 @@
#include "../../lv_examples.h"
#if LV_USE_LABEL && LV_USE_TEXTAREA && LV_FONT_SIMSUN_16_CJK && LV_USE_IME_PINYIN && LV_BUILD_EXAMPLES
static void ta_event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * ta = lv_event_get_target(e);
lv_obj_t * kb = lv_event_get_user_data(e);
if(code == LV_EVENT_FOCUSED) {
if(lv_indev_get_type(lv_indev_get_act()) != LV_INDEV_TYPE_KEYPAD) {
lv_keyboard_set_textarea(kb, ta);
lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
}
}
else if(code == LV_EVENT_READY || code == LV_EVENT_CANCEL) {
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_state(ta, LV_STATE_FOCUSED);
lv_indev_reset(NULL, ta); /*To forget the last clicked object to make it focusable again*/
}
}
void lv_example_ime_pinyin_1(void)
{
lv_obj_t * pinyin_ime = lv_ime_pinyin_create(lv_scr_act());
lv_obj_set_style_text_font(pinyin_ime, &lv_font_simsun_16_cjk, 0);
//lv_ime_pinyin_set_dict(pinyin_ime, your_dict); // Use a custom dictionary. If it is not set, the built-in thesaurus will be used.
lv_obj_t * kb = lv_keyboard_create(lv_scr_act());
lv_ime_pinyin_set_keyboard(pinyin_ime, kb);
/* ta1 */
lv_obj_t * ta1 = lv_textarea_create(lv_scr_act());
lv_obj_set_style_text_font(ta1, &lv_font_simsun_16_cjk, 0);
lv_obj_align(ta1, LV_ALIGN_TOP_LEFT, 10, 10);
lv_keyboard_set_textarea(kb, ta1);
lv_obj_add_event_cb(ta1, ta_event_cb, LV_EVENT_ALL, kb);
/* ta2 */
lv_obj_t * ta2 = lv_textarea_create(lv_scr_act());
lv_obj_set_style_text_font(ta2, &lv_font_simsun_16_cjk, 0);
lv_obj_align_to(ta2, ta1, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
lv_obj_add_event_cb(ta2, ta_event_cb, LV_EVENT_ALL, kb);
lv_obj_t * cz_label = lv_label_create(lv_scr_act());
lv_label_set_text(cz_label,
"嵌入式系统Embedded System\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。");
lv_obj_set_style_text_font(cz_label, &lv_font_simsun_16_cjk, 0);
lv_obj_set_width(cz_label, 310);
lv_obj_align_to(cz_label, ta1, LV_ALIGN_OUT_BOTTOM_LEFT, 5, 5);
}
#endif

View File

@@ -19,6 +19,7 @@ extern "C" {
#include "fragment/lv_example_fragment.h"
#include "imgfont/lv_example_imgfont.h"
#include "msg/lv_example_msg.h"
#include "ime/lv_example_ime_pinyin.h"
/*********************
* DEFINES