【LVGL事件(Events)】事件代码

点击、滑动、输入、数字改变等等都可触发事件。事件就是针对不同的操作做出相对应的反应。

最近看到组态屏,这玩意开发起来好像挺简单的!!哈哈哈!!研究完LVGL的事件就看看这个。

【LVGL(4)】对象的事件及事件冒泡_喜暖知寒的博客对象的事件及事件冒泡,对象的事件就是不同事件调用不同的功能实现代码呗 ~https://blog.csdn.net/qq_41650023/article/details/125260000

【LVGL事件(Events)】事件代码_喜暖知寒的博客LVGL的事件代码介绍https://blog.csdn.net/qq_41650023/article/details/125991887

【LVGL事件(Events)】事件在不同组件上的应用(一)_喜暖知寒的博客圆弧、滑块、复选框、下拉列表的读取其值的API。https://blog.csdn.net/qq_41650023/article/details/125981209


首先声明:本文章是自己备查所用!难免会有疏忽!


事件代码

官方给事件分了几个组:

  • Input device events(输入设备)
  • Drawing events(绘图)
  • Other events(其他)
  • Special events(特殊)
  • Custom events(用户自定义)

All objects (such as Buttons/Labels/Sliders etc.) regardless their type receive the Input device, Drawing and Other events.

所有对象(按钮、标签、滑块等)都会接收 Input device、Drawing、Other 事件。

However, the Special events are specific to a particular widget type.

特殊事件用于特定的小部件。

事件的源代码

路径:lvgl\src\core\lv_event.h

/**
 * Type of event being sent to the object.
 */
typedef enum {
    LV_EVENT_ALL = 0,

    /** Input device events*/
    LV_EVENT_PRESSED,             /**< The object has been pressed*/
    LV_EVENT_PRESSING,            /**< The object is being pressed (called continuously while pressing)*/
    LV_EVENT_PRESS_LOST,          /**< The object is still being pressed but slid cursor/finger off of the object */
    LV_EVENT_SHORT_CLICKED,       /**< The object was pressed for a short period of time, then released it. Not called if scrolled.*/
    LV_EVENT_LONG_PRESSED,        /**< Object has been pressed for at least `long_press_time`.  Not called if scrolled.*/
    LV_EVENT_LONG_PRESSED_REPEAT, /**< Called after `long_press_time` in every `long_press_repeat_time` ms.  Not called if scrolled.*/
    LV_EVENT_CLICKED,             /**< Called on release if not scrolled (regardless to long press)*/
    LV_EVENT_RELEASED,            /**< Called in every cases when the object has been released*/
    LV_EVENT_SCROLL_BEGIN,        /**< Scrolling begins. The event parameter is a pointer to the animation of the scroll. Can be modified*/
    LV_EVENT_SCROLL_END,          /**< Scrolling ends*/
    LV_EVENT_SCROLL,              /**< Scrolling*/
    LV_EVENT_GESTURE,             /**< A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_get_act());` */
    LV_EVENT_KEY,                 /**< A key is sent to the object. Get the key with `lv_indev_get_key(lv_indev_get_act());`*/
    LV_EVENT_FOCUSED,             /**< The object is focused*/
    LV_EVENT_DEFOCUSED,           /**< The object is defocused*/
    LV_EVENT_LEAVE,               /**< The object is defocused but still selected*/
    LV_EVENT_HIT_TEST,            /**< Perform advanced hit-testing*/

    /** Drawing events*/
    LV_EVENT_COVER_CHECK,        /**< Check if the object fully covers an area. The event parameter is `lv_cover_check_info_t *`.*/
    LV_EVENT_REFR_EXT_DRAW_SIZE, /**< Get the required extra draw area around the object (e.g. for shadow). The event parameter is `lv_coord_t *` to store the size.*/
    LV_EVENT_DRAW_MAIN_BEGIN,    /**< Starting the main drawing phase*/
    LV_EVENT_DRAW_MAIN,          /**< Perform the main drawing*/
    LV_EVENT_DRAW_MAIN_END,      /**< Finishing the main drawing phase*/
    LV_EVENT_DRAW_POST_BEGIN,    /**< Starting the post draw phase (when all children are drawn)*/
    LV_EVENT_DRAW_POST,          /**< Perform the post draw phase (when all children are drawn)*/
    LV_EVENT_DRAW_POST_END,      /**< Finishing the post draw phase (when all children are drawn)*/
    LV_EVENT_DRAW_PART_BEGIN,    /**< Starting to draw a part. The event parameter is `lv_obj_draw_dsc_t *`. */
    LV_EVENT_DRAW_PART_END,      /**< Finishing to draw a part. The event parameter is `lv_obj_draw_dsc_t *`. */

    /** Special events*/
    LV_EVENT_VALUE_CHANGED,       /**< The object's value has changed (i.e. slider moved)*/
    LV_EVENT_INSERT,              /**< A text is inserted to the object. The event data is `char *` being inserted.*/
    LV_EVENT_REFRESH,             /**< Notify the object to refresh something on it (for the user)*/
    LV_EVENT_READY,               /**< A process has finished*/
    LV_EVENT_CANCEL,              /**< A process has been cancelled */

    /** Other events*/
    LV_EVENT_DELETE,              /**< Object is being deleted*/
    LV_EVENT_CHILD_CHANGED,       /**< Child was removed, added, or its size, position were changed */
    LV_EVENT_CHILD_CREATED,       /**< Child was created, always bubbles up to all parents*/
    LV_EVENT_CHILD_DELETED,       /**< Child was deleted, always bubbles up to all parents*/
    LV_EVENT_SCREEN_UNLOAD_START, /**< A screen unload started, fired immediately when scr_load is called*/
    LV_EVENT_SCREEN_LOAD_START,   /**< A screen load started, fired when the screen change delay is expired*/
    LV_EVENT_SCREEN_LOADED,       /**< A screen was loaded*/
    LV_EVENT_SCREEN_UNLOADED,     /**< A screen was unloaded*/
    LV_EVENT_SIZE_CHANGED,        /**< Object coordinates/size have changed*/
    LV_EVENT_STYLE_CHANGED,       /**< Object's style has changed*/
    LV_EVENT_LAYOUT_CHANGED,      /**< The children position has changed due to a layout recalculation*/
    LV_EVENT_GET_SELF_SIZE,       /**< Get the internal size of a widget*/

    _LV_EVENT_LAST,               /** Number of default events*/


    LV_EVENT_PREPROCESS = 0x80,   /** This is a flag that can be set with an event so it's processed
                                      before the class default event processing */
} lv_event_code_t;

 输入设备事件

 /** 输入设备事件 */
