首页 > 其他分享 >lvgl table的使用(重绘,事件,行选中,点击,蒙版)

lvgl table的使用(重绘,事件,行选中,点击,蒙版)

时间:2024-06-13 20:11:05浏览次数:22  
标签:蒙版 set obj lv LV table lvgl col

 

//

//验证//密码//人脸//刷卡
#include "baseapp.h"
static lv_group_t* appGroupBtn;
static lv_obj_t* infoMeterLVGLBrushCard=NULL;

static lv_obj_t* infoTextareaMeterPasswdValue;
static lv_obj_t* appObjCamera;
static lv_obj_t* appObjCameraAiFaceImg;
static lv_obj_t* appObjCameraAnim;
static lv_obj_t* appObjInfoData;

static int passwdTextTotal;

#define CAMERA_SHOW_WIDTH 640
#define CAMERA_SHOW_HEIGH 480
#define CAMERA_SHOW_HEIGH_ANIM_MIN -250
#define CAMERA_SHOW_HEIGH_ANIM_MAX +50

static StructObject objs[]={
    // {{APP_HANDLE_KEY_TYPE__TEXT,APP_UI_ALIGN_B_MIDDLE,0,-150,&infoTextareaMeterPasswdValue},{APP_FONT_DEFAULT,APP_STYLE_FONT_COLOR_BLUE,{"请输入密码","Please enter the password"}}},
    // {{APP_HANDLE_KEY_TYPE_CANVAS,APP_UI_ALIGN_C_MIDDLE,0,-100,&appObjCamera},{APP_FONT_DEFAULT,APP_STYLE_DEFAULT,{CAMERA_SHOW_WIDTH,CAMERA_SHOW_HEIGH}}},
    // {{APP_HANDLE_KEY_TYPE___IMG,APP_UI_ALIGN_C_MIDDLE,0,-100,&appObjCameraAiFaceImg},{0,0,{"image/reachtruck/600_aiface.png"}}},
    // {{APP_HANDLE_KEY_TYPE___IMG,APP_UI_ALIGN_C_MIDDLE,0,CAMERA_SHOW_HEIGH_ANIM_MIN,&appObjCameraAnim},{0,0,{"image/reachtruck/600_anim.png"}}},
    {{APP_HANDLE_KEY_TYPE_LABEL,APP_UI_ALIGN_B_MIDDLE,0,-30,&appObjInfoData},{APP_FONT_DEFAULT,APP_STYLE_FONT_COLOR_BLUE,{"test"}}}
};



