App:Library:LVGL:docs:Overview:Events
https://docs.lvgl.io/8.2/overview/event.html
Events
英文 | 自動翻訳 |
---|---|
Events are triggered in LVGL when something happens which might be interesting to the user, e.g. when an object
|
LVGLでは、ユーザが興味を持ちそうなことが起こったときに、イベントが発生します。
|
The user can assign a callback function to an object to see these events.
In practice, it looks like this: |
ユーザーは、コールバック関数をオブジェクトに割り当てて、これらのイベントを確認できます。
実際には、次のようになります。 |
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_event_cb(btn, my_event_cb); /*Assign an event callback*/
...
static void my_event_cb(lv_obj_t * obj, lv_event_t event)
{
switch(event) {
case LV_EVENT_PRESSED:
printf("Pressed\n");
break;
case LV_EVENT_SHORT_CLICKED:
printf("Short clicked\n");
break;
case LV_EVENT_CLICKED:
printf("Clicked\n");
break;
case LV_EVENT_LONG_PRESSED:
printf("Long press\n");
break;
case LV_EVENT_LONG_PRESSED_REPEAT:
printf("Long press repeat\n");
break;
case LV_EVENT_RELEASED:
printf("Released\n");
break;
}
/*Etc.*/
}
| |
More objects can use the same event callback. | より多くのオブジェクトが同じイベント コールバックを使用できます。 |
Event types
The following event types exist: | 次のイベント タイプが存在します。 |
Generic events
All objects (such as Buttons/Labels/Sliders etc.) receive these generic events regardless of their type. | すべてのオブジェクト (ボタン/ラベル/スライダーなど) は、タイプに関係なく、これらの一般的なイベントを受け取ります。 |
Related to the input devices
These are sent when an object is pressed/released etc. by the user. They are used not only for Pointers but can used for Keypad, Encoder and Button input devices as well. Visit the Overview of input devices section to learn more about them.
|
これらは、ユーザーがオブジェクトを押したり離したりしたときに送信されます。ポインターだけでなく、キーパッド、エンコーダー、ボタン入力デバイスにも使用できます。詳細については、入力デバイスの概要セクションをご覧ください。
|
Related to pointer
These events are sent only by pointer-like input devices (E.g. mouse or touchpad)
|
これらのイベントは、ポインターのような入力デバイス (マウスやタッチパッドなど) によってのみ送信されます。
|
Related to keypad and encoder
These events are sent by keypad and encoder input devices. Learn more about Groups in [overview/indev](Input devices) section.
|
これらのイベントは、キーパッドとエンコーダの入力デバイスによって送信されます。 グループの詳細については、[概要/indev](入力デバイス) セクションを参照してください。
LV_EVENT_KEY オブジェクトにキーが送信されます。 通常、長押しの後に押された、または繰り返されたとき。 キーは uint32_t * key = lv_event_get_data() で取得できます LV_EVENT_FOCUSED オブジェクトはそのグループにフォーカスされています LV_EVENT_DEFOCUSED オブジェクトはそのグループ内で焦点が合っていません |
General events
Other general events sent by the library.
|
図書館から送られるその他の一般的なイベント。
|
Special events
These events are specific to a particular object type.
Visit particular Object type's documentation to understand which events are used by an object type. |
これらのイベントは、特定のオブジェクト タイプに固有です。
オブジェクト タイプで使用されるイベントを理解するには、特定のオブジェクト タイプのドキュメントを参照してください。 |
--
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 For example: 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");
}
この例では、 すべてのオプションについては、イベントコードのリストを参照してください。
これについては、後で詳しく説明します。 このように、オブジェクトにはさらにイベントを追加することができます。 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*/
同じイベントコールバックでも、 例えば 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);
イベントは、追加された順番に呼び出されます。 他のオブジェクトも同じイベントコールバックを使用することができます。 |
Remove event(s) from an object
英文 | 自動翻訳 |
---|---|
Events can be removed from an object with the
|
イベントは、lv_obj_remove_event_cb(obj, event_cb) 関数または lv_obj_remove_event_dsc(obj, event_dsc) . でオブジェクトから削除できる。
|
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: |
イベントコードは、以下のカテゴリーに分類されます。
すべてのオブジェクト(ボタン/ラベル/スライダーなど)は、そのタイプに関係なく、Input device、Drawing、Otherの各イベントを受け取ります。 しかし、特別なイベントは、特定のウィジェットタイプに固有のものです。いつ送信されるかは、ウィジェットのドキュメントを参照してください。 カスタムイベントはユーザが追加するもので、LVGLから送信されることはありません。 以下のイベントコードが存在する。 |
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 |
カスタムイベントコードは、uint32_t MY_EVENT_1 = lv_event_register_id(); で登録することができます。
任意のオブジェクトに |
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);
|
手動でオブジェクトにイベントを送るには、lv_event_send(obj, <EVENT_CODE> &some_data) .を使ってください。
例えば、ボタンを押したように見えるメッセージボックスを手動で閉じることができます(もっと簡単な方法もありますが)。 /*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 は特別なイベントで、オブジェクトの更新をユーザに通知するように設計されているからです。いくつかの例を挙げます。
|
Fields of lv_event_t
英文 | 自動翻訳 |
---|---|
|
lv_event_t は、イベントコールバックに渡される唯一のパラメータで、イベントに関するすべてのデータを含んでいます。そこから以下の値を得ることができる。
|
Event bubbling
英文 | 自動翻訳 |
---|---|
If
|
If lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE) が有効な場合、すべてのイベントはオブジェクトの親にも送信されます。
|
Examples
英文 | 自動翻訳 |
---|---|
Button click event |
|
Handle multiple events |
|
Event bubbling |