LV_EVENT_PRESSED,             /**< 对象被按下 */
LV_EVENT_PRESSING,            /**< 对象被按下 (按下时连续调用) */
LV_EVENT_PRESS_LOST,          /**< 对象仍被按下,但光标/手指滑离对象 */
LV_EVENT_SHORT_CLICKED,       /**< 对象被按下一小段时间后释放,如果滚动则不调用 */
LV_EVENT_LONG_PRESSED,        /**< 对象至少被按下long_press_time(在输入设备驱动程序中指定),如果滚动则不调用 */
LV_EVENT_LONG_PRESSED_REPEAT, /**< 在每个long_press_repeat_time毫秒的mslong_press_time之后调用,如果滚动则不调用 */
LV_EVENT_CLICKED,             /**< 如果对象没有滚动,则在释放时调用 (无论长短按) */
LV_EVENT_RELEASED,            /**< 对象被释放就调用 */
LV_EVENT_SCROLL_BEGIN,        /**< 开始滚动。事件参数是NULL或者lv_anim_t *,可以修改*/
LV_EVENT_SCROLL_END,          /**< 滚动结束 */
LV_EVENT_SCROLL,              /**< 滚动 */
LV_EVENT_GESTURE,             /**< 检测到手势。通过 lv_indev_get_gesture_dir(lv_indev_get_act());获取 */
LV_EVENT_KEY,                 /**< KEY被发送到对象. 通过 lv_indev_get_key(lv_indev_get_act());获取秘钥 */
LV_EVENT_FOCUSED,             /**< 对象被聚焦 */
LV_EVENT_DEFOCUSED,           /**< 对象取消聚焦 */
LV_EVENT_LEAVE,               /**< 对象未聚焦但仍被选中 */
LV_EVENT_HIT_TEST,            /**< 执行高级命中测试 (详细看手册) */
  • LV_EVENT_PRESSED对象被按下
  • LV_EVENT_PRESSING对象被按下 (按下时连续调用)
  • LV_EVENT_PRESS_LOST对象仍被按下,但光标/手指滑离对象
  • LV_EVENT_SHORT_CLICKED对象被按下一小段时间后释放,如果滚动则不调用
  • LV_EVENT_LONG_PRESSED对象至少被按下long_press_time(在输入设备驱动程序中指定),如果滚动则不调用
  • LV_EVENT_LONG_PRESSED_REPEAT在每个long_press_repeat_time毫秒的mslong_press_time之后调用,如果滚动则不调用
  • LV_EVENT_CLICKED如果对象没有滚动,则在释放时调用 (无论长短按)
  • LV_EVENT_RELEASED对象被释放就调用
  • LV_EVENT_SCROLL_BEGIN开始滚动。事件参数是NULL或者lv_anim_t *,可以修改
  • LV_EVENT_SCROLL_END滚动结束
  • LV_EVENT_SCROLL滚动
  • LV_EVENT_GESTURE检测到手势。lv_indev_get_gesture_dir(lv_indev_get_act());获取手势
  • LV_EVENT_KEYKEY被发送到对象. 通过 lv_indev_get_key(lv_indev_get_act());获取秘钥
  • LV_EVENT_FOCUSED对象被聚焦
  • LV_EVENT_DEFOCUSED对象取消聚焦
  • LV_EVENT_LEAVE对象未聚焦但仍被选中
  • LV_EVENT_HIT_TEST执行高级命中测试 (详细看手册)

