Delete characters in textarea with pwd mode turned on

Important: posts that do not use this template will be ignored or closed.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation. We will not respond in detail to posts where you haven’t read the relevant documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.


I have a window, where it is required to enter a number password before one can procede. I use a buttonmatrix (for the numbers), and a seperate button to handle deletion of characters. As it is a password i have enabled the pwd mode in the textarea, but when i then try to delete a charcter i get some weird results. Basically it seems to work just fine without password mode switched on, but with the password mode on I get these wierd results when i delete characters.

What MCU/Processor/Board and compiler are you using?

As the video shows im using the simulator on a windows, right now, though i hardly think it’s the problem.

What do you want to achieve?

I would like to have a working password “system” in the sense that i can delete characters with password mode on.

What have you tried so far?

I have tried to run it without the password mode set to true, and then i couldn’t crash/break it, so thats why i’m so stuck

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

I belive this is all the relevant code

    btnm1 = lv_btnmatrix_create(winPin, NULL);
    lv_btnmatrix_set_map(btnm1, btnm_map);
    lv_obj_add_style(btnm1, LV_BTNMATRIX_PART_BG, &style_btnm_bg);
    lv_obj_add_style(btnm1, LV_BTNMATRIX_PART_BTN, &style_btnmatrix_btn);
    lv_obj_set_size(btnm1, 170, 226);
    lv_btnmatrix_set_btn_ctrl(btnm1, 9, LV_BTNMATRIX_CTRL_HIDDEN );
    lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_HIDDEN);
    lv_obj_align(btnm1, NULL, LV_ALIGN_CENTER, 0, 15);  
    lv_obj_set_event_cb(btnm1, btnmatrix_event_handler);

    BSbtn = lv_imgbtn_create(winPin, NULL);
    lv_imgbtn_set_src(BSbtn, LV_BTN_STATE_RELEASED, &BackspaceIcon);
    lv_imgbtn_set_src(BSbtn, LV_BTN_STATE_PRESSED,  &BackspaceIconPR);
    lv_obj_set_event_cb(BSbtn, btnmatrix_event_handler);
    lv_obj_align(BSbtn, NULL, LV_ALIGN_CENTER, 55, 100);

    printf("PinWin B\n");

    ta = lv_textarea_create(winPin, NULL);
    lv_obj_set_size(ta, 160, 40);
    lv_obj_add_style(ta, LV_TEXTAREA_PART_BG, &style_text_placeholder);
    lv_obj_add_style(ta, LV_TEXTAREA_PART_PLACEHOLDER, &style_text_placeholder);
    lv_textarea_set_cursor_click_pos(ta, true);
    lv_textarea_set_max_length(ta, 4);
    lv_obj_align(ta, winPin, LV_ALIGN_IN_TOP_MID, 0, 10);
    lv_textarea_set_text(ta, "");
    lv_textarea_set_accepted_chars(ta, "1234567890");
    lv_textarea_set_placeholder_text(ta, "____");
    lv_textarea_set_one_line(ta, true);
    lv_textarea_set_cursor_hidden(ta, false);
    lv_textarea_set_text_sel(ta, false);
    lv_textarea_set_pwd_mode(ta, true);

    printf("PinWin C\n");

The button matrix handler including dealing with clicks on the deletion button (BSbtn)

static void btnmatrix_event_handler(lv_obj_t* obj, lv_event_t event)

    if (event != LV_EVENT_CLICKED) return; 
    if (obj == NULL) return;
    if (obj == BSbtn) {
        lv_textarea_set_cursor_pos(ta, LV_TEXTAREA_CURSOR_LAST);
        printf("%s\n", lv_textarea_get_text(ta));
    } // endif

    if (obj != BSbtn && lv_btnmatrix_get_active_btn_text(btnm1) != NULL) {
        lv_textarea_add_text(ta, lv_btnmatrix_get_active_btn_text(btnm1));
        printf("%s\n", lv_textarea_get_text(ta));

        //if the entered numbers are correct 
        if (strcmp(lv_textarea_get_text(ta), "1234") == 0) { 
            printf("%s\n", "Bingo");
    } // end if 
/*You code here*/

Screenshot and/or video

When a character is pressed or deleted the textareas text is printed to the left:

Thanks for the repost. I’ve fixed it in master.

1 Like