LVGL

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 被注销了也没有事情。

相关推荐
x10n91 小时前
微软 VC++ 运行库合集VCRedistPack
开发语言·c++·microsoft·vc++运行库·dll报错
qz_Serene1 小时前
C++:string(底层,常用接口,具体题目,模拟实现)
开发语言·c++
king13598745502 小时前
LiteRT Tensor API:C++ 编写端侧模型图,XNNPACK、GPU 与 NPU 怎么选?
开发语言·c++·人工智能·chatgpt·架构·aigc
青少儿编程课堂2 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:差分数组与区间修改实战解析
c++·python·算法·bfs·信息学竞赛
纪念 2292 小时前
C++ list讲解
c++·windows·list
不会就选b8 小时前
C++补充部分(一)--lambda 表达式
开发语言·c++
丰色木夕15 小时前
Ubuntu22.04下源码编译安装USD-Brep
c++·ubuntu·nvidia·usd-brep
n876517 小时前
Playwright Java WEB UI 自动化实现框架与逻辑
java·前端·ui
衍玊18 小时前
多路转接原理与应用
c++
himobrinehacken19 小时前
位运算揭秘:左右移与符号位陷阱
c语言·c++·算法·安全