「App:Library:LVGL:docs:Overview:Events」の版間の差分
13行目: | 13行目: | ||
* has its value changed | * has its value changed | ||
* is redrawn, etc. | * is redrawn, etc. | ||
− | | | + | |LVGLでは、ユーザが興味を持ちそうなことが起こったときに、イベントが発生します。 |
+ | |||
+ | * クリックされたとき | ||
+ | * スクロールされたとき | ||
+ | * その値が変更されたとき | ||
+ | * 再描画されたとき、など | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
24行目: | 29行目: | ||
|- | |- | ||
| | | | ||
− | The user can assign callback functions to an object to see its events. In practice, it looks like this: | + | The user can assign callback functions to an object to see its events. |
+ | |||
+ | In practice, it looks like this: | ||
lv_obj_t * btn = lv_btn_create(lv_scr_act()); | lv_obj_t * btn = lv_btn_create(lv_scr_act()); | ||
<syntaxhighlight lang="C++" style="border:1px dashed gray;"> | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
36行目: | 43行目: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | In the example <code style="color: #bb0000;">LV_EVENT_CLICKED</code> means that only the click event will call <code style="color: #bb0000;">my_event_cb</code>. See the list of event codes for all the options. <code style="color: #bb0000;">LV_EVENT_ALL</code> can be used to receive all events. | + | In the example <code style="color: #bb0000;">LV_EVENT_CLICKED</code> means that only the click event will call <code style="color: #bb0000;">my_event_cb</code>. |
+ | |||
+ | See the list of event codes for all the options. | ||
+ | |||
+ | <code style="color: #bb0000;">LV_EVENT_ALL</code> can be used to receive all events. | ||
+ | |||
+ | |||
+ | The last parameter of <code style="color: #bb0000;">lv_obj_add_event_cb</code> is a pointer to any custom data that will be available in the event. | ||
+ | |||
+ | It will be described later in more detail. | ||
+ | |||
+ | More events can be added to an object, like this: | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
+ | lv_obj_add_event_cb(obj, my_event_cb_1, LV_EVENT_CLICKED, NULL); | ||
+ | lv_obj_add_event_cb(obj, my_event_cb_2, LV_EVENT_PRESSED, NULL); | ||
+ | lv_obj_add_event_cb(obj, my_event_cb_3, LV_EVENT_ALL, NULL); /*No filtering, receive all events*/ | ||
+ | </syntaxhighlight> | ||
+ | Even the same event callback can be used on an object with different <code style="color: #bb0000;">user_data</code>. For example: | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
+ | lv_obj_add_event_cb(obj, increment_on_click, LV_EVENT_CLICKED, &num1); | ||
+ | lv_obj_add_event_cb(obj, increment_on_click, LV_EVENT_CLICKED, &num2); | ||
+ | </syntaxhighlight> | ||
+ | The events will be called in the order as they were added. | ||
+ | |||
+ | Other objects can use the same ''event callback''. | ||
+ | |ユーザーは、オブジェクトにコールバック関数を割り当てて、そのイベントを確認することができます。 | ||
+ | |||
+ | 実際には、以下のような感じです。 | ||
+ | lv_obj_t * btn = lv_btn_create(lv_scr_act()); | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
+ | lv_obj_add_event_cb(btn, my_event_cb, LV_EVENT_CLICKED, NULL); /*Assign an event callback*/ | ||
+ | |||
+ | ... | ||
+ | |||
+ | static void my_event_cb(lv_event_t * event) | ||
+ | { | ||
+ | printf("Clicked\n"); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | In the example <code style="color: #bb0000;">LV_EVENT_CLICKED</code> means that only the click event will call <code style="color: #bb0000;">my_event_cb</code>. | ||
+ | |||
+ | See the list of event codes for all the options. | ||
+ | |||
+ | <code style="color: #bb0000;">LV_EVENT_ALL</code> can be used to receive all events. | ||
+ | |||
+ | |||
+ | The last parameter of <code style="color: #bb0000;">lv_obj_add_event_cb</code> is a pointer to any custom data that will be available in the event. | ||
+ | |||
+ | It will be described later in more detail. | ||
− | |||
More events can be added to an object, like this: | More events can be added to an object, like this: | ||
54行目: | 108行目: | ||
Other objects can use the same ''event callback''. | Other objects can use the same ''event callback''. | ||
− | |||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
66行目: | 119行目: | ||
| | | | ||
Events can be removed from an object with the <code style="color: #bb0000;">lv_obj_remove_event_cb(obj, event_cb)</code> function or <code style="color: #bb0000;">lv_obj_remove_event_dsc(obj, event_dsc)</code>. <code style="color: #bb0000;">event_dsc</code> is a pointer returned by <code style="color: #bb0000;">lv_obj_add_event_cb</code>. | Events can be removed from an object with the <code style="color: #bb0000;">lv_obj_remove_event_cb(obj, event_cb)</code> function or <code style="color: #bb0000;">lv_obj_remove_event_dsc(obj, event_dsc)</code>. <code style="color: #bb0000;">event_dsc</code> is a pointer returned by <code style="color: #bb0000;">lv_obj_add_event_cb</code>. | ||
− | | | + | |Events can be removed from an object with the <code style="color: #bb0000;">lv_obj_remove_event_cb(obj, event_cb)</code> function or <code style="color: #bb0000;">lv_obj_remove_event_dsc(obj, event_dsc)</code>. <code style="color: #bb0000;">event_dsc</code> is a pointer returned by <code style="color: #bb0000;">lv_obj_add_event_cb</code>. |
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
92行目: | 145行目: | ||
The following event codes exist: | The following event codes exist: | ||
− | | | + | |The event codes can be grouped into these categories: |
+ | |||
+ | * 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. | ||
+ | |||
+ | However, the ''Special events'' are specific to a particular widget type. See the widgets' documentation to learn when they are sent, | ||
+ | |||
+ | ''Custom events'' are added by the user and are never sent by LVGL. | ||
+ | |||
+ | The following event codes exist: | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
121行目: | 188行目: | ||
* <code style="color: #bb0000;">LV_EVENT_HIT_TEST</code> Perform advanced hit-testing. Use <code style="color: #bb0000;">lv_hit_test_info_t * a = lv_event_get_hit_test_info(e)</code> and check if <code style="color: #bb0000;">a->point</code> can click the object or not. If not set <code style="color: #bb0000;">a->res = false</code> | * <code style="color: #bb0000;">LV_EVENT_HIT_TEST</code> Perform advanced hit-testing. Use <code style="color: #bb0000;">lv_hit_test_info_t * a = lv_event_get_hit_test_info(e)</code> and check if <code style="color: #bb0000;">a->point</code> can click the object or not. If not set <code style="color: #bb0000;">a->res = false</code> | ||
| | | | ||
+ | *<code style="color: #bb0000;">LV_EVENT_PRESSED</code> An object has been pressed | ||
+ | *<code style="color: #bb0000;">LV_EVENT_PRESSING</code> An object is being pressed (called continuously while pressing) | ||
+ | *<code style="color: #bb0000;">LV_EVENT_PRESS_LOST</code> An object is still being pressed but slid cursor/finger off of the object | ||
+ | *<code style="color: #bb0000;">LV_EVENT_SHORT_CLICKED</code> An object was pressed for a short period of time, then released. Not called if scrolled. | ||
+ | *<code style="color: #bb0000;">LV_EVENT_LONG_PRESSED</code> An object has been pressed for at least the <code style="color: #bb0000;">long_press_time</code> specified in the input device driver. Not called if scrolled. | ||
+ | *<code style="color: #bb0000;">LV_EVENT_LONG_PRESSED_REPEAT</code> Called after <code style="color: #bb0000;">long_press_time</code> in every <code style="color: #bb0000;">long_press_repeat_time</code> ms. Not called if scrolled. | ||
+ | *<code style="color: #bb0000;">LV_EVENT_CLICKED</code> Called on release if an object did not scroll (regardless of long press) | ||
+ | *<code style="color: #bb0000;">LV_EVENT_RELEASED</code> Called in every case when an object has been released | ||
+ | *<code style="color: #bb0000;">LV_EVENT_SCROLL_BEGIN</code> Scrolling begins. The event parameter is <code style="color: #bb0000;">NULL</code> or an <code style="color: #bb0000;">lv_anim_t *</code> with a scroll animation descriptor that can be modified if required. | ||
+ | *<code style="color: #bb0000;">LV_EVENT_SCROLL_END</code> Scrolling ends. | ||
+ | *<code style="color: #bb0000;">LV_EVENT_SCROLL</code> An object was scrolled | ||
+ | *<code style="color: #bb0000;">LV_EVENT_GESTURE</code> A gesture is detected. Get the gesture with <code style="color: #bb0000;">lv_indev_get_gesture_dir(lv_indev_get_act());</code> | ||
+ | *<code style="color: #bb0000;">LV_EVENT_KEY</code> A key is sent to an object. Get the key with <code style="color: #bb0000;">lv_indev_get_key(lv_indev_get_act());</code> | ||
+ | *<code style="color: #bb0000;">LV_EVENT_FOCUSED</code> An object is focused | ||
+ | *<code style="color: #bb0000;">LV_EVENT_DEFOCUSED</code> An object is unfocused | ||
+ | *<code style="color: #bb0000;">LV_EVENT_LEAVE</code> An object is unfocused but still selected | ||
+ | *<code style="color: #bb0000;">LV_EVENT_HIT_TEST</code> Perform advanced hit-testing. Use <code style="color: #bb0000;">lv_hit_test_info_t * a = lv_event_get_hit_test_info(e)</code> and check if <code style="color: #bb0000;">a->point</code> can click the object or not. If not set <code style="color: #bb0000;">a->res = false</code> | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
144行目: | 228行目: | ||
In <code style="color: #bb0000;">LV_EVENT_DRAW_...</code> events it's not allowed to adjust the widgets' properties. E.g. you can not call <code style="color: #bb0000;">lv_obj_set_width()</code>. In other words only <code style="color: #bb0000;">get</code> functions can be called. | In <code style="color: #bb0000;">LV_EVENT_DRAW_...</code> events it's not allowed to adjust the widgets' properties. E.g. you can not call <code style="color: #bb0000;">lv_obj_set_width()</code>. In other words only <code style="color: #bb0000;">get</code> functions can be called. | ||
| | | | ||
+ | *<code style="color: #bb0000;">LV_EVENT_COVER_CHECK</code> Check if an object fully covers an area. The event parameter is <code style="color: #bb0000;">lv_cover_check_info_t *</code>. | ||
+ | *<code style="color: #bb0000;">LV_EVENT_REFR_EXT_DRAW_SIZE</code> Get the required extra draw area around an object (e.g. for a shadow). The event parameter is <code style="color: #bb0000;">lv_coord_t *</code> to store the size. Only overwrite it with a larger value. | ||
+ | *<code style="color: #bb0000;">LV_EVENT_DRAW_MAIN_BEGIN</code> Starting the main drawing phase. | ||
+ | *<code style="color: #bb0000;">LV_EVENT_DRAW_MAIN</code> Perform the main drawing | ||
+ | *<code style="color: #bb0000;">LV_EVENT_DRAW_MAIN_END</code> Finishing the main drawing phase | ||
+ | *<code style="color: #bb0000;">LV_EVENT_DRAW_POST_BEGIN</code> Starting the post draw phase (when all children are drawn) | ||
+ | *<code style="color: #bb0000;">LV_EVENT_DRAW_POST</code> Perform the post draw phase (when all children are drawn) | ||
+ | *<code style="color: #bb0000;">LV_EVENT_DRAW_POST_END</code> Finishing the post draw phase (when all children are drawn) | ||
+ | *<code style="color: #bb0000;">LV_EVENT_DRAW_PART_BEGIN</code> Starting to draw a part. The event parameter is <code style="color: #bb0000;">lv_obj_draw_dsc_t *</code>. Learn more here. | ||
+ | *<code style="color: #bb0000;">LV_EVENT_DRAW_PART_END</code> Finishing to draw a part. The event parameter is <code style="color: #bb0000;">lv_obj_draw_dsc_t *</code>. Learn more here. | ||
+ | |||
+ | In <code style="color: #bb0000;">LV_EVENT_DRAW_...</code> events it's not allowed to adjust the widgets' properties. E.g. you can not call <code style="color: #bb0000;">lv_obj_set_width()</code>. In other words only <code style="color: #bb0000;">get</code> functions can be called. | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
167行目: | 263行目: | ||
* <code style="color: #bb0000;">LV_EVENT_SCREEN_UNLOADED</code> A screen was unloaded, called when all animations are finished | * <code style="color: #bb0000;">LV_EVENT_SCREEN_UNLOADED</code> A screen was unloaded, called when all animations are finished | ||
| | | | ||
+ | *<code style="color: #bb0000;">LV_EVENT_DELETE</code> Object is being deleted | ||
+ | *<code style="color: #bb0000;">LV_EVENT_CHILD_CHANGED</code> Child was removed/added | ||
+ | *<code style="color: #bb0000;">LV_EVENT_CHILD_CREATED</code> Child was created, always bubbles up to all parents | ||
+ | *<code style="color: #bb0000;">LV_EVENT_CHILD_DELETED</code> Child was deleted, always bubbles up to all parents | ||
+ | *<code style="color: #bb0000;">LV_EVENT_SIZE_CHANGED</code> Object coordinates/size have changed | ||
+ | *<code style="color: #bb0000;">LV_EVENT_STYLE_CHANGED</code> Object's style has changed | ||
+ | *<code style="color: #bb0000;">LV_EVENT_BASE_DIR_CHANGED</code> The base dir has changed | ||
+ | *<code style="color: #bb0000;">LV_EVENT_GET_SELF_SIZE</code> Get the internal size of a widget | ||
+ | *<code style="color: #bb0000;">LV_EVENT_SCREEN_UNLOAD_START</code> A screen unload started, fired immediately when lv_scr_load/lv_scr_load_anim is called | ||
+ | *<code style="color: #bb0000;">LV_EVENT_SCREEN_LOAD_START</code> A screen load started, fired when the screen change delay is expired | ||
+ | *<code style="color: #bb0000;">LV_EVENT_SCREEN_LOADED</code> A screen was loaded, called when all animations are finished | ||
+ | *<code style="color: #bb0000;">LV_EVENT_SCREEN_UNLOADED</code> A screen was unloaded, called when all animations are finished | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
183行目: | 291行目: | ||
* <code style="color: #bb0000;">LV_EVENT_CANCEL</code> A process has been canceled | * <code style="color: #bb0000;">LV_EVENT_CANCEL</code> A process has been canceled | ||
| | | | ||
+ | *<code style="color: #bb0000;">LV_EVENT_VALUE_CHANGED</code> The object's value has changed (i.e. slider moved) | ||
+ | *<code style="color: #bb0000;">LV_EVENT_INSERT</code> Text is being inserted into the object. The event data is <code style="color: #bb0000;">char *</code> being inserted. | ||
+ | *<code style="color: #bb0000;">LV_EVENT_REFRESH</code> Notify the object to refresh something on it (for the user) | ||
+ | *<code style="color: #bb0000;">LV_EVENT_READY</code> A process has finished | ||
+ | *<code style="color: #bb0000;">LV_EVENT_CANCEL</code> A process has been canceled | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
196行目: | 309行目: | ||
They can be sent to any object with <code style="color: #bb0000;">lv_event_send(obj, MY_EVENT_1, &some_data)</code> | They can be sent to any object with <code style="color: #bb0000;">lv_event_send(obj, MY_EVENT_1, &some_data)</code> | ||
− | | | + | |Any custom event codes can be registered by <code style="color: #bb0000;">uint32_t MY_EVENT_1 = lv_event_register_id();</code> |
+ | |||
+ | They can be sent to any object with <code style="color: #bb0000;">lv_event_send(obj, MY_EVENT_1, &some_data)</code> | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
215行目: | 330行目: | ||
lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id); | lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | | | + | |To manually send events to an object, use <code style="color: #bb0000;">lv_event_send(obj, <EVENT_CODE> &some_data)</code>. |
+ | |||
+ | For example, this can be used to manually close a message box by simulating a button press (although there are simpler ways to do this): | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
+ | /*Simulate the press of the first button (indexes start from zero)*/ | ||
+ | uint32_t btn_id = 0; | ||
+ | lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id); | ||
+ | </syntaxhighlight> | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
232行目: | 354行目: | ||
* enable a button if some conditions are met (e.g. the correct PIN is entered) | * enable a button if some conditions are met (e.g. the correct PIN is entered) | ||
* add/remove styles to/from an object if a limit is exceeded, etc | * add/remove styles to/from an object if a limit is exceeded, etc | ||
− | | | + | |<code style="color: #bb0000;">LV_EVENT_REFRESH</code> is a special event because it's designed to let the user notify an object to refresh itself. Some examples: |
+ | |||
+ | * notify a label to refresh its text according to one or more variables (e.g. current time) | ||
+ | * refresh a label when the language changes | ||
+ | * enable a button if some conditions are met (e.g. the correct PIN is entered) | ||
+ | * add/remove styles to/from an object if a limit is exceeded, etc | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
250行目: | 377行目: | ||
* <code style="color: #bb0000;">lv_event_get_user_data(e)</code> get the pointer passed as the last parameter of <code style="color: #bb0000;">lv_obj_add_event_cb</code>. | * <code style="color: #bb0000;">lv_event_get_user_data(e)</code> get the pointer passed as the last parameter of <code style="color: #bb0000;">lv_obj_add_event_cb</code>. | ||
* <code style="color: #bb0000;">lv_event_get_param(e)</code> get the parameter passed as the last parameter of <code style="color: #bb0000;">lv_event_send</code> | * <code style="color: #bb0000;">lv_event_get_param(e)</code> get the parameter passed as the last parameter of <code style="color: #bb0000;">lv_event_send</code> | ||
− | | | + | |<code style="color: #bb0000;">lv_event_t</code> is the only parameter passed to the event callback and it contains all data about the event. The following values can be gotten from it: |
+ | |||
+ | *<code style="color: #bb0000;">lv_event_get_code(e)</code> get the event code | ||
+ | *<code style="color: #bb0000;">lv_event_get_current_target(e)</code> get the object to which an event was sent. I.e. the object whose event handler is being called. | ||
+ | *<code style="color: #bb0000;">lv_event_get_target(e)</code> get the object that originally triggered the event (different from <code style="color: #bb0000;">lv_event_get_target</code> if event bubbling is enabled) | ||
+ | *<code style="color: #bb0000;">lv_event_get_user_data(e)</code> get the pointer passed as the last parameter of <code style="color: #bb0000;">lv_obj_add_event_cb</code>. | ||
+ | *<code style="color: #bb0000;">lv_event_get_param(e)</code> get the parameter passed as the last parameter of <code style="color: #bb0000;">lv_event_send</code> | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
264行目: | 397行目: | ||
The ''target'' parameter of the event is always the current target object, not the original object. To get the original target call <code style="color: #bb0000;">lv_event_get_original_target(e)</code> in the event handler. | The ''target'' parameter of the event is always the current target object, not the original object. To get the original target call <code style="color: #bb0000;">lv_event_get_original_target(e)</code> in the event handler. | ||
− | | | + | |If <code style="color: #bb0000;">lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE)</code> is enabled all events will be sent to an object's parent too. If the parent also has <code style="color: #bb0000;">LV_OBJ_FLAG_EVENT_BUBBLE</code> enabled the event will be sent to its parent and so on. |
+ | |||
+ | The ''target'' parameter of the event is always the current target object, not the original object. To get the original target call <code style="color: #bb0000;">lv_event_get_original_target(e)</code> in the event handler. | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] |
2022年6月30日 (木) 23:25時点における版
https://docs.lvgl.io/8.2/overview/style.html
Events
英文 | 自動翻訳 |
---|---|
Events are triggered in LVGL when something happens which might be interesting to the user, e.g. when an object
|
LVGLでは、ユーザが興味を持ちそうなことが起こったときに、イベントが発生します。
|
Add events to the object
英文 | 自動翻訳 |
---|---|
The user can assign callback functions to an object to see its events. In practice, it looks like this: lv_obj_t * btn = lv_btn_create(lv_scr_act()); lv_obj_add_event_cb(btn, my_event_cb, LV_EVENT_CLICKED, NULL); /*Assign an event callback*/
...
static void my_event_cb(lv_event_t * event)
{
printf("Clicked\n");
}
In the example See the list of event codes for all the options.
It will be described later in more detail. More events can be added to an object, like this: lv_obj_add_event_cb(obj, my_event_cb_1, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(obj, my_event_cb_2, LV_EVENT_PRESSED, NULL);
lv_obj_add_event_cb(obj, my_event_cb_3, LV_EVENT_ALL, NULL); /*No filtering, receive all events*/
Even the same event callback can be used on an object with different lv_obj_add_event_cb(obj, increment_on_click, LV_EVENT_CLICKED, &num1);
lv_obj_add_event_cb(obj, increment_on_click, LV_EVENT_CLICKED, &num2);
The events will be called in the order as they were added. Other objects can use the same event callback. |
ユーザーは、オブジェクトにコールバック関数を割り当てて、そのイベントを確認することができます。
実際には、以下のような感じです。 lv_obj_t * btn = lv_btn_create(lv_scr_act()); lv_obj_add_event_cb(btn, my_event_cb, LV_EVENT_CLICKED, NULL); /*Assign an event callback*/
...
static void my_event_cb(lv_event_t * event)
{
printf("Clicked\n");
}
In the example See the list of event codes for all the options.
It will be described later in more detail.
lv_obj_add_event_cb(obj, my_event_cb_1, LV_EVENT_CLICKED, NULL);
lv_obj_add_event_cb(obj, my_event_cb_2, LV_EVENT_PRESSED, NULL);
lv_obj_add_event_cb(obj, my_event_cb_3, LV_EVENT_ALL, NULL); /*No filtering, receive all events*/
Even the same event callback can be used on an object with different lv_obj_add_event_cb(obj, increment_on_click, LV_EVENT_CLICKED, &num1);
lv_obj_add_event_cb(obj, increment_on_click, LV_EVENT_CLICKED, &num2);
The events will be called in the order as they were added. Other objects can use the same event callback. |
Remove event(s) from an object
英文 | 自動翻訳 |
---|---|
Events can be removed from an object with the |
Events can be removed from an object with the lv_obj_remove_event_cb(obj, event_cb) function or lv_obj_remove_event_dsc(obj, event_dsc) . event_dsc is a pointer returned by lv_obj_add_event_cb .
|
Event codes
英文 | 自動翻訳 |
---|---|
The event codes can be grouped into these categories:
All objects (such as Buttons/Labels/Sliders etc.) regardless their type receive the Input device, Drawing and Other events. However, the Special events are specific to a particular widget type. See the widgets' documentation to learn when they are sent, Custom events are added by the user and are never sent by LVGL. The following event codes exist: |
The event codes can be grouped into these categories:
All objects (such as Buttons/Labels/Sliders etc.) regardless their type receive the Input device, Drawing and Other events. However, the Special events are specific to a particular widget type. See the widgets' documentation to learn when they are sent, Custom events are added by the user and are never sent by LVGL. The following event codes exist: |
Input device events
英文 | 自動翻訳 |
---|---|
|
|
Drawing events
英文 | 自動翻訳 |
---|---|
In |
In |
Other events
英文 | 自動翻訳 |
---|---|
|
|
Special events
英文 | 自動翻訳 |
---|---|
|
|
Custom events
英文 | 自動翻訳 |
---|---|
Any custom event codes can be registered by They can be sent to any object with |
Any custom event codes can be registered by uint32_t MY_EVENT_1 = lv_event_register_id();
They can be sent to any object with |
Sending events
英文 | 自動翻訳 |
---|---|
To manually send events to an object, use For example, this can be used to manually close a message box by simulating a button press (although there are simpler ways to do this): /*Simulate the press of the first button (indexes start from zero)*/
uint32_t btn_id = 0;
lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id);
|
To manually send events to an object, use lv_event_send(obj, <EVENT_CODE> &some_data) .
For example, this can be used to manually close a message box by simulating a button press (although there are simpler ways to do this): /*Simulate the press of the first button (indexes start from zero)*/
uint32_t btn_id = 0;
lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id);
|
Refresh event
英文 | 自動翻訳 |
---|---|
|
LV_EVENT_REFRESH is a special event because it's designed to let the user notify an object to refresh itself. Some examples:
|
Fields of lv_event_t
英文 | 自動翻訳 |
---|---|
|
lv_event_t is the only parameter passed to the event callback and it contains all data about the event. The following values can be gotten from it:
|
Event bubbling
英文 | 自動翻訳 |
---|---|
If The target parameter of the event is always the current target object, not the original object. To get the original target call |
If lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE) is enabled all events will be sent to an object's parent too. If the parent also has LV_OBJ_FLAG_EVENT_BUBBLE enabled the event will be sent to its parent and so on.
The target parameter of the event is always the current target object, not the original object. To get the original target call |
Examples
英文 | 自動翻訳 |
---|---|
Button click event |
|
Handle multiple events |
|
Event bubbling |