// 遮罩
static lv_obj_t * mask_parent;
static lv_obj_t * mask_name;
static lv_obj_t * mask_state;
// void create_mask_obj(void);
static void mask_obj_show(char* name){
    lv_label_set_text(mask_name,name);
    lv_label_set_text(mask_state,"please click face btn");

    if(lv_obj_has_flag(mask_parent,LV_OBJ_FLAG_HIDDEN)==true){
        lv_obj_clear_flag(mask_parent,LV_OBJ_FLAG_HIDDEN);
    }
}
static void mask_obj_hide(void){
    if(lv_obj_has_flag(mask_parent,LV_OBJ_FLAG_HIDDEN)==false){
        lv_obj_add_flag(mask_parent,LV_OBJ_FLAG_HIDDEN);
    }
}
// 取消 回调函数
static void event_cb_btn_cancel(lv_event_t * e) {
    // lv_obj_t * obj = lv_event_get_target(e);
    mask_obj_hide();
    mydebug;
}
// 删除 回调函数
static void event_cb_btn_del(lv_event_t * e) {
    mask_obj_hide();
    mydebug;
}
// 重新录入 回调函数
static void event_cb_btn_record(lv_event_t * e) {
    mask_obj_hide();
    mydebug;
}
static void create_mask_obj(void){
    mask_parent = lv_obj_create(appObjUiParent);
    lv_obj_set_size(mask_parent, lv_obj_get_width(appObjUiParent)-1, lv_obj_get_height(appObjUiParent)-1);
    lv_obj_set_style_bg_color(mask_parent,lv_color_hex(0x145B7D),LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(mask_parent,LV_OPA_30,LV_STATE_DEFAULT);
    lv_obj_center(mask_parent);

    lv_obj_t * mask_p = lv_obj_create(mask_parent);
    lv_obj_set_size(mask_p, 600, 400);
    lv_obj_set_style_bg_color(mask_p,lv_color_hex(0xfffef9),LV_STATE_DEFAULT);
    // lv_obj_set_style_bg_opa(mask_P,LV_OPA_30,LV_STATE_DEFAULT);
    lv_obj_center(mask_p);

    // 姓名
    mask_name = lv_label_create(mask_p);
    lv_obj_align(mask_name,LV_ALIGN_TOP_MID,0,30);
    lv_label_set_text(mask_name,"mask_name");

    // 状态
    mask_state = lv_label_create(mask_p);
    lv_obj_align(mask_state,LV_ALIGN_CENTER,0,0);
    lv_label_set_text(mask_state,"mask_state");


    // 取消
    lv_obj_t * btn_cancel =  lv_btn_create(mask_p);
    lv_obj_set_size(btn_cancel,45,45);
    lv_obj_set_style_radius(btn_cancel, LV_PCT(40), LV_PART_MAIN);
    lv_obj_align(btn_cancel,LV_ALIGN_TOP_RIGHT,0,0);
    lv_obj_add_event_cb(btn_cancel, event_cb_btn_cancel, LV_EVENT_CLICKED, NULL);
    lv_obj_t * btn_cancel_name = lv_label_create(btn_cancel);
    lv_obj_center(btn_cancel_name);
    // lv_obj_set_style_text_font()
    lv_label_set_text(btn_cancel_name,"X");

    // 删除
    lv_obj_t * btn_del =  lv_btn_create(mask_p);
    lv_obj_set_size(btn_del,100,50);
    lv_obj_set_style_radius(btn_del, 5, LV_PART_MAIN);
    lv_obj_align(btn_del,LV_ALIGN_BOTTOM_MID,-200,-10);
    lv_obj_add_event_cb(btn_del, event_cb_btn_del, LV_EVENT_CLICKED, NULL);
    lv_obj_t * btn_del_name = lv_label_create(btn_del);
    lv_obj_center(btn_del_name);
    lv_label_set_text(btn_del_name,"DEL");

    // 重新录入
    lv_obj_t * btn_record =  lv_btn_create(mask_p);
    lv_obj_set_size(btn_record,100,50);
    lv_obj_set_style_radius(btn_record, 5, LV_PART_MAIN);
    lv_obj_align(btn_record,LV_ALIGN_BOTTOM_MID,200,-10);
    lv_obj_add_event_cb(btn_record, event_cb_btn_record, LV_EVENT_CLICKED, NULL);
    lv_obj_t * btn_record_name = lv_label_create(btn_record);
    lv_obj_center(btn_record_name);
    lv_label_set_text(btn_record_name,"FACE");

}



// 表格
static uint16_t selected_row = LV_TABLE_CELL_NONE;
static lv_obj_t * table1;
// 重绘的回调
static void table_event_begin_cb(lv_event_t* e){
    lv_obj_draw_part_dsc_t* dsc = (lv_obj_draw_part_dsc_t*)lv_event_get_param(e);
    if (dsc->part == LV_PART_ITEMS) {
        uint32_t row = dsc->id / lv_table_get_col_cnt(table1);
        uint32_t col = dsc->id - row * lv_table_get_col_cnt(table1);
        // dsc->label_dsc->align = LV_TEXT_ALIGN_CENTER;//文字居中
        if (row == selected_row) {
            dsc->rect_dsc->bg_color = lv_color_hex(0xD9D6C3);
            dsc->rect_dsc->bg_opa = LV_OPA_60;
        }
    }
}
// 表格的事件回调函数
static void table_event_cb(lv_event_t * e) {
    // lv_obj_t * obj = lv_event_get_target(e);
    lv_obj_t * obj = table1;
    uint16_t col, row;
    lv_table_get_selected_cell(obj, &row, &col);  // 获取被按下的单元格
    // mydebugNum(row);
    // mydebugNum(col);
    if(selected_row == row) {
        mydebugNum(selected_row);
        mask_obj_show(lv_table_get_cell_value(obj,row, 1));
    } else {
        selected_row = row;
        mydebugNum(selected_row);
    }
}
 
static void create_table_and_styles(void) {
    // 创建表格
    #define table_header_height 60
    #define table_header_offset 15
    lv_obj_t * table_col = lv_table_create(appObjUiParent); 
    lv_table_set_col_cnt(table_col, 4);  // 假定有4列
    lv_table_set_row_cnt(table_col, 1); // 假定有1
    lv_obj_set_size(table_col, lv_obj_get_width(appObjUiParent)-200, table_header_height);
    lv_table_set_cell_value(table_col, 0, 0, "ID");
    lv_table_set_cell_value(table_col, 0, 1, "NAME");
    lv_table_set_cell_value(table_col, 0, 2, "TEL");
    lv_table_set_cell_value(table_col, 0, 3, "IDENTIFY");
    lv_obj_set_style_text_align(table_col,LV_TEXT_ALIGN_CENTER,LV_PART_ITEMS);
    lv_obj_set_style_bg_color(table_col,lv_color_hex(0xD3D7D4),LV_PART_ITEMS);
    lv_obj_set_style_border_side(table_col,LV_BORDER_SIDE_NONE,LV_PART_ITEMS);
    lv_obj_set_style_bg_color(table_col,lv_color_hex(0xD3D7D4),LV_PART_MAIN);
    int col_w[]={120,180,200,300};
    for(uint16_t col = 0; col < lv_table_get_col_cnt(table_col); col++){lv_table_set_col_width(table_col, col, col_w[col]);}
    lv_obj_align(table_col, LV_ALIGN_TOP_MID, 0, table_header_offset);

    table1 = lv_table_create(appObjUiParent); 
    lv_table_set_col_cnt(table1, 4);  // 假定有4列
    lv_table_set_row_cnt(table1, 100); // 假定有10行
    lv_obj_set_size(table1, lv_obj_get_width(appObjUiParent)-200, lv_obj_get_height(appObjUiParent)-table_header_offset*2-table_header_height);
    // int col_w[]={100,150,200,430};
    for(uint16_t col = 0; col < lv_table_get_col_cnt(table1); col++){lv_table_set_col_width(table1, col, col_w[col]);}
    lv_obj_set_style_text_align(table1,LV_TEXT_ALIGN_CENTER,LV_PART_ITEMS);
    lv_obj_set_style_bg_color(table1,lv_color_hex(0xF6F5EC),LV_PART_ITEMS);
    lv_obj_set_style_border_width(table1,2,LV_PART_ITEMS);
    lv_obj_set_style_border_side(table1,LV_BORDER_SIDE_BOTTOM,LV_PART_ITEMS);
    lv_obj_set_style_bg_color(table1,lv_color_hex(0xF6F5EC),LV_PART_MAIN);
    lv_obj_align(table1, LV_ALIGN_TOP_MID, 0, table_header_height+table_header_offset);

    // 设置表格单元格的内容,此处以文本"Cell x-y"为例
    for(uint16_t row = 0; row < lv_table_get_row_cnt(table1); row++) {
        // lv_table_set_cell_value_fmt(table1, row, col, "Cell %d-%d", row, col);
        // lv_table_set_cell_value_fmt(table1, row, 0, "%d", 65530-row);
        lv_table_set_cell_value(table1, row, 0, "---");
        lv_table_set_cell_value_fmt(table1, row, 1, "name_%d", row);
        lv_table_set_cell_value_fmt(table1, row, 2, "15597683%d", 999-row);
        lv_table_set_cell_value_fmt(table1, row, 3, "41132519950707%d", 9999-row);
    }
    // for(uint16_t col = 0; col < lv_table_get_col_cnt(table1); col++) { }
    
    // 重绘事件
    lv_obj_add_event_cb(table1, table_event_begin_cb, LV_EVENT_DRAW_PART_BEGIN, NULL);
    // 设置表格的事件回调
    lv_obj_add_event_cb(table1, table_event_cb, LV_EVENT_CLICKED, NULL);
}
 









static void timerCameraShow(lv_timer_t* timer){
    // if(appObjCamera==NULL){ 
    //     mydebugUs;
    //     lv_timer_del(timer); 
    //     return; 
    // } 
    //
}








static int HandleRecv(int type,void* param,int len){
    return 0;
}


//释放
static int Release(void){
    appObjCamera=NULL;
    infoTextareaMeterPasswdValue=NULL;
    appObjInfoData=NULL;
    lv_group_del(appGroupBtn);
    mydebug;
    return 0;
}


static void TIME_TEST_PAGE_TIP3333(lv_timer_t* timer){
    HandlePageLevelUp();
} 
 

//初始化
static int Init(void){ 
    mydebug;
    for(int i=0;i<(sizeof(objs)/sizeof(StructObject));i++){ HandleCreateObject(appObjUiParent,&objs[i]); }

    // 创建表格和样式
    create_table_and_styles();
    create_mask_obj();
    mask_obj_hide();

    // lv_timer_set_repeat_count(lv_timer_create(TIME_TEST_PAGE_TIP3333,3000,NULL),1);
    // lv_timer_create(timerCameraShow, 5, NULL);

    appGroupBtn = lv_group_create();
    currentAppUseDefaultButtonGroup = appGroupBtn;//使用自定义按钮
    currentAppFuncRelease=Release;
    currentAppFuncHandleKey=NULL;
    currentAppFuncHandleRecv=NULL;

    //自动跳转
    // lv_timer_set_repeat_count(lv_timer_create(mytime,5000,NULL),1);
    // lv_timer_set_repeat_count(lv_timer_create(timerCameraHandle__,2000,NULL),1);

    return 0;
}
//预处理
int PreproccessLanguageSelect(void) {
    listHandlePageInit[APP_UI_MENU_LANGUAGE] = Init;
    return 0;
}

 

 

//

标签:蒙版,set,obj,lv,LV,table,lvgl,col
From: https://www.cnblogs.com/RYSBlog/p/18246684

相关文章

  • 【限免】Stable Diffusion一键部署 开箱即用!
    参加AI写真快闪活动时,教学视频只有几分钟,但您可能自己实操时,仅准备环境、上传下载文件就要花几个小时,甚至一两天,苦不堪言!近期好易智算重磅上线,完美解决了stablediffusion模型、Lora等大文件下载慢的问题,下载速度能稳定达到500M/s,5G左右的文件10秒内搞定,加上其一键部署、开箱即......
  • stable-diffusion-webui 环境配置
    链接:AUTOMATIC1111/stable-diffusion-webui:StableDiffusionwebUI(github.com)查看python版本:   安装完python之后,打开工程,配置虚拟环境 下载安装对应的依赖库,其中的torch相关三个库选择与自己cuda相关的版本安装,我的pytorch选的是2.1.2,下载网址:download.pytorch.o......
  • element ui 封装Table组件
    1.首先npmielement-ui-S安装element-ui2.引入Element在main.js中写入以下内容:importVuefrom'vue';importElementUIfrom'element-ui';import'element-ui/lib/theme-chalk/index.css';importAppfrom'./App.vue';Vue.use(Ele......
  • 【JUC】7-CompletableFutrue的应用 大厂案例分析 -电商比价
    1.需求说明1.1同一款产品,同时搜索出同款产品在各大电商平台的售价;1.2同一款产品,同时搜索出本产品在同一个电商平台下,各个入驻卖家售价是多少;2.输出返回:出来结果希望是同款产品的在不同地方的价格清单列表,返回一个List<String>《Mysql》injdpriceis88.05《Mysql》in......
  • c++哈希表hash_table的深度学习(hash_map,un和hash_set的底层实现)
    什么是哈希表?哈希表(HashTable)是一种数据结构,它使用哈希函数将键(key)映射到桶(bucket)或槽(slot)中,可以直接通过相应的键值直接对数据进行访问,高效的插入,删除,查找 哈希表的组成部分和特性哈希函数:哈希函数接受一个键作为输入,并返回一个索引值(通常是一个整数),该索引值用于确定键......
  • iptables - 规则动作
    规则和动作rule(规则)通过定义链和表而形成规则存在内核空间的信息报过滤表中规则指定了原地址,目的地址,传输协议(TCP,UDP,ICMP),服务类型(HTTP,FTP,SMTP)等要求当规则匹配时,就根据规则定义的方法处理(accept-放行,reject-拒绝,drop-丢弃)数据包,如果数据包头......
  • Java线程池以及Future和CompletableFuture的用法
    参考:https://blog.csdn.net/weixin_50330544/article/details/1316871501.线程池为什么使用线程池?频繁申请/销毁资源和调度资源,将带来额外的消耗,可能会非常巨大。对资源无限申请缺少抑制手段,易引发系统资源耗尽的风险。系统无法合理管理内部的资源分布,会降低系统的稳定性。......
  • AIGC绘画设计:深入浅出完整解析Stable Diffusion(SD)核心基础知识
    心血来潮再加上想要督促自己,所以决定开始搞AI绘画技术的分享。如果觉得我写的好,又很久没更新,请多点我,因为可能我的懒癌又犯了,哈哈哈哈哈......没有本人帅,十分之一都没有不多废话,切入主题。学一门技术什么最难?当然是入门最难!从0到1,远远比从1到100要难一百倍,为啥?因为你之前......
  • R:microtable包线性判别分析LEfSe
    rm(list=ls())setwd("C:\\Users\\Administrator\\Desktop\\New_microtable")#设置工作目录library(microeco)library(magrittr)library(dplyr)library(tibble)feature_table<-read.table('Bac_species.txt',header=TRUE,row.names=......
  • Java多线程CompletableFuture使用
    引言一个接口可能需要调用N个其他服务的接口,这在项目开发中非常常见。如果是串行执行的话,接口的响应速度会很慢。考虑到这些接口之间有大部分都是无前后顺序关联的,可以并行执行。就比如说调用获取商品详情的时候,可以同时调用获取物流信息,通过并行执行多个任务的方式,接口的......