1 #include "../../lv_examples.h"
2 #if LV_USE_LABEL && LV_USE_TEXTAREA && LV_FONT_SIMSUN_16_CJK && LV_USE_IME_PINYIN && LV_IME_PINYIN_USE_K9_MODE && LV_BUILD_EXAMPLES
3
ta_event_cb(lv_event_t * e)4 static void ta_event_cb(lv_event_t * e)
5 {
6 lv_event_code_t code = lv_event_get_code(e);
7 lv_obj_t * ta = lv_event_get_target(e);
8 lv_obj_t * kb = lv_event_get_user_data(e);
9
10 if(code == LV_EVENT_FOCUSED) {
11 if(lv_indev_get_type(lv_indev_get_act()) != LV_INDEV_TYPE_KEYPAD) {
12 lv_keyboard_set_textarea(kb, ta);
13 lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
14 }
15 }
16 else if(code == LV_EVENT_READY) {
17 lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
18 lv_obj_clear_state(ta, LV_STATE_FOCUSED);
19 lv_indev_reset(NULL, ta); /*To forget the last clicked object to make it focusable again*/
20 }
21 }
22
lv_example_ime_pinyin_2(void)23 void lv_example_ime_pinyin_2(void)
24 {
25 lv_obj_t * pinyin_ime = lv_ime_pinyin_create(lv_scr_act());
26 lv_obj_set_style_text_font(pinyin_ime, &lv_font_simsun_16_cjk, 0);
27 //lv_ime_pinyin_set_dict(pinyin_ime, your_dict); // Use a custom dictionary. If it is not set, the built-in dictionary will be used.
28
29 /* ta1 */
30 lv_obj_t * ta1 = lv_textarea_create(lv_scr_act());
31 lv_textarea_set_one_line(ta1, true);
32 lv_obj_set_style_text_font(ta1, &lv_font_simsun_16_cjk, 0);
33 lv_obj_align(ta1, LV_ALIGN_TOP_LEFT, 0, 0);
34
35 /*Create a keyboard and add it to ime_pinyin*/
36 lv_obj_t * kb = lv_keyboard_create(lv_scr_act());
37 lv_keyboard_set_textarea(kb, ta1);
38
39 lv_ime_pinyin_set_keyboard(pinyin_ime, kb);
40 lv_ime_pinyin_set_mode(pinyin_ime,
41 LV_IME_PINYIN_MODE_K9); // Set to 9-key input mode. Default: 26-key input(k26) mode.
42 lv_obj_add_event_cb(ta1, ta_event_cb, LV_EVENT_ALL, kb);
43
44 /*Get the cand_panel, and adjust its size and position*/
45 lv_obj_t * cand_panel = lv_ime_pinyin_get_cand_panel(pinyin_ime);
46 lv_obj_set_size(cand_panel, LV_PCT(100), LV_PCT(10));
47 lv_obj_align_to(cand_panel, kb, LV_ALIGN_OUT_TOP_MID, 0, 0);
48
49 /*Try using ime_pinyin to output the Chinese below in the ta1 above*/
50 lv_obj_t * cz_label = lv_label_create(lv_scr_act());
51 lv_label_set_text(cz_label,
52 "嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。");
53 lv_obj_set_style_text_font(cz_label, &lv_font_simsun_16_cjk, 0);
54 lv_obj_set_width(cz_label, 310);
55 lv_obj_align_to(cz_label, ta1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
56 }
57
58 #endif
59