lvgl自定义组件

说明

lvgl版本7.11。

1.模板文件

先从lvgl\src\lv_widgets\lv_objx_templ.c复制出lv_objx_templ.clv_objx_templ.h,重命名为你需要创建的组件名称例如lv_objxscrol.clv_objxscrol.h
在这里插入图片描述

2.修改文件

根据提示我们将对应的temp字段替换成我们自己的组件名称。
在这里插入图片描述

2.1全局替换成下面这样

在这里插入图片描述

3.包含头文件

在这里插入图片描述

3.1如下

在这里插入图片描述

4.去掉defined() &&

在这里插入图片描述

5.在文件lvgl\lvgl.h中添加头文件

在这里插入图片描述

6.在文件lv_conf.h中添加#define LV_USE_OBJSCROL 1开启组件功能

在这里插入图片描述

7.添加源文件

目录

gui\lvgl\CMakeLists.txt

在这里插入图片描述

编译问题记录

问题1

在这里插入图片描述
先注释掉,后面用到再改。
在这里插入图片描述

问题2

在这里插入图片描述
注释掉,没有用。
在这里插入图片描述

问题3

在这里插入图片描述
参数不对,注释掉
在这里插入图片描述

问题4

在这里插入图片描述
找到对应函数
在这里插入图片描述
改成
在这里插入图片描述
因为我是打算在创建的页上做扩展。

问题5

在这里插入图片描述
找到对应函数
在这里插入图片描述
改成
在这里插入图片描述
因为在这个版本里是对应的是这个宏。

例 自定义组件lv_scale

需要在配置文件中启用LV_USE_SCALE 宏定义

/**
 * @file lv_scale.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "../lv_misc/lv_debug.h"
#include "lv_scale.h"

#if  LV_USE_SCALE != 0

/*********************
 *      DEFINES
 *********************/
#define LV_OBJX_NAME "lv_scale"

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/
static lv_design_res_t lv_scale_design(lv_obj_t * scale, const lv_area_t * clip_area, lv_design_mode_t mode);
static lv_res_t lv_scale_signal(lv_obj_t * scale, lv_signal_t sign, void * param);

/**********************
 *  STATIC VARIABLES
 **********************/
static lv_signal_cb_t ancestor_signal;
static lv_design_cb_t ancestor_design;

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
 **********************/

/**
 * Create a scalemenu object
 * @param par pointer to an object, it will be the parent of the new scalemenu
 * @param copy pointer to a scalemenu object, if not NULL then the new object will be copied from it
 * @return pointer to the created scalemenu
 */
lv_obj_t * lv_scale_create(lv_obj_t * par, const lv_obj_t * copy)
{
    LV_LOG_TRACE("scalemenu create started");

    /*Create the ancestor of scalemenu*/
    /*TODO modify it to the ancestor create function */
    lv_obj_t * new_scale = lv_cont_create(par, copy);
    LV_ASSERT_MEM(new_scale);
    if(new_scale == NULL) return NULL;

    /*Allocate the scalemenu type specific extended data*/
    lv_scale_ext_t * ext = lv_obj_allocate_ext_attr(new_scale, sizeof(lv_scale_ext_t));
    lv_mem_assert(ext);
    if(ext == NULL) {
        lv_obj_del(new_scale);
        return NULL;
    }

    if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_scale);
    if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(new_scale);

    /*Initialize the allocated 'ext' */


    /*The signal and design functions are not copied so set them here*/
    lv_obj_set_signal_cb(new_scale, lv_scale_signal);
    lv_obj_set_design_cb(new_scale, lv_scale_design);

    /*Init the new scalemenu scalemenu*/
    if(copy == NULL) {

    }
    /*Copy an existing scalemenu*/
    else {
        lv_scale_ext_t * copy_ext = lv_obj_get_ext_attr(copy);

        /*Refresh the style with new signal function*/

    }

    LV_LOG_INFO("scalemenu created");

    return new_scale;
}

/*======================
 * Add/remove functions
 *=====================*/

/*
 * New object specific "add" or "remove" functions come here
 */

/*=====================
 * Setter functions
 *====================*/

/*
 * New object specific "set" functions come here
 */

/**
 * Set a style of a scalemenu.
 * @param scale pointer to scalemenu object
 * @param type which style should be set
 * @param style pointer to a style
 */
