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_2.c (2046B)

      1 #include "../../lv_examples.h"
      2 #if LV_USE_TEXTAREA && LV_USE_KEYBOARD && LV_BUILD_EXAMPLES
      3 
      4 static void ta_event_cb(lv_event_t * e);
      5 
      6 static lv_obj_t * kb;
      7 
      8 void lv_example_textarea_2(void)
      9 {
     10     /*Create the password box*/
     11     lv_obj_t * pwd_ta = lv_textarea_create(lv_scr_act());
     12     lv_textarea_set_text(pwd_ta, "");
     13     lv_textarea_set_password_mode(pwd_ta, true);
     14     lv_textarea_set_one_line(pwd_ta, true);
     15     lv_obj_set_width(pwd_ta, lv_pct(40));
     16     lv_obj_set_pos(pwd_ta, 5, 20);
     17     lv_obj_add_event_cb(pwd_ta, ta_event_cb, LV_EVENT_ALL, NULL);
     18 
     19     /*Create a label and position it above the text box*/
     20     lv_obj_t * pwd_label = lv_label_create(lv_scr_act());
     21     lv_label_set_text(pwd_label, "Password:");
     22     lv_obj_align_to(pwd_label, pwd_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
     23 
     24     /*Create the one-line mode text area*/
     25     lv_obj_t * text_ta = lv_textarea_create(lv_scr_act());
     26     lv_textarea_set_one_line(text_ta, true);
     27     lv_textarea_set_password_mode(text_ta, false);
     28     lv_obj_set_width(text_ta, lv_pct(40));
     29     lv_obj_add_event_cb(text_ta, ta_event_cb, LV_EVENT_ALL, NULL);
     30     lv_obj_align(text_ta, LV_ALIGN_TOP_RIGHT, -5, 20);
     31 
     32 
     33     /*Create a label and position it above the text box*/
     34     lv_obj_t * oneline_label = lv_label_create(lv_scr_act());
     35     lv_label_set_text(oneline_label, "Text:");
     36     lv_obj_align_to(oneline_label, text_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
     37 
     38     /*Create a keyboard*/
     39     kb = lv_keyboard_create(lv_scr_act());
     40     lv_obj_set_size(kb,  LV_HOR_RES, LV_VER_RES / 2);
     41 
     42     lv_keyboard_set_textarea(kb, pwd_ta); /*Focus it on one of the text areas to start*/
     43 }
     44 
     45 static void ta_event_cb(lv_event_t * e)
     46 {
     47     lv_event_code_t code = lv_event_get_code(e);
     48     lv_obj_t * ta = lv_event_get_target(e);
     49     if(code == LV_EVENT_CLICKED || code == LV_EVENT_FOCUSED) {
     50         /*Focus on the clicked text area*/
     51         if(kb != NULL) lv_keyboard_set_textarea(kb, ta);
     52     }
     53 
     54     else if(code == LV_EVENT_READY) {
     55         LV_LOG_USER("Ready, current text: %s", lv_textarea_get_text(ta));
     56     }
     57 }
     58 
     59 #endif