1 #include "../../lv_examples.h"
2 #if LV_USE_LABEL && LV_USE_TEXTAREA && LV_FONT_SIMSUN_16_CJK && LV_USE_IME_PINYIN && 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_CANCEL) {
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_1(void)23 void lv_example_ime_pinyin_1(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_ime_pinyin_set_keyboard(pinyin_ime, kb);
38 lv_keyboard_set_textarea(kb, ta1);
39
40 lv_obj_add_event_cb(ta1, ta_event_cb, LV_EVENT_ALL, kb);
41
42 /*Get the cand_panel, and adjust its size and position*/
43 lv_obj_t * cand_panel = lv_ime_pinyin_get_cand_panel(pinyin_ime);
44 lv_obj_set_size(cand_panel, LV_PCT(100), LV_PCT(10));
45 lv_obj_align_to(cand_panel, kb, LV_ALIGN_OUT_TOP_MID, 0, 0);
46
47 /*Try using ime_pinyin to output the Chinese below in the ta1 above*/
48 lv_obj_t * cz_label = lv_label_create(lv_scr_act());
49 lv_label_set_text(cz_label,
50 "嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。");
51 lv_obj_set_style_text_font(cz_label, &lv_font_simsun_16_cjk, 0);
52 lv_obj_set_width(cz_label, 310);
53 lv_obj_align_to(cz_label, ta1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
54 }
55
56 #endif
57