首页 > 其他分享 >LVGL btn组件

LVGL btn组件

时间:2024-06-17 20:12:43浏览次数:12  
标签:disp style btn obj drv lv 组件 line LVGL

/*************************************************
 *
 *   file name:widget_line.c
 *   author   :[email protected]
 *   date     :2024/06/17
 *   brief :移植LVGL,实现在屏幕上显示一个按钮,按钮上有一个标签,当用户通过触摸屏点击了该按钮,则显示一个新的屏幕对象
 *   note     :None
 *
 *   CopyRight (c) 2024    [email protected]    All Right Reseverd
 *
 **************************************************/
#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>

#define DISP_BUF_SIZE (8 * 1024 * 1024)
static void my_event_cb(lv_event_t * event)
{

    /*创建线条风格*/
    // 创建风格对象
    static lv_style_t style_line;
    // 对新创建的线条风格进行初始化
    lv_style_init(&style_line);
    // 设置线条宽度
    lv_style_set_line_width(&style_line, 8);
    // 设置线条颜色
    lv_style_set_line_color(&style_line, lv_palette_main(LV_PALETTE_PINK));
    // 设置线条端点是否为圆点
    lv_style_set_line_rounded(&style_line, true);

    /*虚线只能用于水平或垂直线条*/
    // lv_obj_set_style_line_dash_width(&style_line, 1, LV_PART_MAIN);//虚线显示的线条长度
    // lv_obj_set_style_line_dash_gap(&style_line, 1, LV_PART_MAIN);//虚线间隔的线条长度

    // 创建屏幕对象
    lv_obj_t * scr2 = lv_obj_create(NULL);

    // 创建线条对象
    lv_obj_t * line1 = lv_line_create(scr2);

    // 设置点数组
    static lv_point_t line_points[] = {{5, 5}, {70, 70}, {120, 10}, {180, 60}, {240, 10}};
    // 创建线条的连接点
    lv_line_set_points(line1, line_points, 5);

    // 是否反转y轴反向(默认y轴起点为上,即自上而下y值(纵坐标)增大;若选择反转,则y轴起点为下,即自下而上y值(纵坐标)增大)
    lv_line_set_y_invert(line1, true);

    // 设置线条风格
    lv_obj_add_style(line1, &style_line, 0);

    // 设置主体的位置(参照点为主体左上方的顶点)
    lv_obj_set_pos(line1, 100, 0);

    // 将创建好的线条主体添加到父对象上
    lv_obj_center(scr2);

    // 加载屏幕对象
    lv_scr_load(scr2);
}

int main(void)
{
    /*LittlevGL init*/
    lv_init(); // 初始化LVGL图形库

    /*Linux frame buffer device init*/
    fbdev_init();

    /*A small buffer for LittlevGL to draw the screen's content*/
    static lv_color_t buf[DISP_BUF_SIZE];

    /*Initialize a descriptor for the buffer*/
    static lv_disp_draw_buf_t disp_buf;
    lv_disp_draw_buf_init(&disp_buf, buf, NULL, DISP_BUF_SIZE);

    /*Initialize and register a display driver*/
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    disp_drv.draw_buf = &disp_buf;
    disp_drv.flush_cb = fbdev_flush;
    disp_drv.hor_res  = 800;
    disp_drv.ver_res  = 480;
    lv_disp_drv_register(&disp_drv);

    evdev_init();
    static lv_indev_drv_t indev_drv_1;
    lv_indev_drv_init(&indev_drv_1); /*Basic initialization*/
    indev_drv_1.type = LV_INDEV_TYPE_POINTER;

    /*This function will be called periodically (by the library) to get the mouse position and state*/
    indev_drv_1.read_cb      = evdev_read;
    lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv_1);

    // 创建屏幕对象
    lv_obj_t * scr1 = lv_obj_create(NULL);
    // 创建按钮对象
    lv_obj_t * btn1 = lv_btn_create(scr1);

    lv_obj_set_pos(btn1, 375, 220); // 设置按钮的位置
    // 创建标签对象
    lv_obj_t * lab1 = lv_label_create(btn1);
    lv_label_set_text(lab1, "line"); // 设置标签内容

    // 加载屏幕对象
    lv_scr_load(scr1);

    lv_obj_add_event_cb(btn1, my_event_cb, LV_EVENT_CLICKED, NULL); /*分配一个事件回调*/

    /*Handle LitlevGL tasks (tickless mode)*/
    while(1) {
        lv_tick_inc(5);
        lv_timer_handler();
        usleep(5000);
    }

    return 0;
}

