2021-04-08 13:07:48 +02:00
|
|
|
#include "../../lv_examples.h"
|
2021-02-14 14:56:34 +01:00
|
|
|
#if LV_USE_TEXTAREA && LV_USE_KEYBOARD && LV_BUILD_EXAMPLES
|
|
|
|
|
2021-04-14 15:31:54 +02:00
|
|
|
static void ta_event_cb(lv_event_t * e);
|
2021-02-14 14:56:34 +01:00
|
|
|
|
|
|
|
static lv_obj_t * kb;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Automatically format text like a clock. E.g. "12:34"
|
|
|
|
* Add the ':' automatically.
|
|
|
|
*/
|
|
|
|
void lv_example_textarea_3(void)
|
|
|
|
{
|
2021-03-15 02:03:27 +08:00
|
|
|
/*Create the text area*/
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * ta = lv_textarea_create(lv_scr_act());
|
2021-02-14 14:56:34 +01:00
|
|
|
lv_obj_add_event_cb(ta, ta_event_cb, NULL);
|
|
|
|
lv_textarea_set_accepted_chars(ta, "0123456789:");
|
|
|
|
lv_textarea_set_max_length(ta, 5);
|
|
|
|
lv_textarea_set_one_line(ta, true);
|
|
|
|
lv_textarea_set_text(ta, "");
|
|
|
|
|
2021-03-15 02:03:27 +08:00
|
|
|
/*Create a keyboard*/
|
2021-02-14 14:56:34 +01:00
|
|
|
kb = lv_keyboard_create(lv_scr_act());
|
|
|
|
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
|
|
|
|
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUMBER);
|
|
|
|
lv_keyboard_set_textarea(kb, ta);
|
|
|
|
}
|
|
|
|
|
2021-04-14 15:31:54 +02:00
|
|
|
static void ta_event_cb(lv_event_t * e)
|
2021-02-14 14:56:34 +01:00
|
|
|
{
|
2021-04-14 15:31:54 +02:00
|
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
|
|
lv_obj_t * ta = lv_event_get_target(e);
|
|
|
|
if(code == LV_EVENT_VALUE_CHANGED) {
|
2021-02-14 14:56:34 +01:00
|
|
|
const char * txt = lv_textarea_get_text(ta);
|
|
|
|
if(txt[0] >= '0' && txt[0] <= '9' &&
|
|
|
|
txt[1] >= '0' && txt[1] <= '9' &&
|
|
|
|
txt[2] != ':')
|
|
|
|
{
|
|
|
|
lv_textarea_set_cursor_pos(ta, 2);
|
|
|
|
lv_textarea_add_char(ta, ':');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|