「App:Library:LVGL:docs:Overview:Events」の版間の差分
32行目: | 32行目: | ||
In practice, it looks like this: | In practice, it looks like this: | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
lv_obj_t * btn = lv_btn_create(lv_scr_act()); | 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*/ | lv_obj_add_event_cb(btn, my_event_cb, LV_EVENT_CLICKED, NULL); /*Assign an event callback*/ | ||
71行目: | 71行目: | ||
実際には、以下のような感じです。 | 実際には、以下のような感じです。 | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
lv_obj_t * btn = lv_btn_create(lv_scr_act()); | 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*/ | lv_obj_add_event_cb(btn, my_event_cb, LV_EVENT_CLICKED, NULL); /*Assign an event callback*/ | ||
110行目: | 110行目: | ||
|} | |} | ||
:[[App:Library:LVGL:docs:Overview|戻る : Previous]] | :[[App:Library:LVGL:docs:Overview|戻る : Previous]] | ||
− | |||
== Remove event(s) from an object == | == Remove event(s) from an object == |
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 |