让LVGL中文输入法(Let lvgl support Chinese input method)

中文
English

LVGL中文输入法插件

我将它称为插件,因为它是在 lv_keyboard 的基础上编写的一个自定义部件(我定义创建接口为: lv_100ask_keyboard_create(lv_obj_t *parent) ); ),它和 lv_keyboard 没有什么区别,只是新增了支持中文输入法(或者其他输入法)的功能。

这个插件框架在后续非常容易维护和拓展,现在只是最简单的版本,我正在编写更多的功能以及在不同平台上进行测试。相信在一个月之内能和大家分享源码,希望大家能喜欢我的项目!

演示视频:

仓库地址

  • Gitee: TODO
  • Github: TODO

LVGL Chinese input method plug-in

I call it a plug-in because it’s in Lv_ A custom part written on the basis of keyboard (I define the creation interface as lv_100ask_keyboard_create (lv_obj_t * parent)), It and LV_ Keyboard is no different, but it has added the function of supporting Chinese input method (or other input methods).
This plug-in framework is very easy to maintain and expand in the future. Now it is only the simplest version. I am writing more functions and testing on different platforms. I believe I can share the source code with you within one month. I hope you can like my project!

Demo video

Source code

  • Gitee: TODO
  • Github: TODO

why you don’t use Phonetic layout?

That’s a good idea. I’ll try it.

Make you new keyboard layouts like LV_KEYBOARD_MODE_TEXT_LOWER but some like LV_KEYBOARD_MODE_CH_LOWER

#define LV_KB_BTN(width) LV_BTNMATRIX_CTRL_POPOVER | width

static const char* default_kb_map_lc[] = { "1#", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", LV_SYMBOL_BACKSPACE, "\n",
                                                    "ABC", "a", "s", "d", "f", "g", "h", "j", "k", "l", LV_SYMBOL_NEW_LINE, "\n",
                                                    "_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n",
                                                    LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""
};

static const lv_btnmatrix_ctrl_t default_kb_ctrl_lc_map[] = {
    LV_KEYBOARD_CTRL_BTN_FLAGS | 5, LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_KB_BTN(4), LV_BTNMATRIX_CTRL_CHECKED | 7,
    LV_KEYBOARD_CTRL_BTN_FLAGS | 6, LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_KB_BTN(3), LV_BTNMATRIX_CTRL_CHECKED | 7,
    LV_BTNMATRIX_CTRL_CHECKED | LV_KB_BTN(1), LV_BTNMATRIX_CTRL_CHECKED | LV_KB_BTN(1), LV_KB_BTN(1), LV_KB_BTN(1), LV_KB_BTN(1), LV_KB_BTN(1), LV_KB_BTN(1), LV_KB_BTN(1), LV_KB_BTN(1), LV_BTNMATRIX_CTRL_CHECKED | LV_KB_BTN(1), LV_BTNMATRIX_CTRL_CHECKED | LV_KB_BTN(1), LV_BTNMATRIX_CTRL_CHECKED | LV_KB_BTN(1),
    LV_BTNMATRIX_CTRL_CHECKED | 2, 6, LV_BTNMATRIX_CTRL_CHECKED | 2, LV_KEYBOARD_CTRL_BTN_FLAGS | 2
};
lv_keyboard_set_map(keyboard, LV_KEYBOARD_MODE_TEXT_LOWER, default_kb_map_lc, default_kb_ctrl_lc_map);

aaaaa
这个现在能在ESP32上使用吗?中文字体可以更换吗?

FYI, Chinese input is now also supported in NXP GUI Guider from version 1.3.0.

1 Like

Thank you for your message. What you said should support Chinese display? I didn’t find a function to support Chinese input

主要是看字库和词库的大小,只要开发板资源足够都能显示,字体可以任意切换,我这几天正在将他上传到github仓库

代码已经上传到git仓库,欢迎一起学习交流!
github: https://github.com/100askTeam/lv_chinese_ime
gitee: https://gitee.com/weidongshan/lv_chinese_ime

The code has been uploaded to github. Welcome to discuss it together :grinning:

github: https://github.com/100askTeam/lv_chinese_ime

github: https://github.com/100askTeam/lv_chinese_ime

gitee: lv_chinese_ime: lv_chinese_ime:支持中文输入法的LVGL键盘部件增强插件。lv_chinese_ime: LVGL keyboard widget enhancement plugin that supports Chinese input method.

可以,但是我发现这个输入法现在切换还有点问题,只能中文切换到大写字母,切回小写字母直接就是拼音模式了。

默认的字体 lv_font_source_han_sans_normal_16.c 不能显示空格, 需要把

static const lv_font_fmt_txt_cmap_t cmaps[] =

.range_start = 33, .range_length = 94, .glyph_id_start = 2,

改为:

.range_start = 32, .range_length = 95, .glyph_id_start = 1,

Hello, @kisvegabor , I can reproduce this problem with LVGL 8.3.3.
The default Chinese font lv_font_source_han_sans_normal_16 cannot show space ’ ’ correctly. Need to change this line:

.range_start = 33, .range_length = 94, .glyph_id_start = 2,

to

.range_start = 32, .range_length = 95, .glyph_id_start = 1,

Can you please update it ?

将 lv_ime_pinyin 加入到 lv_kb 组件中之后不能再切回到英文大小写字母输入模式,如果需要输入英文大小写字母可以在输入之后点击回车键输入;或者直接先将 lv_ime_pinyin 移出 lv_kb 输入待输入完成之后再加入 lv_ime_pinyin ,这是 lv_ime_pinyin 下一个要做的功能(可切回到英文大小写字母输入模式)。

lv_ime_pinyin 示例使用的是 lvgl 库内置的 lv_font_simsun_16_cjk 字体,在 lv_conf.h 中配置 LV_FONT_SIMSUN_16_CJK 使用。lvgl库本身没有内置 lv_font_source_han_sans_normal_16 字体,如果你使用自定义的字体出现问题请检查字体本身以及转换步骤是否有问题。

使用lvgl内置的 lv_font_simsun_16_cjk 字体只是用于演示效果,其本身只是收录了1000 个最常见的 CJK 部首,实际使用建议使用自定义字体以及词库,参考文档: https://docs.lvgl.io/master/others/ime_pinyin.html#usage

当然都可以,现在已经合并到lvgl主仓库并命名为 lv_ime_pinyin 更换字库(字体)操作 lv_kb 本身即可,比如:

lv_style_set_text_font(&my_style, &my_font_name);  /*Set a larger font*/

参考文档: https://docs.lvgl.io/master/overview/font.html

Sorry, I wrongly think the lv_font_source_han_sans_normal_16.c is a repo file. Actually it is copied to the font folder by myself.