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

相关推荐
_Twink1e1 天前
openJiuwen 实训营 Day 1 · WorkSwarm 入门教程
开发语言·c++·openjiuwen
dong_junshuai1 天前
每天一个开源项目#87 fmt:24.5K Stars 的 C++ 格式化核心
c++·开源·github
我命由我123451 天前
Photoshop - Photoshop 把两个 PSD 文件合并
学习·ui·职场和发展·产品运营·产品经理·学习方法·photoshop
雪的季节1 天前
Multisim14.0的详细中文安装步骤【附安装包】
c++
Persistent的粽子!1 天前
C++:类与对象(二)
开发语言·c++
蒸蒸yyyyzwd1 天前
cpp 选手备战秋招学习笔记 day23
c++·求职招聘
.YM.Z1 天前
C++ STL 容器深度剖析:vector 与 list 的模拟实现及对比
开发语言·c++·vector·list
mengzhi啊1 天前
QEventLoop loop配合loop.exec();替代while(1)。电脑cpu占用为0,使用while(1)cpu占用率100%
c++·qt
HugoStudio_SWAN1 天前
洛谷 P1319 / P1320 压缩技术——同一枚硬币的正反面
c++·学习·程序人生·算法
小小晓.1 天前
C++单例模式万字详解:6种实现演进+线程安全彻底解决+CRTP终极模板
c++·单例模式