绘图事件

/** 绘图事件 */
LV_EVENT_COVER_CHECK,        /**< 检测对象是否完全覆盖了一个区域。 事件参数是 lv_cover_check_info_t * 。*/
LV_EVENT_REFR_EXT_DRAW_SIZE, /**< 获取对象周围所需的额外绘制区域 (e.g. 阴影)。用来存储大小的事件参数是 lv_coord_t * 。*/
LV_EVENT_DRAW_MAIN_BEGIN,    /**< 开始主要绘图阶段 */
LV_EVENT_DRAW_MAIN,          /**< 执行主要绘图 */
LV_EVENT_DRAW_MAIN_END,      /**< 完成主要绘图阶段 */
LV_EVENT_DRAW_POST_BEGIN,    /**< 开始后期绘图阶段 (当所有子对象被绘制时)*/
LV_EVENT_DRAW_POST,          /**< 执行后期绘图 (当所有子对象被绘制时)*/
LV_EVENT_DRAW_POST_END,      /**< 完成后期绘图阶段 (当所有子对象被绘制时)*/
LV_EVENT_DRAW_PART_BEGIN,    /**< 开始部分绘图。事件参数是 lv_obj_draw_dsc_t * 。 */
LV_EVENT_DRAW_PART_END,      /**< 完成部分绘图。事件参数是 lv_obj_draw_dsc_t * 。 */
  • LV_EVENT_COVER_CHECK检测对象是否完全覆盖了一个区域。 事件参数是 lv_cover_check_info_t * 。
  • LV_EVENT_REFR_EXT_DRAW_SIZE获取对象周围所需的额外绘制区域 (e.g. 阴影)。用来存储大小的事件参数是 lv_coord_t * 。
  • LV_EVENT_DRAW_MAIN_BEGIN开始主要绘图阶段
  • LV_EVENT_DRAW_MAIN执行主要绘图
  • LV_EVENT_DRAW_MAIN_END完成主要绘图阶段
  • LV_EVENT_DRAW_POST_BEGIN开始后期绘图阶段 (当所有子对象被绘制时)
  • LV_EVENT_DRAW_POST执行后期绘图 (当所有子对象被绘制时)
  • LV_EVENT_DRAW_POST_END完成后期绘图阶段 (当所有子对象被绘制时)
  • LV_EVENT_DRAW_PART_BEGIN开始部分绘图。事件参数是 lv_obj_draw_dsc_t * 。
  • LV_EVENT_DRAW_PART_END完成部分绘图。事件参数是 lv_obj_draw_dsc_t * 。

其他事件

 /** 其他事件 */
