Description
I wish to use a button matrix to enter numbers in to multiple individual text areas.
What MCU/Processor/Board and compiler are you using?
Teensy 4.0, Arduino IDE
What LVGL version are you using?
8.0.2
What do you want to achieve?
When I touch a text area I want then to enter numbers from the button matrix in to the touched text area only
What have you tried so far?
I have used the example " Simple Text Area" as a starting point. I have added additional text areas and call back handlers for the text areas and added call back handlers for the button matrix for each text area.
The code compiles and runs. However, the button matrix numbers appear in all text areas and I have not been able to get the button matrix to focus on only the touched text area.
Some help on achieving the right focus would be appreciated.
I would also like the text areas to show the text without a background, so the text only appears directly on the existing background. Again, some help would be appreciated.
I have attached the codeā¦
/*//=========================event handlers===============================
static void textarea_event_handler_1(lv_event_t * e)
{
lv_obj_t * ta1 = lv_event_get_target(e);//changed ta to Ta
LV_LOG_USER("Enter was pressed. The current text is: %s", lv_textarea_get_text(ta1));
}
static void textarea_event_handler_2(lv_event_t * e)
{
lv_obj_t * ta2 = lv_event_get_target(e);
LV_LOG_USER("Enter was pressed. The current text is: %s", lv_textarea_get_text(ta2));
}
static void textarea_event_handler_3(lv_event_t * e)
{
lv_obj_t * ta3 = lv_event_get_target(e);
LV_LOG_USER("Enter was pressed. The current text is: %s", lv_textarea_get_text(ta3));
}
static void btnm_event_handler_1(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);
lv_obj_t * ta1 = lv_event_get_user_data(e);
const char * txt = lv_btnmatrix_get_btn_text(obj, lv_btnmatrix_get_selected_btn(obj));
if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) lv_textarea_del_char(ta1);
else if(strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_event_send(ta1, LV_EVENT_READY, NULL);
else lv_textarea_add_text(ta1, txt);
}
static void btnm_event_handler_2(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);
lv_obj_t * ta2 = lv_event_get_user_data(e);
const char * txt = lv_btnmatrix_get_btn_text(obj, lv_btnmatrix_get_selected_btn(obj));
if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) lv_textarea_del_char(ta2);
else if(strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_event_send(ta2, LV_EVENT_READY, NULL);
else lv_textarea_add_text(ta2, txt);
}
static void btnm_event_handler_3(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);
lv_obj_t * ta3 = lv_event_get_user_data(e);//changed ta to Ta
const char * txt = lv_btnmatrix_get_btn_text(obj, lv_btnmatrix_get_selected_btn(obj));
if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) lv_textarea_del_char(ta3);
else if(strcmp(txt, LV_SYMBOL_NEW_LINE) == 0) lv_event_send(ta3, LV_EVENT_READY, NULL);
else lv_textarea_add_text(ta3, txt);
}
//===================void function=========================
lv_obj_t * ta1 = lv_textarea_create(lv_scr_act());
lv_textarea_set_one_line(ta1, true);
lv_obj_set_width(ta1, lv_pct(40));
lv_obj_align(ta1, LV_ALIGN_TOP_MID, 0, 10);
lv_obj_add_event_cb(ta1, textarea_event_handler_1, LV_EVENT_ALL, ta1);
//lv_obj_add_state(ta1, LV_STATE_FOCUSED); /*To be sure the cursor is visible*/
lv_obj_t * ta2 = lv_textarea_create(lv_scr_act());
lv_textarea_set_one_line(ta2, true);
lv_obj_set_width(ta2, lv_pct(40));
lv_obj_align(ta2, LV_ALIGN_TOP_MID, 0, 100);
lv_obj_add_event_cb(ta2, textarea_event_handler_2, LV_EVENT_READY, ta2);
lv_obj_add_state(ta2, LV_STATE_FOCUSED); /*To be sure the cursor is visible*/
lv_obj_t * ta3 = lv_textarea_create(lv_scr_act());
lv_textarea_set_one_line(ta3, true);
lv_obj_set_width(ta3, lv_pct(40));
lv_obj_align(ta3, LV_ALIGN_TOP_MID, 0, 190);
lv_obj_add_event_cb(ta3, textarea_event_handler_3, LV_EVENT_READY, ta3);
lv_obj_add_state(ta3, 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",
LV_SYMBOL_BACKSPACE, "0", LV_SYMBOL_NEW_LINE, ""};
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act());
lv_obj_set_size(btnm, 200, 150);
lv_obj_align(btnm, LV_ALIGN_BOTTOM_MID, 0, -10);
lv_obj_add_event_cb(btnm, btnm_event_handler_1, LV_EVENT_VALUE_CHANGED, ta1);
lv_obj_add_event_cb(btnm, btnm_event_handler_2, LV_EVENT_VALUE_CHANGED, ta2);//added
lv_obj_add_event_cb(btnm, btnm_event_handler_3, LV_EVENT_VALUE_CHANGED, ta3);//added
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);
//lv_btnmatrix_set_textarea(btnm, ta1); // tried to use similar code to keyboard but not recognised
*/
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.