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-05-11 13:13:01 +02:00
|
|
|
static void textarea_event_handler(lv_event_t * e)
|
|
|
|
{
|
|
|
|
lv_obj_t * ta = lv_event_get_target(e);
|
2022-10-10 21:31:29 +08:00
|
|
|
LV_UNUSED(ta);
|
2021-05-11 13:13:01 +02:00
|
|
|
LV_LOG_USER("Enter was pressed. The current text is: %s", lv_textarea_get_text(ta));
|
|
|
|
}
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-04-14 15:31:54 +02:00
|
|
|
static void btnm_event_handler(lv_event_t * e)
|
2021-02-08 09:53:03 +01:00
|
|
|
{
|
2021-04-14 15:31:54 +02:00
|
|
|
lv_obj_t * obj = lv_event_get_target(e);
|
2021-04-19 11:15:28 +02:00
|
|
|
lv_obj_t * ta = lv_event_get_user_data(e);
|
2023-09-14 20:12:31 +02:00
|
|
|
const char * txt = lv_buttonmatrix_get_button_text(obj, lv_buttonmatrix_get_selected_button(obj));
|
2021-02-14 14:56:34 +01:00
|
|
|
|
2023-10-12 20:37:27 +02:00
|
|
|
if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) lv_textarea_delete_char(ta);
|
2023-02-20 20:50:58 +01:00
|
|
|
else if(strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_obj_send_event(ta, LV_EVENT_READY, NULL);
|
2021-04-19 11:15:28 +02:00
|
|
|
else lv_textarea_add_text(ta, txt);
|
2021-02-14 14:56:34 +01:00
|
|
|
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void lv_example_textarea_1(void)
|
|
|
|
{
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_t * ta = lv_textarea_create(lv_screen_active());
|
2021-08-03 16:36:10 +02:00
|
|
|
lv_textarea_set_one_line(ta, true);
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align(ta, LV_ALIGN_TOP_MID, 0, 10);
|
2023-11-28 15:36:51 +01:00
|
|
|
lv_obj_add_event_cb(ta, textarea_event_handler, LV_EVENT_READY, ta);
|
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",
|
2022-02-13 13:59:17 -05:00
|
|
|
"4", "5", "6", "\n",
|
|
|
|
"7", "8", "9", "\n",
|
|
|
|
LV_SYMBOL_BACKSPACE, "0", LV_SYMBOL_NEW_LINE, ""
|
|
|
|
};
|
2021-02-14 14:56:34 +01:00
|
|
|
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_t * btnm = lv_buttonmatrix_create(lv_screen_active());
|
2021-02-14 14:56:34 +01:00
|
|
|
lv_obj_set_size(btnm, 200, 150);
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align(btnm, LV_ALIGN_BOTTOM_MID, 0, -10);
|
2023-11-28 15:36:51 +01:00
|
|
|
lv_obj_add_event_cb(btnm, btnm_event_handler, LV_EVENT_VALUE_CHANGED, ta);
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_remove_flag(btnm, LV_OBJ_FLAG_CLICK_FOCUSABLE); /*To keep the text area focused on button clicks*/
|
2023-09-14 20:12:31 +02:00
|
|
|
lv_buttonmatrix_set_map(btnm, btnm_map);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|