LV_EVENT_DELETE,              /**< 对象正在被删除 */
LV_EVENT_CHILD_CHANGED,       /**< 子对象正在被移除/添加,位置/大小正在被改变 */
LV_EVENT_CHILD_CREATED,       /**< 子对象被创建,对所有父对象冒泡 */
LV_EVENT_CHILD_DELETED,       /**< 子对象被删除,对所有父对象冒泡 */
LV_EVENT_SCREEN_UNLOAD_START, /**< 屏幕卸载开始,在调用 lv_scr_load/lv_scr_load_anim 时立即触发 */
LV_EVENT_SCREEN_LOAD_START,   /**< 屏幕加载开始, 当屏幕更改延迟到期时触发 */
LV_EVENT_SCREEN_LOADED,       /**< 加载屏幕,当所有动画完成时调用 */
LV_EVENT_SCREEN_UNLOADED,     /**< 卸载屏幕,当所有动画完成时调用 */
LV_EVENT_SIZE_CHANGED,        /**< 对象的坐标/大小被改变 */
LV_EVENT_STYLE_CHANGED,       /**< 对象样式被改变 */
LV_EVENT_LAYOUT_CHANGED,      /**< 由布局计算的对象的位置被改变 */
LV_EVENT_GET_SELF_SIZE,       /**< 获取部件内部大小 */
  • LV_EVENT_DELETE对象正在被删除
  • LV_EVENT_CHILD_CHANGED子对象正在被移除/添加,位置/大小正在被改变
  • LV_EVENT_CHILD_CREATED子对象被创建,对所有父对象冒泡
  • LV_EVENT_CHILD_DELETED子对象被删除,对所有父对象冒泡
  • LV_EVENT_SCREEN_UNLOAD_START屏幕卸载开始,在调用 lv_scr_load/lv_scr_load_anim 时立即触发
  • LV_EVENT_SCREEN_LOAD_START屏幕加载开始, 当屏幕更改延迟到期时触发
  • LV_EVENT_SCREEN_LOADED加载屏幕,当所有动画完成时调用
  • LV_EVENT_SCREEN_UNLOADED卸载屏幕,当所有动画完成时调用
  • LV_EVENT_SIZE_CHANGED对象的坐标/大小被改变
  • LV_EVENT_STYLE_CHANGED对象样式被改变
  • LV_EVENT_LAYOUT_CHANGED由布局计算的对象的位置被改变
  • LV_EVENT_GET_SELF_SIZE获取部件内部大小

特殊事件

/** Special events*/
LV_EVENT_VALUE_CHANGED,       /**< 对象的值被更改 (i.e. 滑块移动) */
LV_EVENT_INSERT,              /**< 文本被插入对象中。事件被插入的数据为char * 。*/
LV_EVENT_REFRESH,             /**< 通知对象刷新其上的显示 (对于用户) */
LV_EVENT_READY,               /**< 一个进程已完成 */
LV_EVENT_CANCEL,              /**< 一个进程被取消 */
  • LV_EVENT_VALUE_CHANGED对象的值被更改 (i.e. 滑块移动)
  • LV_EVENT_INSERT文本被插入对象中。事件被插入的数据为char * 。
  • LV_EVENT_REFRESH通知对象刷新其上的显示 (对于用户)
  • LV_EVENT_READY一个进程已完成
  • LV_EVENT_CANCEL一个进程被取消

LV_EVENT_REFRESH :让用户使用它通知对象刷新

自定义事件

任何自定义事件代码都可以通过下面函数注册

uint32_t <EVENT_CODE> = lv_event_register_id();
/* example: */
uint32_t USER_Event_ONE = lv_event_register_id();

发送事件

手动发送事件(包括自定义事件):

lv_event_send(obj, <EVENT_CODE> &some_data).

回调参数

lv_event_t 是传递给事件回调的唯一参数!包含所有数据。

typedef struct _lv_event_t {
    struct _lv_obj_t * target;
    struct _lv_obj_t * current_target;
    lv_event_code_t code;
    void * user_data;
    void * param;
    struct _lv_event_t * prev;
    uint8_t deleted : 1;
    uint8_t stop_processing : 1;
    uint8_t stop_bubbling : 1;
} lv_event_t;

有关 lv_event_t 的函数

/* 获取事件代码 */
lv_event_get_code(e)
/* 获取发送事件的对象 */
lv_event_get_current_target(e)
/* 获取最初触发事件的对象,冒泡相关 */
lv_event_get_target(e)
/* 获取作为最后一个参数传递的指针 */
lv_event_get_user_data(e)
/* 获取作为最后一个参数传递的参数 */
lv_event_get_param(e)

事件冒泡

 对象的事件及事件冒泡 文章中做了详细介绍!

后续项目如用到其他会继续更新!!

猜你喜欢

转载自blog.csdn.net/qq_41650023/article/details/125991887