• 【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

    1. /**
    2. * Type of event being sent to the object.
    3. */
    4. typedef enum {
    5. LV_EVENT_ALL = 0,
    6. /** Input device events*/
    7. LV_EVENT_PRESSED, /**< The object has been pressed*/
    8. LV_EVENT_PRESSING, /**< The object is being pressed (called continuously while pressing)*/
    9. LV_EVENT_PRESS_LOST, /**< The object is still being pressed but slid cursor/finger off of the object */
    10. LV_EVENT_SHORT_CLICKED, /**< The object was pressed for a short period of time, then released it. Not called if scrolled.*/
    11. LV_EVENT_LONG_PRESSED, /**< Object has been pressed for at least `long_press_time`. Not called if scrolled.*/
    12. LV_EVENT_LONG_PRESSED_REPEAT, /**< Called after `long_press_time` in every `long_press_repeat_time` ms. Not called if scrolled.*/
    13. LV_EVENT_CLICKED, /**< Called on release if not scrolled (regardless to long press)*/
    14. LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/
    15. LV_EVENT_SCROLL_BEGIN, /**< Scrolling begins. The event parameter is a pointer to the animation of the scroll. Can be modified*/
    16. LV_EVENT_SCROLL_END, /**< Scrolling ends*/
    17. LV_EVENT_SCROLL, /**< Scrolling*/
    18. LV_EVENT_GESTURE, /**< A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_get_act());` */
    19. LV_EVENT_KEY, /**< A key is sent to the object. Get the key with `lv_indev_get_key(lv_indev_get_act());`*/
    20. LV_EVENT_FOCUSED, /**< The object is focused*/
    21. LV_EVENT_DEFOCUSED, /**< The object is defocused*/
    22. LV_EVENT_LEAVE, /**< The object is defocused but still selected*/
    23. LV_EVENT_HIT_TEST, /**< Perform advanced hit-testing*/
    24. /** Drawing events*/
    25. LV_EVENT_COVER_CHECK, /**< Check if the object fully covers an area. The event parameter is `lv_cover_check_info_t *`.*/
    26. 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.*/
    27. LV_EVENT_DRAW_MAIN_BEGIN, /**< Starting the main drawing phase*/
    28. LV_EVENT_DRAW_MAIN, /**< Perform the main drawing*/
    29. LV_EVENT_DRAW_MAIN_END, /**< Finishing the main drawing phase*/
    30. LV_EVENT_DRAW_POST_BEGIN, /**< Starting the post draw phase (when all children are drawn)*/
    31. LV_EVENT_DRAW_POST, /**< Perform the post draw phase (when all children are drawn)*/
    32. LV_EVENT_DRAW_POST_END, /**< Finishing the post draw phase (when all children are drawn)*/
    33. LV_EVENT_DRAW_PART_BEGIN, /**< Starting to draw a part. The event parameter is `lv_obj_draw_dsc_t *`. */
    34. LV_EVENT_DRAW_PART_END, /**< Finishing to draw a part. The event parameter is `lv_obj_draw_dsc_t *`. */
    35. /** Special events*/
    36. LV_EVENT_VALUE_CHANGED, /**< The object's value has changed (i.e. slider moved)*/
    37. LV_EVENT_INSERT, /**< A text is inserted to the object. The event data is `char *` being inserted.*/
    38. LV_EVENT_REFRESH, /**< Notify the object to refresh something on it (for the user)*/
    39. LV_EVENT_READY, /**< A process has finished*/
    40. LV_EVENT_CANCEL, /**< A process has been cancelled */
    41. /** Other events*/
    42. LV_EVENT_DELETE, /**< Object is being deleted*/
    43. LV_EVENT_CHILD_CHANGED, /**< Child was removed, added, or its size, position were changed */
    44. LV_EVENT_CHILD_CREATED, /**< Child was created, always bubbles up to all parents*/
    45. LV_EVENT_CHILD_DELETED, /**< Child was deleted, always bubbles up to all parents*/
    46. LV_EVENT_SCREEN_UNLOAD_START, /**< A screen unload started, fired immediately when scr_load is called*/
    47. LV_EVENT_SCREEN_LOAD_START, /**< A screen load started, fired when the screen change delay is expired*/
    48. LV_EVENT_SCREEN_LOADED, /**< A screen was loaded*/
    49. LV_EVENT_SCREEN_UNLOADED, /**< A screen was unloaded*/
    50. LV_EVENT_SIZE_CHANGED, /**< Object coordinates/size have changed*/
    51. LV_EVENT_STYLE_CHANGED, /**< Object's style has changed*/
    52. LV_EVENT_LAYOUT_CHANGED, /**< The children position has changed due to a layout recalculation*/
    53. LV_EVENT_GET_SELF_SIZE, /**< Get the internal size of a widget*/
    54. _LV_EVENT_LAST, /** Number of default events*/
    55. LV_EVENT_PREPROCESS = 0x80, /** This is a flag that can be set with an event so it's processed
    56. before the class default event processing */
    57. } lv_event_code_t;

     输入设备事件

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

    绘图事件

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

    其他事件

    1. /** 其他事件 */
    2. LV_EVENT_DELETE, /**< 对象正在被删除 */
    3. LV_EVENT_CHILD_CHANGED, /**< 子对象正在被移除/添加,位置/大小正在被改变 */
    4. LV_EVENT_CHILD_CREATED, /**< 子对象被创建,对所有父对象冒泡 */
    5. LV_EVENT_CHILD_DELETED, /**< 子对象被删除,对所有父对象冒泡 */
    6. LV_EVENT_SCREEN_UNLOAD_START, /**< 屏幕卸载开始,在调用 lv_scr_load/lv_scr_load_anim 时立即触发 */
    7. LV_EVENT_SCREEN_LOAD_START, /**< 屏幕加载开始, 当屏幕更改延迟到期时触发 */
    8. LV_EVENT_SCREEN_LOADED, /**< 加载屏幕,当所有动画完成时调用 */
    9. LV_EVENT_SCREEN_UNLOADED, /**< 卸载屏幕,当所有动画完成时调用 */
    10. LV_EVENT_SIZE_CHANGED, /**< 对象的坐标/大小被改变 */
    11. LV_EVENT_STYLE_CHANGED, /**< 对象样式被改变 */
    12. LV_EVENT_LAYOUT_CHANGED, /**< 由布局计算的对象的位置被改变 */
    13. 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获取部件内部大小

    特殊事件

    1. /** Special events*/
    2. LV_EVENT_VALUE_CHANGED, /**< 对象的值被更改 (i.e. 滑块移动) */
    3. LV_EVENT_INSERT, /**< 文本被插入对象中。事件被插入的数据为char * 。*/
    4. LV_EVENT_REFRESH, /**< 通知对象刷新其上的显示 (对于用户) */
    5. LV_EVENT_READY, /**< 一个进程已完成 */
    6. 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 :让用户使用它通知对象刷新

    自定义事件

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

    1. uint32_t = lv_event_register_id();
    2. /* example: */
    3. uint32_t USER_Event_ONE = lv_event_register_id();

    发送事件

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

    lv_event_send(obj,  &some_data).

    回调参数

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

    1. typedef struct _lv_event_t {
    2. struct _lv_obj_t * target;
    3. struct _lv_obj_t * current_target;
    4. lv_event_code_t code;
    5. void * user_data;
    6. void * param;
    7. struct _lv_event_t * prev;
    8. uint8_t deleted : 1;
    9. uint8_t stop_processing : 1;
    10. uint8_t stop_bubbling : 1;
    11. } lv_event_t;

    有关 lv_event_t 的函数

    1. /* 获取事件代码 */
    2. lv_event_get_code(e)
    3. /* 获取发送事件的对象 */
    4. lv_event_get_current_target(e)
    5. /* 获取最初触发事件的对象,冒泡相关 */
    6. lv_event_get_target(e)
    7. /* 获取作为最后一个参数传递的指针 */
    8. lv_event_get_user_data(e)
    9. /* 获取作为最后一个参数传递的参数 */
    10. lv_event_get_param(e)

    事件冒泡

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

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

  • 相关阅读:
    队列的实现
    新需求:实现一个自动运维部署工具
    编程挑战赛第六期我带我的小侄子来了【赛题解析】
    拉格朗日插值法(理论详解)
    面试题: LEAD 和 LAG 求每个用户的页面停留时长
    从互联网大厂生态长出的新业务:网易智企要做“卖水人”?
    大数据的技术运用:探索未来的无限可能性
    【Java 进阶篇】JDBC 数据库连接池详解
    利用Python+阿里云实现DDNS(动态域名解析)
    Zfile-轻量开源个人网盘【超简单部署】
  • 原文地址:https://blog.csdn.net/qq_41650023/article/details/125991887