void lv_scale_set_style(lv_obj_t * scale, lv_scale_style_t type, const lv_style_t * style)
{
    LV_ASSERT_OBJ(scale, LV_OBJX_NAME);

    lv_scale_ext_t * ext = lv_obj_get_ext_attr(scale);

    switch(type) {
        case LV_SCALE_STYLE_X:
            break;
        case LV_SCALE_STYLE_Y:
            break;
    }
}

/*=====================
 * Getter functions
 *====================*/

/*
 * New object specific "get" functions come here
 */

/**
 * Get style of a scalemenu.
 * @param scale pointer to scalemenu object
 * @param type which style should be get
 * @return style pointer to the style
 */
lv_style_t * lv_scale_get_style(const lv_obj_t * scale, lv_scale_style_t type)
{
    LV_ASSERT_OBJ(scale, LV_OBJX_NAME);

    lv_scale_ext_t * ext = lv_obj_get_ext_attr(scale);
    lv_style_t * style   = NULL;

    switch(type) {
        case LV_SCALE_STYLE_X:
            style = NULL; /*Replace NULL with a pointer to the style*/
        case LV_SCALE_STYLE_Y:
            style = NULL; /*Replace NULL with a pointer to the style*/
        default:
            style = NULL;
    }

    return style;
}

/*=====================
 * Other functions
 *====================*/

/*
 * New object specific "other" functions come here
 */

/**********************
 *   STATIC FUNCTIONS
 **********************/

/**
 * Handle the drawing related tasks of the scalemenus
 * @param scale pointer to an object
 * @param mask the object will be drawn only in this area
 * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
 *                                  (return 'true' if yes)
 *             LV_DESIGN_DRAW: draw the object (always return 'true')
 *             LV_DESIGN_DRAW_POST: drawing after every children are drawn
 * @param return an element of `lv_design_res_t`
 */
static lv_design_res_t lv_scale_design(lv_obj_t * scale, const lv_area_t * clip_area, lv_design_mode_t mode)
{
    /*Return false if the object is not covers the mask_p area*/
    if(mode == LV_DESIGN_COVER_CHK) {
        return LV_DESIGN_RES_NOT_COVER;
    }
    /*Draw the object*/
    else if(mode == LV_DESIGN_DRAW_MAIN) {

    }
    /*Post draw when the children are drawn*/
    else if(mode == LV_DESIGN_DRAW_POST) {
    }

    return LV_DESIGN_RES_OK;
}

/**
 * Signal function of the scalemenu
 * @param scale pointer to a scalemenu object
 * @param sign a signal type from lv_signal_t enum
 * @param param pointer to a signal specific variable
 * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
 */
static lv_res_t lv_scale_signal(lv_obj_t * scale, lv_signal_t sign, void * param)
{
    lv_res_t res;

    /* Include the ancient signal function */
    res = ancestor_signal(scale, sign, param);
    if(res != LV_RES_OK) return res;
    if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);

    if(sign == LV_SIGNAL_CLEANUP) {
        /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
    }

    return res;
}

#else /* Enable this file at the top */

/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif

/**
 * @file lv_scale.h
 *
 */

#ifndef LV_SCALE_H
#define LV_SCALE_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/
#include "../lv_conf_internal.h"

#if LV_USE_SCALE != 0

#include "../lv_core/lv_obj.h"

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/
/*Data of scalemenu*/
typedef struct {
    // lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/
    /*New data for this type */
} lv_scale_ext_t;

/*Styles*/
enum {
    LV_SCALE_STYLE_X,
    LV_SCALE_STYLE_Y,
};
typedef uint8_t lv_scale_style_t;

/**********************
 * GLOBAL PROTOTYPES
 **********************/

/**
 * Create a scalemenu objects
 * @param par pointer to an object, it will be the parent of the new scalemenu
 * @param copy pointer to a scalemenu object, if not NULL then the new object will be copied from it
 * @return pointer to the created scalemenu
 */
lv_obj_t * lv_scale_create(lv_obj_t * par, const lv_obj_t * copy);

/*======================
 * Add/remove functions
 *=====================*/

/*=====================
 * Setter functions
 *====================*/

/**
 * Set a style of a scalemenu.
 * @param scale pointer to scalemenu object
 * @param type which style should be set
 * @param style pointer to a style
 */
void lv_scale_set_style(lv_obj_t * scale, lv_scale_style_t type, const lv_style_t * style);

/*=====================
 * Getter functions
 *====================*/

/**
 * Get style of a scalemenu.
 * @param scale pointer to scalemenu object
 * @param type which style should be get
 * @return style pointer to the style
 */
