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

相关推荐
小小龙学IT1 小时前
Boost.Interprocess 开源 C++ 进程间通信库深度解析
c++·开源
倒头就睡的小比特5 天前
算法竞赛C++常用的STL
c++·算法
weilx12345 天前
C++笔记-文件IO-<fcntl.h>
c++
大蓝头5 天前
安装包UI美化之路-nsNiuniuSkin全新UI调试与预览方法
ui·electron·安装包·截图控件·截屏控件
Smileyqp沛沛5 天前
前端?C++ ?较大差异基础罗列
c++·基础·前端转c++
C语言小火车6 天前
C/C++ 为什么需要编译器?
开发语言·c++
旖旎夜光6 天前
力控面试题 01.01: 判定字符是否唯一(位运算) —— 题解
c++·学习·算法·leetcode·力控
吞下星星的少年·-·6 天前
C++ 萌新语法入门篇
c++·算法比赛
霍霍的袁6 天前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio
another heaven6 天前
【算法/C++ MD5算法能否逆解码?原理、C++实现与同类哈希算法对比】
c++·算法·哈希算法