1 #include "../../lv_examples.h"
2 #if LV_USE_TEXTAREA && LV_BUILD_EXAMPLES
3
textarea_event_handler(lv_event_t * e)4 static void textarea_event_handler(lv_event_t * e)
5 {
6 lv_obj_t * ta = lv_event_get_target(e);
7 LV_UNUSED(ta);
8 LV_LOG_USER("Enter was pressed. The current text is: %s", lv_textarea_get_text(ta));
9 }
10
btnm_event_handler(lv_event_t * e)11 static void btnm_event_handler(lv_event_t * e)
12 {
13 lv_obj_t * obj = lv_event_get_target(e);
14 lv_obj_t * ta = lv_event_get_user_data(e);
15 const char * txt = lv_buttonmatrix_get_button_text(obj, lv_buttonmatrix_get_selected_button(obj));
16
17 if(lv_strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) lv_textarea_delete_char(ta);
18 else if(lv_strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_obj_send_event(ta, LV_EVENT_READY, NULL);
19 else lv_textarea_add_text(ta, txt);
20
21 }
22
lv_example_textarea_1(void)23 void lv_example_textarea_1(void)
24 {
25 lv_obj_t * ta = lv_textarea_create(lv_screen_active());
26 lv_textarea_set_one_line(ta, true);
27 lv_obj_align(ta, LV_ALIGN_TOP_MID, 0, 10);
28 lv_obj_add_event_cb(ta, textarea_event_handler, LV_EVENT_READY, ta);
29 lv_obj_add_state(ta, LV_STATE_FOCUSED); /*To be sure the cursor is visible*/
30
31 static const char * btnm_map[] = {"1", "2", "3", "\n",
32 "4", "5", "6", "\n",
33 "7", "8", "9", "\n",
34 LV_SYMBOL_BACKSPACE, "0", LV_SYMBOL_NEW_LINE, ""
35 };
36
37 lv_obj_t * btnm = lv_buttonmatrix_create(lv_screen_active());
38 lv_obj_set_size(btnm, 200, 150);
39 lv_obj_align(btnm, LV_ALIGN_BOTTOM_MID, 0, -10);
40 lv_obj_add_event_cb(btnm, btnm_event_handler, LV_EVENT_VALUE_CHANGED, ta);
41 lv_obj_remove_flag(btnm, LV_OBJ_FLAG_CLICK_FOCUSABLE); /*To keep the text area focused on button clicks*/
42 lv_buttonmatrix_set_map(btnm, btnm_map);
43 }
44
45 #endif
46