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;
|
|
|
|
|
|
|
|
void lv_example_textarea_2(void)
|
|
|
|
{
|
2021-03-15 02:03:27 +08:00
|
|
|
/*Create the password box*/
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * pwd_ta = lv_textarea_create(lv_scr_act());
|
2021-02-14 14:56:34 +01:00
|
|
|
lv_textarea_set_text(pwd_ta, "");
|
2021-02-27 22:19:58 +01:00
|
|
|
lv_textarea_set_password_mode(pwd_ta, true);
|
2021-02-14 14:56:34 +01:00
|
|
|
lv_textarea_set_one_line(pwd_ta, true);
|
2021-05-13 16:13:47 +02:00
|
|
|
lv_obj_set_width(pwd_ta, lv_pct(40));
|
2021-02-14 14:56:34 +01:00
|
|
|
lv_obj_set_pos(pwd_ta, 5, 20);
|
2021-04-19 11:15:28 +02:00
|
|
|
lv_obj_add_event_cb(pwd_ta, ta_event_cb, LV_EVENT_ALL, NULL);
|
2021-02-14 14:56:34 +01:00
|
|
|
|
2021-03-15 02:03:27 +08:00
|
|
|
/*Create a label and position it above the text box*/
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * pwd_label = lv_label_create(lv_scr_act());
|
2021-02-14 14:56:34 +01:00
|
|
|
lv_label_set_text(pwd_label, "Password:");
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align_to(pwd_label, pwd_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
|
2021-02-14 14:56:34 +01:00
|
|
|
|
2021-03-15 02:03:27 +08:00
|
|
|
/*Create the one-line mode text area*/
|
2021-05-11 13:18:27 +02:00
|
|
|
lv_obj_t * text_ta = lv_textarea_create(lv_scr_act());
|
|
|
|
lv_textarea_set_one_line(text_ta, true);
|
|
|
|
lv_textarea_set_password_mode(text_ta, false);
|
2021-05-13 16:13:47 +02:00
|
|
|
lv_obj_set_width(text_ta, lv_pct(40));
|
2021-05-11 13:18:27 +02:00
|
|
|
lv_obj_add_event_cb(text_ta, ta_event_cb, LV_EVENT_ALL, NULL);
|
|
|
|
lv_obj_align(text_ta, LV_ALIGN_TOP_RIGHT, -5, 20);
|
2021-02-14 14:56:34 +01:00
|
|
|
|
|
|
|
|
2021-03-15 02:03:27 +08:00
|
|
|
/*Create a label and position it above the text box*/
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * oneline_label = lv_label_create(lv_scr_act());
|
2021-02-14 14:56:34 +01:00
|
|
|
lv_label_set_text(oneline_label, "Text:");
|
2021-05-11 13:18:27 +02:00
|
|
|
lv_obj_align_to(oneline_label, text_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
|
2021-02-14 14:56:34 +01:00
|
|
|
|
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);
|
|
|
|
|
2021-03-15 02:03:27 +08:00
|
|
|
lv_keyboard_set_textarea(kb, pwd_ta); /*Focus it on one of the text areas to start*/
|
2021-02-14 14:56:34 +01:00
|
|
|
}
|
|
|
|
|
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);
|
2021-05-11 13:18:27 +02:00
|
|
|
if(code == LV_EVENT_CLICKED || code == LV_EVENT_FOCUSED) {
|
2021-03-15 02:03:27 +08:00
|
|
|
/*Focus on the clicked text area*/
|
2021-05-11 13:18:27 +02:00
|
|
|
if(kb != NULL) lv_keyboard_set_textarea(kb, ta);
|
2021-02-14 14:56:34 +01:00
|
|
|
}
|
|
|
|
|
2021-05-11 13:18:27 +02:00
|
|
|
else if(code == LV_EVENT_READY) {
|
2021-05-17 20:22:01 +02:00
|
|
|
LV_LOG_USER("Ready, current text: %s", lv_textarea_get_text(ta));
|
2021-02-14 14:56:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|