init Files
This commit is contained in:
14
libraries/lvgl/examples/widgets/keyboard/index.rst
Normal file
14
libraries/lvgl/examples/widgets/keyboard/index.rst
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
Keyboard with text area
|
||||
-----------------------
|
||||
|
||||
.. lv_example:: widgets/keyboard/lv_example_keyboard_1
|
||||
:language: c
|
||||
|
||||
|
||||
Keyboard with custom map
|
||||
------------------------
|
||||
|
||||
.. lv_example:: widgets/keyboard/lv_example_keyboard_2
|
||||
:language: c
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_KEYBOARD && 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) {
|
||||
lv_keyboard_set_textarea(kb, ta);
|
||||
lv_obj_remove_flag(kb, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
if(code == LV_EVENT_DEFOCUSED) {
|
||||
lv_keyboard_set_textarea(kb, NULL);
|
||||
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_keyboard_1(void)
|
||||
{
|
||||
/*Create a keyboard to use it with an of the text areas*/
|
||||
lv_obj_t * kb = lv_keyboard_create(lv_screen_active());
|
||||
|
||||
/*Create a text area. The keyboard will write here*/
|
||||
lv_obj_t * ta1;
|
||||
ta1 = lv_textarea_create(lv_screen_active());
|
||||
lv_obj_align(ta1, LV_ALIGN_TOP_LEFT, 10, 10);
|
||||
lv_obj_add_event_cb(ta1, ta_event_cb, LV_EVENT_ALL, kb);
|
||||
lv_textarea_set_placeholder_text(ta1, "Hello");
|
||||
lv_obj_set_size(ta1, 140, 80);
|
||||
|
||||
lv_obj_t * ta2;
|
||||
ta2 = lv_textarea_create(lv_screen_active());
|
||||
lv_obj_align(ta2, LV_ALIGN_TOP_RIGHT, -10, 10);
|
||||
lv_obj_add_event_cb(ta2, ta_event_cb, LV_EVENT_ALL, kb);
|
||||
lv_obj_set_size(ta2, 140, 80);
|
||||
|
||||
lv_keyboard_set_textarea(kb, ta1);
|
||||
|
||||
/*The keyboard will show Arabic characters if they are enabled */
|
||||
#if LV_USE_ARABIC_PERSIAN_CHARS && LV_FONT_DEJAVU_16_PERSIAN_HEBREW
|
||||
lv_obj_set_style_text_font(kb, &lv_font_dejavu_16_persian_hebrew, 0);
|
||||
lv_obj_set_style_text_font(ta1, &lv_font_dejavu_16_persian_hebrew, 0);
|
||||
lv_obj_set_style_text_font(ta2, &lv_font_dejavu_16_persian_hebrew, 0);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_KEYBOARD && LV_BUILD_EXAMPLES
|
||||
|
||||
void lv_example_keyboard_2(void)
|
||||
{
|
||||
/*Create an AZERTY keyboard map*/
|
||||
static const char * kb_map[] = {"A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", LV_SYMBOL_BACKSPACE, "\n",
|
||||
"Q", "S", "D", "F", "G", "J", "K", "L", "M", LV_SYMBOL_NEW_LINE, "\n",
|
||||
"W", "X", "C", "V", "B", "N", ",", ".", ":", "!", "?", "\n",
|
||||
LV_SYMBOL_CLOSE, " ", " ", " ", LV_SYMBOL_OK, NULL
|
||||
};
|
||||
|
||||
/*Set the relative width of the buttons and other controls*/
|
||||
static const lv_buttonmatrix_ctrl_t kb_ctrl[] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
2, LV_BUTTONMATRIX_CTRL_HIDDEN | 2, 6, LV_BUTTONMATRIX_CTRL_HIDDEN | 2, 2
|
||||
};
|
||||
|
||||
/*Create a keyboard and add the new map as USER_1 mode*/
|
||||
lv_obj_t * kb = lv_keyboard_create(lv_screen_active());
|
||||
|
||||
lv_keyboard_set_map(kb, LV_KEYBOARD_MODE_USER_1, kb_map, kb_ctrl);
|
||||
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_USER_1);
|
||||
|
||||
/*Create a text area. The keyboard will write here*/
|
||||
lv_obj_t * ta;
|
||||
ta = lv_textarea_create(lv_screen_active());
|
||||
lv_obj_align(ta, LV_ALIGN_TOP_MID, 0, 10);
|
||||
lv_obj_set_size(ta, lv_pct(90), 80);
|
||||
lv_obj_add_state(ta, LV_STATE_FOCUSED);
|
||||
|
||||
lv_keyboard_set_textarea(kb, ta);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user