1 #include "../../../lv_examples.h"
2 #include <stdio.h>
3 #if LV_USE_TEXTAREA
5 lv_obj_t * ta1;
7 static void event_handler(lv_obj_t * obj, lv_event_t event)
9 if(event == LV_EVENT_VALUE_CHANGED) {
10 printf("Value: %s\n", lv_textarea_get_text(obj));
11 }
12 else if(event == LV_EVENT_LONG_PRESSED_REPEAT) {
13 /*For simple test: Long press the Text are to add the text below*/
14 const char * txt = "\n\nYou can scroll it if the text is long enough.\n";
15 static uint16_t i = 0;
16 if(txt[i] != '\0') {
17 lv_textarea_add_char(ta1, txt[i]);
18 i++;
19 }
20 }
21 }
23 void lv_ex_textarea_1(void)
24 {
25 ta1 = lv_textarea_create(lv_scr_act(), NULL);
26 lv_obj_set_size(ta1, 200, 100);
27 lv_obj_align(ta1, NULL, LV_ALIGN_CENTER, 0, 0);
28 lv_textarea_set_text(ta1, "A text in a Text Area"); /*Set an initial text*/
29 lv_obj_set_event_cb(ta1, event_handler);
30 }
32 #endif
1 #include "../../../lv_examples.h"
2 #include <stdio.h>
3 #if LV_USE_TEXTAREA && LV_USE_KEYBOARD
5 static void ta_event_cb(lv_obj_t * ta, lv_event_t event);
7 static lv_obj_t * kb;
9 void lv_ex_textarea_2(void)
10 {
11 /* Create the password box */
12 lv_obj_t * pwd_ta = lv_textarea_create(lv_scr_act(), NULL);
13 lv_textarea_set_text(pwd_ta, "");
14 lv_textarea_set_pwd_mode(pwd_ta, true);
15 lv_textarea_set_one_line(pwd_ta, true);
16 lv_textarea_set_cursor_hidden(pwd_ta, true);
17 lv_obj_set_width(pwd_ta, LV_HOR_RES / 2 - 20);
18 lv_obj_set_pos(pwd_ta, 5, 20);
19 lv_obj_set_event_cb(pwd_ta, ta_event_cb);
21 /* Create a label and position it above the text box */
22 lv_obj_t * pwd_label = lv_label_create(lv_scr_act(), NULL);
23 lv_label_set_text(pwd_label, "Password:");
24 lv_obj_align(pwd_label, pwd_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
26 /* Create the one-line mode text area */
27 lv_obj_t * oneline_ta = lv_textarea_create(lv_scr_act(), pwd_ta);
28 lv_textarea_set_pwd_mode(oneline_ta, false);
29 lv_textarea_set_cursor_hidden(oneline_ta, true);
30 lv_obj_align(oneline_ta, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 20);
33 /* Create a label and position it above the text box */
34 lv_obj_t * oneline_label = lv_label_create(lv_scr_act(), NULL);
35 lv_label_set_text(oneline_label, "Text:");
36 lv_obj_align(oneline_label, oneline_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
38 /* Create a keyboard */
39 kb = lv_keyboard_create(lv_scr_act(), NULL);
40 lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
42 lv_keyboard_set_textarea(kb, pwd_ta); /* Focus it on one of the text areas to start */
43 lv_keyboard_set_cursor_manage(kb, true); /* Automatically show/hide cursors on text areas */
44 }
46 static void ta_event_cb(lv_obj_t * ta, lv_event_t event)
47 {
48 if(event == LV_EVENT_CLICKED) {
49 /* Focus on the clicked text area */
50 if(kb != NULL)
51 lv_keyboard_set_textarea(kb, ta);
52 }
54 else if(event == LV_EVENT_INSERT) {
55 const char * str = lv_event_get_data();
56 if(str[0] == '\n') {
57 printf("Ready\n");
58 }
59 }
60 }
62 #endif
1 #include "../../../lv_examples.h"
2 #include <stdio.h>
3 #if LV_USE_TEXTAREA && LV_USE_KEYBOARD
5 static void ta_event_cb(lv_obj_t * ta, lv_event_t event);
7 static lv_obj_t * kb;
9 /**
10 * Automatically format text like a clock. E.g. "12:34"
11 * Add the ':' automatically.
12 */
13 void lv_ex_textarea_3(void)
14 {
15 /* Create the text area */
16 lv_obj_t * ta = lv_textarea_create(lv_scr_act(), NULL);
17 lv_obj_set_event_cb(ta, ta_event_cb);
18 lv_textarea_set_accepted_chars(ta, "0123456789:");
19 lv_textarea_set_max_length(ta, 5);
20 lv_textarea_set_one_line(ta, true);
21 lv_textarea_set_text(ta, "");
24 /*Create a custom map for the keyboard*/
26 static const char * kb_map[] = {
27 "1","2", "3", " ","\n",
28 "4", "5", "6", " ", "\n",
29 "7", "8", "9", LV_SYMBOL_BACKSPACE ,"\n",
30 "0",LV_SYMBOL_LEFT,LV_SYMBOL_RIGHT," ",""
31 };
33 static const lv_btnmatrix_ctrl_t kb_ctrl[] = {
34 LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_HIDDEN,
35 LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_HIDDEN,
36 LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT,
37 LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_NO_REPEAT, LV_BTNMATRIX_CTRL_HIDDEN,
38 };
40 /* Create a keyboard*/
41 kb = lv_keyboard_create(lv_scr_act(), NULL);
42 lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
43 lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUM);
44 lv_keyboard_set_map(kb, LV_KEYBOARD_MODE_NUM, kb_map);
45 lv_keyboard_set_ctrl_map(kb, LV_KEYBOARD_MODE_NUM,kb_ctrl);
46 lv_keyboard_set_textarea(kb, ta);
47 }
49 static void ta_event_cb(lv_obj_t * ta, lv_event_t event)
50 {
51 if(event == LV_EVENT_VALUE_CHANGED) {
52 const char * txt = lv_textarea_get_text(ta);
53 if(txt[3] == ':') {
54 lv_textarea_del_char(ta);
55 }
56 else if(txt[0] >= '0' && txt[0] <= '9' &&
57 txt[1] >= '0' && txt[1] <= '9' &&
58 txt[2] != ':')
59 {
60 lv_textarea_set_cursor_pos(ta, 2);
61 lv_textarea_add_char(ta, ':');
62 }
63 }
64 }
66 #endif