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_3.c (1168B)

      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 /**
      9  * Automatically format text like a clock. E.g. "12:34"
     10  * Add the ':' automatically.
     11  */
     12 void lv_example_textarea_3(void)
     13 {
     14     /*Create the text area*/
     15     lv_obj_t * ta = lv_textarea_create(lv_scr_act());
     16     lv_obj_add_event_cb(ta, ta_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
     17     lv_textarea_set_accepted_chars(ta, "0123456789:");
     18     lv_textarea_set_max_length(ta, 5);
     19     lv_textarea_set_one_line(ta, true);
     20     lv_textarea_set_text(ta, "");
     21 
     22     /*Create a keyboard*/
     23     kb = lv_keyboard_create(lv_scr_act());
     24     lv_obj_set_size(kb,  LV_HOR_RES, LV_VER_RES / 2);
     25     lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUMBER);
     26     lv_keyboard_set_textarea(kb, ta);
     27 }
     28 
     29 static void ta_event_cb(lv_event_t * e)
     30 {
     31     lv_obj_t * ta = lv_event_get_target(e);
     32     const char * txt = lv_textarea_get_text(ta);
     33     if(txt[0] >= '0' && txt[0] <= '9' &&
     34        txt[1] >= '0' && txt[1] <= '9' &&
     35        txt[2] != ':') {
     36         lv_textarea_set_cursor_pos(ta, 2);
     37         lv_textarea_add_char(ta, ':');
     38     }
     39 }
     40 
     41 #endif