acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_textarea_1.c (1725B)

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