Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
12
sdk/lib/lvgl/examples/others/ime/index.rst
Normal file
12
sdk/lib/lvgl/examples/others/ime/index.rst
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
Pinyin IME 26 key input
|
||||
"""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/ime/lv_example_ime_pinyin_1
|
||||
:language: c
|
||||
|
||||
Pinyin IME 9 key input
|
||||
"""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/ime/lv_example_ime_pinyin_2
|
||||
:language: c
|
||||
39
sdk/lib/lvgl/examples/others/ime/lv_example_ime_pinyin.h
Normal file
39
sdk/lib/lvgl/examples/others/ime/lv_example_ime_pinyin.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @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);
|
||||
void lv_example_ime_pinyin_2(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EX_IME_PINYIN_H*/
|
||||
56
sdk/lib/lvgl/examples/others/ime/lv_example_ime_pinyin_1.c
Normal file
56
sdk/lib/lvgl/examples/others/ime/lv_example_ime_pinyin_1.c
Normal 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_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 dictionary will be used.
|
||||
|
||||
/* ta1 */
|
||||
lv_obj_t * ta1 = lv_textarea_create(lv_scr_act());
|
||||
lv_textarea_set_one_line(ta1, true);
|
||||
lv_obj_set_style_text_font(ta1, &lv_font_simsun_16_cjk, 0);
|
||||
lv_obj_align(ta1, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
|
||||
/*Create a keyboard and add it to ime_pinyin*/
|
||||
lv_obj_t * kb = lv_keyboard_create(lv_scr_act());
|
||||
lv_ime_pinyin_set_keyboard(pinyin_ime, kb);
|
||||
lv_keyboard_set_textarea(kb, ta1);
|
||||
|
||||
lv_obj_add_event_cb(ta1, ta_event_cb, LV_EVENT_ALL, kb);
|
||||
|
||||
/*Get the cand_panel, and adjust its size and position*/
|
||||
lv_obj_t * cand_panel = lv_ime_pinyin_get_cand_panel(pinyin_ime);
|
||||
lv_obj_set_size(cand_panel, LV_PCT(100), LV_PCT(10));
|
||||
lv_obj_align_to(cand_panel, kb, LV_ALIGN_OUT_TOP_MID, 0, 0);
|
||||
|
||||
/*Try using ime_pinyin to output the Chinese below in the ta1 above*/
|
||||
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, 0, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
50
sdk/lib/lvgl/examples/others/ime/lv_example_ime_pinyin_1.py
Normal file
50
sdk/lib/lvgl/examples/others/ime/lv_example_ime_pinyin_1.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import fs_driver
|
||||
|
||||
def ta_event_cb(e,kb):
|
||||
code = e.get_code()
|
||||
ta = e.get_target()
|
||||
|
||||
if code == lv.EVENT.FOCUSED:
|
||||
if lv.indev_get_act() != None and lv.indev_get_act().get_type() != lv.INDEV_TYPE.KEYPAD :
|
||||
kb.set_textarea(ta)
|
||||
kb.clear_flag(lv.obj.FLAG.HIDDEN)
|
||||
elif code == lv.EVENT.CANCEL:
|
||||
kb.add_flag(lv.obj.FLAG.HIDDEN)
|
||||
ta.clear_state(ta, LV_STATE_FOCUSED);
|
||||
lv.indev_reset(None, ta) # To forget the last clicked object to make it focusable again
|
||||
|
||||
fs_drv = lv.fs_drv_t()
|
||||
fs_driver.fs_register(fs_drv, 'S')
|
||||
font_simsun_16_cjk = lv.font_load("S:../../assets/font/lv_font_simsun_16_cjk.fnt")
|
||||
if font_simsun_16_cjk == None:
|
||||
print("Error when loading chinese font")
|
||||
|
||||
pinyin_ime = lv.ime_pinyin(lv.scr_act())
|
||||
pinyin_ime.set_style_text_font(font_simsun_16_cjk, 0)
|
||||
# pinyin_ime.pinyin_set_dict(your_dict) # Use a custom dictionary. If it is not set, the built-in dictionary will be used.
|
||||
|
||||
# ta1
|
||||
ta1 = lv.textarea(lv.scr_act())
|
||||
ta1.set_one_line(True)
|
||||
ta1.set_style_text_font(font_simsun_16_cjk, 0)
|
||||
ta1.align(lv.ALIGN.TOP_LEFT, 0, 0)
|
||||
|
||||
# Create a keyboard and add it to ime_pinyin
|
||||
kb = lv.keyboard(lv.scr_act())
|
||||
pinyin_ime.pinyin_set_keyboard(kb)
|
||||
kb.set_textarea(ta1)
|
||||
|
||||
ta1.add_event_cb(lambda evt: ta_event_cb(evt,kb), lv.EVENT.ALL, None)
|
||||
|
||||
# Get the cand_panel, and adjust its size and position
|
||||
cand_panel = pinyin_ime.pinyin_get_cand_panel()
|
||||
cand_panel.set_size(lv.pct(100), lv.pct(10))
|
||||
cand_panel.align_to(kb, lv.ALIGN.OUT_TOP_MID, 0, 0)
|
||||
|
||||
# Try using ime_pinyin to output the Chinese below in the ta1 above
|
||||
cz_label = lv.label(lv.scr_act())
|
||||
cz_label.set_text("嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。")
|
||||
cz_label.set_style_text_font(font_simsun_16_cjk, 0)
|
||||
cz_label.set_width(310)
|
||||
cz_label.align_to(ta1, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0)
|
||||
|
||||
58
sdk/lib/lvgl/examples/others/ime/lv_example_ime_pinyin_2.c
Normal file
58
sdk/lib/lvgl/examples/others/ime/lv_example_ime_pinyin_2.c
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "../../lv_examples.h"
|
||||
#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
|
||||
|
||||
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) {
|
||||
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_2(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 dictionary will be used.
|
||||
|
||||
/* ta1 */
|
||||
lv_obj_t * ta1 = lv_textarea_create(lv_scr_act());
|
||||
lv_textarea_set_one_line(ta1, true);
|
||||
lv_obj_set_style_text_font(ta1, &lv_font_simsun_16_cjk, 0);
|
||||
lv_obj_align(ta1, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
|
||||
/*Create a keyboard and add it to ime_pinyin*/
|
||||
lv_obj_t * kb = lv_keyboard_create(lv_scr_act());
|
||||
lv_keyboard_set_textarea(kb, ta1);
|
||||
|
||||
lv_ime_pinyin_set_keyboard(pinyin_ime, kb);
|
||||
lv_ime_pinyin_set_mode(pinyin_ime,
|
||||
LV_IME_PINYIN_MODE_K9); // Set to 9-key input mode. Default: 26-key input(k26) mode.
|
||||
lv_obj_add_event_cb(ta1, ta_event_cb, LV_EVENT_ALL, kb);
|
||||
|
||||
/*Get the cand_panel, and adjust its size and position*/
|
||||
lv_obj_t * cand_panel = lv_ime_pinyin_get_cand_panel(pinyin_ime);
|
||||
lv_obj_set_size(cand_panel, LV_PCT(100), LV_PCT(10));
|
||||
lv_obj_align_to(cand_panel, kb, LV_ALIGN_OUT_TOP_MID, 0, 0);
|
||||
|
||||
/*Try using ime_pinyin to output the Chinese below in the ta1 above*/
|
||||
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, 0, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
52
sdk/lib/lvgl/examples/others/ime/lv_example_ime_pinyin_2.py
Normal file
52
sdk/lib/lvgl/examples/others/ime/lv_example_ime_pinyin_2.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import fs_driver
|
||||
|
||||
def ta_event_cb(e,kb):
|
||||
code = e.get_code()
|
||||
ta = e.get_target()
|
||||
|
||||
if code == lv.EVENT.FOCUSED:
|
||||
if lv.indev_get_act() != None and lv.indev_get_act().get_type() != lv.INDEV_TYPE.KEYPAD :
|
||||
kb.set_textarea(ta)
|
||||
kb.clear_flag(lv.obj.FLAG.HIDDEN)
|
||||
elif code == lv.EVENT.READY:
|
||||
kb.add_flag(lv.obj.FLAG.HIDDEN)
|
||||
ta.clear_state(ta, LV_STATE_FOCUSED);
|
||||
lv.indev_reset(None, ta) # To forget the last clicked object to make it focusable again
|
||||
|
||||
fs_drv = lv.fs_drv_t()
|
||||
fs_driver.fs_register(fs_drv, 'S')
|
||||
font_simsun_16_cjk = lv.font_load("S:../../assets/font/lv_font_simsun_16_cjk.fnt")
|
||||
if font_simsun_16_cjk == None:
|
||||
print("Error when loading chinese font")
|
||||
|
||||
pinyin_ime = lv.ime_pinyin(lv.scr_act())
|
||||
pinyin_ime.set_style_text_font(font_simsun_16_cjk, 0)
|
||||
# pinyin_ime.pinyin_set_dict(your_dict) # Use a custom dictionary. If it is not set, the built-in dictionary will be used.
|
||||
|
||||
# ta1
|
||||
ta1 = lv.textarea(lv.scr_act())
|
||||
ta1.set_one_line(True)
|
||||
ta1.set_style_text_font(font_simsun_16_cjk, 0)
|
||||
ta1.align(lv.ALIGN.TOP_LEFT, 0, 0)
|
||||
|
||||
# Create a keyboard and add it to ime_pinyin
|
||||
kb = lv.keyboard(lv.scr_act())
|
||||
kb.set_textarea(ta1)
|
||||
|
||||
pinyin_ime.pinyin_set_keyboard(kb)
|
||||
pinyin_ime.pinyin_set_mode(lv.ime_pinyin.PINYIN_MODE.K9) # Set to 9-key input mode. Default: 26-key input(k26) mode.
|
||||
|
||||
ta1.add_event_cb(lambda evt: ta_event_cb(evt,kb), lv.EVENT.ALL, None)
|
||||
|
||||
# Get the cand_panel, and adjust its size and position
|
||||
cand_panel = pinyin_ime.pinyin_get_cand_panel()
|
||||
cand_panel.set_size(lv.pct(100), lv.pct(10))
|
||||
cand_panel.align_to(kb, lv.ALIGN.OUT_TOP_MID, 0, 0)
|
||||
|
||||
# Try using ime_pinyin to output the Chinese below in the ta1 above
|
||||
cz_label = lv.label(lv.scr_act())
|
||||
cz_label.set_text("嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。")
|
||||
cz_label.set_style_text_font(font_simsun_16_cjk, 0)
|
||||
cz_label.set_width(310)
|
||||
cz_label.align_to(ta1, lv.ALIGN.OUT_BOTTOM_LEFT, 0, 0)
|
||||
|
||||
Reference in New Issue
Block a user