1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/examples/widgets/textarea/lv_example_textarea_1.c

39 lines
1.4 KiB
C
Raw Normal View History

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_BUILD_EXAMPLES
2021-02-08 09:53:03 +01:00
2021-02-14 14:56:34 +01:00
static void btnm_event_handler(lv_obj_t * obj, lv_event_t event)
2021-02-08 09:53:03 +01:00
{
if(event == LV_EVENT_VALUE_CHANGED) {
2021-02-14 14:56:34 +01:00
lv_obj_t * ta = lv_event_get_user_data();
const char * txt = lv_btnmatrix_get_btn_text(obj, lv_btnmatrix_get_selected_btn(obj));
2021-02-14 14:56:34 +01:00
if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) lv_textarea_del_char(ta);
else if(strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_textarea_add_char(ta, '\n');
else lv_textarea_add_text(ta, txt);
2021-02-08 09:53:03 +01:00
}
}
void lv_example_textarea_1(void)
{
lv_obj_t * ta = lv_textarea_create(lv_scr_act());
2021-03-19 16:33:42 +01:00
lv_textarea_set_one_line(ta, true);
lv_obj_align(ta, LV_ALIGN_TOP_MID, 0, 10);
2021-02-14 14:56:34 +01:00
lv_obj_add_state(ta, LV_STATE_FOCUSED); /*To be sure the cursor is visible*/
static const char * btnm_map[] = {"1", "2", "3", "\n",
"4", "5", "6", "\n",
"7", "8", "9", "\n",
2021-03-03 09:22:34 +01:00
LV_SYMBOL_BACKSPACE, "0", LV_SYMBOL_NEW_LINE, ""};
2021-02-14 14:56:34 +01:00
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act());
2021-02-14 14:56:34 +01:00
lv_obj_set_size(btnm, 200, 150);
lv_obj_align(btnm, LV_ALIGN_BOTTOM_MID, 0, -10);
2021-02-14 14:56:34 +01:00
lv_obj_add_event_cb(btnm, btnm_event_handler, ta);
lv_obj_clear_flag(btnm, LV_OBJ_FLAG_CLICK_FOCUSABLE); /*To keep the text area focused on button clicks*/
lv_btnmatrix_set_map(btnm, btnm_map);
2021-02-08 09:53:03 +01:00
}
#endif