标签:disp,style,btn,obj,drv,lv,组件,line,LVGL
From: https://www.cnblogs.com/bell-c/p/18253123

相关文章

  • React中AntDesign upload组件 自定义请求将多个上传请求合并成一个并
    接口文档核心代码constImportPictureUpload=()=>{const[fileList,setFileList]=useState([])constonBeforeUpload=(file:any,fileList:any)=>{setFileList(fileList)returnfalse;}useEffect(()=>{if(......
  • Ant Design Vue 的 Notification 组件如何调用以及常见问题解释
    AntDesignVue是一个基于Vue.js的UI组件库,它提供了一套丰富的组件来构建高质量的企业级应用程序。其中,Notification组件用于在屏幕的角落显示全局通知,以告知用户某些信息或操作的结果。以下是关于如何在AntDesignVue中调用Notification组件的详细介绍。什么是......
  • 在Vue 3中,要获取指定目录内的所有组件
     vue3获取指定目录内组件在Vue3中,要获取指定目录内的所有组件,可以使用Vue的编程式导入。这通常在自动化场景,如通过编程的方式导入一个目录下所有的Vue组件时使用。以下是一个简单的例子,展示如何在Vue3中编程式地导入一个目录下的所有组件://假设componentsDir为组件......
  • React+TS前台项目实战(九)-- 全局常用组件弹窗Dialog封装
    文章目录前言Dialog公共弹窗组件1.功能分析2.代码+详细注释3.使用方式4.效果展示总结前言今天这篇主要讲全局公共弹窗Dialog组件封装,将用到上篇封装的模态框Modal组件。有时在前台项目中,偶尔要用到一两个常用的组件,如弹窗,其实不必非安装ant-design这些主流框......
  • Unity学习笔记----摄像机组件信息相关知识点总结
    一.ClearFlags1.skybox天空盒一般用于3d游戏。2.SolidColor颜色填充一般用于2d游戏。3.Depthonly只画该层,背景透明与Depth配合使用,等会再写。4.Don'tClear不移除,渲染覆盖不会擦除上一帧的画面,一般不使用。默认二.CullingMask选择性渲染部分层级,可以指定渲染对......
  • HarmonyOS【ArkUI组件--TextInput】
    1.文本输入框基本用法2.使用文本输入框组件(如何实现输入数字改变图片大小)在此博客的基础上继续编写:HarmonyOS【ArkUI组件--Text】-CSDN博客 ①代码如下:importfontfrom'@ohos.font'@Entry@ComponentstructIndex{@StateimageWidth:number=30build()......
  • React+TS前台项目实战(十)-- 全局常用组件CopyText封装
    文章目录前言CopyText组件1.功能分析2.代码+详细注释3.使用方式4.效果展示总结前言今天这篇主要讲项目常用复制文本组件封装,这个组件是一个用于拷贝文本的React组件,它提供了拷贝,国际化和消息提示的功能CopyText组件1.功能分析(1)将content作为其内容,表......
  • [vue3]组件通信
    自定义属性父组件中给子组件绑定属性,传递数据给子组件,子组件通过props选项接收数据props传递的数据,在模版中可以直接使用{{message}},在逻辑中使用props.messagedefinePropsdefineProps是编译器宏函数,就是一个编译阶段的标识,实际编译器解析时,遇到后会进......
  • CLFS驱动程序(clfs.sys)是Windows操作系统中的一个组件,它提供了日志记录和恢复功能,以增
    clfs.sys是Windows操作系统中的一个系统文件,它是CLFS(CommonLogFileSystem)驱动程序的一部分。CLFS是Windows操作系统中用于管理日志文件的文件系统,它提供了日志记录和恢复功能。CLFS驱动程序(clfs.sys)具有以下功能和作用:日志记录:CLFS可以记录系统的操作、事件和错误等信息到......
  • Vue3动态组件的基本用法
     和Vue2动态组件写法不同的是,:is传递的内容需要先定义,再给:is使用<template><div><component:is="currentComponent"></component></div></template><scriptsetup>importMyComponentfrom'./MyComponent.vue';......