cpp
static void ui_wifi_populate_list(const std::vector<WifiApEntry>& entries)
{
if (ui_wifi_list_container == NULL) {
return;
}
lv_obj_clean(ui_wifi_list_container);
if (entries.empty()) {
lv_obj_t * empty_label = lv_label_create(ui_wifi_list_container);
lv_label_set_text(empty_label, "未发现 WiFi");
lv_obj_set_width(empty_label, lv_pct(100));
lv_obj_set_style_text_align(empty_label, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN | LV_STATE_DEFAULT);
ui_wifi_apply_theme_to_label(empty_label);
return;
}
for (const auto& entry : entries) {
lv_obj_t * row = lv_button_create(ui_wifi_list_container);
lv_obj_set_width(row, lv_pct(100));
lv_obj_set_height(row, 72);
lv_obj_set_style_bg_color(row, lv_color_hex(0xFFFFFF), LV_PART_MAIN );
lv_obj_set_style_bg_color(row, lv_color_hex(0xFFFFFF), LV_STATE_DEFAULT );
lv_obj_set_style_pad_hor(row, 16, LV_PART_MAIN);
lv_obj_remove_flag(row, LV_OBJ_FLAG_SCROLLABLE);
auto * row_data = new WifiApRowData();
row_data->ssid = entry.ssid;
row_data->authmode = entry.authmode;
lv_obj_set_user_data(row, row_data);
lv_obj_add_event_cb(row, ui_event_wifi_ap_clicked, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(row, ui_event_wifi_ap_deleted, LV_EVENT_DELETE, NULL);
lv_obj_t * ssid_label = lv_label_create(row);
lv_obj_set_width(ssid_label, lv_pct(65));
lv_label_set_long_mode(ssid_label, LV_LABEL_LONG_DOT);
lv_label_set_text(ssid_label, entry.ssid.c_str());
ui_wifi_apply_theme_to_label(ssid_label);
lv_obj_align(ssid_label, LV_ALIGN_LEFT_MID, 0, 0);
char meta[48];
snprintf(meta, sizeof(meta), "%ddBm %s", entry.rssi, ui_wifi_auth_label(entry.authmode));
lv_obj_t * meta_label = lv_label_create(row);
lv_label_set_text(meta_label, meta);
ui_wifi_apply_theme_to_label(meta_label);
lv_obj_align(meta_label, LV_ALIGN_RIGHT_MID, 0, 0);
}
}
像那种
lv_obj_t * row = lv_button_create(ui_wifi_list_container);
它本身是返回的一个指针,实际的内存在堆里面,
而且ui_wifi_list_container 父节点会有一份孩子的指针,
后续删除的时候,可以对父节点进行操作即可。
lv_obj_t * row 被注销了也没有事情。