Description
If closed button are pressed only the message box closes keyboard stays open with the overlay and prevents my from using the pervious pop-ups
What MCU/Processor/Board and compiler are you using?
ESP32-S3 4.3inch Capacitive Touch Display Development Board, 800×480, 5-point Touch, 32-bit
What LVGL version are you using?
8.3.9
What do you want to achieve?
I want everything to close when you exit the pop-up message box
What have you tried so far?
// Popup message box for entering Wi-Fi password
void popupMsgBox(const char *title, const char *hint, const String &selectedSSID) {
selectedSSID_static = selectedSSID;
// Create overlay
lv_obj_t *overlay = lv_obj_create(lv_scr_act());
lv_obj_set_size(overlay, LV_HOR_RES, LV_VER_RES);
lv_obj_set_style_bg_color(overlay, lv_color_black(), LV_PART_MAIN);
lv_obj_set_style_bg_opa(overlay, LV_OPA_50, LV_PART_MAIN);
lv_obj_set_style_border_width(overlay, 0, LV_PART_MAIN);
lv_obj_align(overlay, LV_ALIGN_CENTER, 0, 0);
// Create message box on top of overlay (with built-in cancel button)
static const char *btns[] = {"Connect", ""}; // No need to explicitly add "Cancel" here, as it exists in the close button
lv_obj_t *mbox = lv_msgbox_create(overlay, title, hint, btns, true);
lv_obj_align(mbox, LV_ALIGN_CENTER, 0, -40);
// Create textarea for password input
lv_obj_t *textarea = lv_textarea_create(mbox);
lv_textarea_set_password_mode(textarea, true);
lv_obj_set_width(textarea, 200);
lv_obj_align(textarea, LV_ALIGN_CENTER, 0, 0);
lv_textarea_set_placeholder_text(textarea, "Enter password");
// Create keyboard if it doesn't exist
if (!keyboard) {
keyboard = lv_keyboard_create(lv_scr_act());
lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_TEXT_LOWER);
lv_obj_set_size(keyboard, LV_HOR_RES, LV_VER_RES / 3);
lv_obj_align(keyboard, LV_ALIGN_BOTTOM_MID, 0, 0);
}
lv_obj_add_flag(keyboard, LV_OBJ_FLAG_HIDDEN);
// Show keyboard when textarea is focused
lv_obj_add_event_cb(textarea, [](lv_event_t *e) {
lv_obj_clear_flag(keyboard, LV_OBJ_FLAG_HIDDEN);
lv_keyboard_set_textarea(keyboard, lv_event_get_target(e));
lv_obj_move_foreground(keyboard);
}, LV_EVENT_FOCUSED, NULL);
// Event handler for the "Connect" button in the message box
lv_obj_add_event_cb(mbox, [](lv_event_t *e) {
lv_obj_t *mbox = lv_event_get_target(e);
lv_obj_t *overlay = (lv_obj_t *)lv_event_get_user_data(e); // Retrieve overlay
// Check which button was clicked
uint32_t btn_id = lv_msgbox_get_active_btn(mbox);
if (btn_id == 0) { // "Connect" button
lv_obj_t *textarea = lv_obj_get_child(mbox, 0); // Get the textarea
const char *input_text = lv_textarea_get_text(textarea);
String password = String(input_text);
password.trim();
Serial.printf("Password entered: %s\n", password.c_str());
lv_obj_del(mbox); // Close the message box
lv_obj_del(overlay); // Close the overlay
lv_obj_add_flag(keyboard, LV_OBJ_FLAG_HIDDEN); // Hide the keyboard after submitting
connectToWiFi(selectedSSID_static, password); // Use the selected SSID to connect
}
}, LV_EVENT_VALUE_CHANGED, overlay);
// Bring message box and keyboard to the front
lv_obj_move_foreground(mbox);
}
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.