lv_style_t * lv_scale_get_style(const lv_obj_t * scale, lv_scale_style_t type);

/*=====================
 * Other functions
 *====================*/

/**********************
 *      MACROS
 **********************/

#endif /*LV_USE_SCALE*/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*LV_SCALE_H*/

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Edgeline LVGL是一个开源的图形库,专门用于嵌入式系统中的低功耗设备。LVGL代表"LittlevGL",它是一个轻量级的图形库,旨在提供基本且易于使用的用户界面功能。 Edgeline是一个面向边缘设备的软件解决方案,而LVGL作为其图形库的一部分,为开发者提供了一种在嵌入式设备上创建美观和交互式用户界面的方法。 Edgeline LVGL支持多种平台和操作系统,包括Linux、RTOS和裸机系统。这使得开发人员可以灵活选择适合他们项目的平台,并快速构建功能强大的嵌入式应用程序。 LVGL具有小巧、高效和可定制的特点。它可以在资源受限的设备上运行,并提供丰富的图形元素和交互功能,如按钮、标签、滑块等。开发者可以使用LVGL的API来创建自定义的用户界面,满足特定项目的需求。 另外,Edgeline LVGL还提供了丰富的文档和示例代码,以帮助开发者快速入门和理解其使用方式。开发人员可以轻松地从头开始构建应用程序,也可以使用提供的示例代码作为基础进行二次开发。 总之,Edgeline LVGL嵌入式设备开发者提供了一个强大而灵活的图形库,使他们能够快速构建出色的用户界面,提升产品的用户体验。 ### 回答2: edgeline lvgl是指一种嵌入式图形库,它能够在低端设备上实现高质量的图形用户界面(GUI)。edgeline lvgl嵌入式系统提供了现代化的图形显示能力,包括丰富的图形元素和交互控件。它能够为用户提供直观、易用的界面,使用户能够轻松地与设备进行交互。 edgeline lvgl具有较小的存储空间占用和低功耗需求,适用于低端设备和资源有限的嵌入式系统。它支持各种不同的显示器类型,包括彩色、单色和高分辨率显示器。通过提供丰富的图形绘制和动画效果功能,edgeline lvgl能够为用户提供优秀的视觉体验。 除了基本的图形显示能力,edgeline lvgl还提供了多种交互控件,如按钮、滑块、文本框等,以及各类容器和布局选项,方便用户创建复杂的界面。它还支持触摸屏和鼠标输入,可以实现多点触控和手势识别。通过提供强大的布局功能和自定义样式选项,用户可以轻松地设计和定制自己的界面。 edgeline lvgl具有开放源代码的特点,这意味着用户可以根据自己的需求来修改和定制该库。它还拥有活跃的开发者社区,提供丰富的文档和资源,以及定期的更新和修复。这使得edgeline lvgl成为嵌入式系统开发者的理想选择。总之,edgeline lvgl为低端设备提供了现代化的图形界面解决方案,具有易用性、灵活性和定制性,能够满足不同应用的需求。 ### 回答3: Edgeline LVGL是一个开源的图形化库,专为嵌入式设备设计。它可以将低成本的微控制器与有限的资源结合,提供流畅的图形绘制和用户界面操作。 Edgeline LVGL具有很多特性,使其在嵌入式系统中广泛应用。首先,它具有高性能的图形绘制能力,支持各种图形元素和效果,如直线、矩形、圆形、渐变等,可以满足不同项目的需求。 另外,Edgeline LVGL还拥有灵活的布局管理器和丰富的组件库,可以轻松创建具有复杂布局和功能的用户界面。这些组件包括按钮、文本框、进度条、列表等,可以实现用户与设备的交互操作。 此外,Edgeline LVGL支持多种输入设备,如触摸屏、键盘、鼠标等,使用户可以通过不同的方式与嵌入式设备进行交互。它还提供了事件驱动的机制,可以处理用户的输入操作,并根据不同的事件触发相应的响应。 最重要的是,Edgeline LVGL是一个跨平台的库,可以在不同的操作系统上运行,如Linux、RTOS等。这使得开发人员可以更加灵活地选择合适的平台来开发和部署嵌入式应用程序。 总的来说,Edgeline LVGL是一个功能强大、易于使用且跨平台的图形化库,可以帮助开发人员轻松实现嵌入式设备的图形界面和用户交互。无论是开发工业控制系统、智能家居还是便携式设备,Edgeline LVGL都是一个不错的选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值