「App:Library:LVGL:docs:Overview:Events」の版間の差分

提供: robot-jp wiki
ナビゲーションに移動検索に移動
11行目: 11行目:
 
* is clicked
 
* is clicked
 
* is scrolled
 
* is scrolled
* has its value changed
+
* its value changed
* is redrawn, etc.
 
 
|LVGLでは、ユーザが興味を持ちそうなことが起こったときに、イベントが発生します。
 
|LVGLでは、ユーザが興味を持ちそうなことが起こったときに、イベントが発生します。
  
18行目: 17行目:
 
* スクロールされたとき
 
* スクロールされたとき
 
* その値が変更されたとき
 
* その値が変更されたとき
* 再描画されたとき、など
 
 
|}
 
|}
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]

2022年8月31日 (水) 19:35時点における版

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

  • is clicked
  • is scrolled
  • its value changed
LVGLでは、ユーザが興味を持ちそうなことが起こったときに、イベントが発生します。
  • クリックされたとき
  • スクロールされたとき
  • その値が変更されたとき
戻る : Previous


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 LV_EVENT_CLICKED means that only the click event will call my_event_cb.

See the list of event codes for all the options.

LV_EVENT_ALL can be used to receive all events.


The last parameter of lv_obj_add_event_cb 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:

 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 user_data.

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_EVENT_CLICKED は、クリックイベントだけがmy_event_cbを呼び出すことを意味します。

すべてのオプションについては、イベントコードのリストを参照してください。

LV_EVENT_ALLは、すべてのイベントを受信するために使用することができます。


lv_obj_add_event_cbの最後のパラメータは、イベントで利用可能な任意のカスタムデータへのポインタです。

これについては、後で詳しく説明します。

このように、オブジェクトにはさらにイベントを追加することができます。

 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*/

同じイベントコールバックでも、user_dataが異なるオブジェクトに対して使用することができます。

例えば

 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);

イベントは、追加された順番に呼び出されます。

他のオブジェクトも同じイベントコールバックを使用することができます。

戻る : Previous

Remove event(s) from an object

英文 自動翻訳

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.

イベントは、lv_obj_remove_event_cb(obj, event_cb) 関数または lv_obj_remove_event_dsc(obj, event_dsc). でオブジェクトから削除できる。

event_dsclv_obj_add_event_cbが返すポインタです。

戻る : Previous


Event codes

英文 自動翻訳

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:

イベントコードは、以下のカテゴリーに分類されます。
  • 入力デバイスイベント
  • 描画イベント
  • その他のイベント
  • 特殊イベント
  • カスタムイベント

すべてのオブジェクト(ボタン/ラベル/スライダーなど)は、そのタイプに関係なく、Input device、Drawing、Otherの各イベントを受け取ります。

しかし、特別なイベントは、特定のウィジェットタイプに固有のものです。いつ送信されるかは、ウィジェットのドキュメントを参照してください。

カスタムイベントはユーザが追加するもので、LVGLから送信されることはありません。

以下のイベントコードが存在する。

戻る : Previous


Input device events

英文 自動翻訳
  • LV_EVENT_PRESSED An object has been pressed
  • LV_EVENT_PRESSING An object is being pressed (called continuously while pressing)
  • LV_EVENT_PRESS_LOST An object is still being pressed but slid cursor/finger off of the object
  • LV_EVENT_SHORT_CLICKED An object was pressed for a short period of time, then released. Not called if scrolled.
  • LV_EVENT_LONG_PRESSED An object has been pressed for at least the long_press_time specified in the input device driver. 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 an object did not scroll (regardless of long press)
  • LV_EVENT_RELEASED Called in every case when an object has been released
  • LV_EVENT_SCROLL_BEGIN Scrolling begins. The event parameter is NULL or an lv_anim_t * with a scroll animation descriptor that can be modified if required.
  • LV_EVENT_SCROLL_END Scrolling ends.
  • LV_EVENT_SCROLL An object was scrolled
  • 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 an object. Get the key with lv_indev_get_key(lv_indev_get_act());
  • LV_EVENT_FOCUSED An object is focused
  • LV_EVENT_DEFOCUSED An object is unfocused
  • LV_EVENT_LEAVE An object is unfocused but still selected
  • LV_EVENT_HIT_TEST Perform advanced hit-testing. Use lv_hit_test_info_t * a = lv_event_get_hit_test_info(e) and check if a->point can click the object or not. If not set a->res = false
  • 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_time の後に long_press_repeat_time ms毎に呼び出される。スクロールしている間は呼び出されない。
  • LV_EVENT_CLICKED オブジェクトがスクロールしなかった場合、リリース時に呼び出されます (長押しに関係なく)。
  • LV_EVENT_RELEASED オブジェクトが解放されたときに毎回呼び出されます。
  • LV_EVENT_SCROLL_BEGIN スクロールが開始されます。イベントパラメータはNULL か、必要に応じて変更可能なスクロールアニメーション記述子を持つlv_anim_t * です。descriptor that can be modified if required.
  • LV_EVENT_SCROLL_END スクロールが終了します。
  • LV_EVENT_SCROLL オブジェクトがスクロールされました。
  • LV_EVENT_GESTURE ジェスチャが検出されました。lv_indev_get_gesture_dir(lv_indev_get_act());でジェスチャーを取得します。
  • LV_EVENT_KEY キーがオブジェクトに送信される。キーはlv_indev_get_key(lv_indev_get_act());で取得する。
  • LV_EVENT_FOCUSED オブジェクトがフォーカスされた。
  • LV_EVENT_DEFOCUSED オブジェクトがフォーカスされていない.
  • LV_EVENT_LEAVE オブジェクトはフォーカスされていないが、選択されている。
  • LV_EVENT_HIT_TEST 高度なヒットテストを実行します。 lv_hit_test_info_t * a = lv_event_get_hit_test_info(e) を使ってa->point がオブジェクトをクリックできるかどうかをチェックします。クリックできない場合はa->res = falseをセットする。
戻る : Previous


Drawing events

英文 自動翻訳
  • LV_EVENT_COVER_CHECK Check if an 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 an object (e.g. for a shadow). The event parameter is lv_coord_t * to store the size. Only overwrite it with a larger value.
  • 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 *. Learn more here.
  • LV_EVENT_DRAW_PART_END Finishing to draw a part. The event parameter is lv_obj_draw_dsc_t *. Learn more here.

In LV_EVENT_DRAW_... events it's not allowed to adjust the widgets' properties. E.g. you can not call lv_obj_set_width(). In other words only get functions can be called.

  • LV_EVENT_COVER_CHECK オブジェクトが領域を完全に覆っているかどうかをチェックする。イベントパラメータは lv_cover_check_info_t *です。
  • LV_EVENT_REFR_EXT_DRAW_SIZE オブジェクトの周りに必要な余分な描画領域を取得します (例:シャドウ). イベントパラメータは 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 *詳細はこちら。

In LV_EVENT_DRAW_...イベントでは、ウィジェットのプロパティを調整することはできません。例えば、 lv_obj_set_width(). を呼び出すことはできません。つまり、get 関数のみが呼び出せます。

戻る : Previous


Other events

英文 自動翻訳
  • LV_EVENT_DELETE Object is being deleted
  • LV_EVENT_CHILD_CHANGED Child was removed/added
  • 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_SIZE_CHANGED Object coordinates/size have changed
  • LV_EVENT_STYLE_CHANGED Object's style has changed
  • LV_EVENT_BASE_DIR_CHANGED The base dir has changed
  • LV_EVENT_GET_SELF_SIZE Get the internal size of a widget
  • LV_EVENT_SCREEN_UNLOAD_START A screen unload started, fired immediately when lv_scr_load/lv_scr_load_anim 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, called when all animations are finished
  • LV_EVENT_SCREEN_UNLOADED A screen was unloaded, called when all animations are finished
  • LV_EVENT_DELETE オブジェクトが削除された
  • LV_EVENT_CHILD_CHANGED 子が削除/追加されました。
  • LV_EVENT_CHILD_CREATED 子が作成されました。常にすべての親にバブルアップされます。
  • LV_EVENT_CHILD_DELETED 子が削除された、常にすべての親にバブルアップされる
  • LV_EVENT_SIZE_CHANGED オブジェクトの座標/サイズが変更されました。
  • LV_EVENT_STYLE_CHANGED オブジェクトのスタイルが変更された
  • LV_EVENT_BASE_DIR_CHANGED ベースディレクトリが変更されました。
  • LV_EVENT_GET_SELF_SIZE ウィジェットの内部サイズの取得
  • 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 スクリーンがアンロードされた、すべてのアニメーションが終了したときに呼び出されます。
戻る : Previous


Special events

英文 自動翻訳
  • LV_EVENT_VALUE_CHANGED The object's value has changed (i.e. slider moved)
  • LV_EVENT_INSERT Text is being inserted into 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 canceled
  • LV_EVENT_VALUE_CHANGED オブジェクトの値が変更された(スライダーが移動した)。
  • LV_EVENT_INSERT オブジェクトにテキストが挿入された。イベントデータが char * で挿入されています。
  • LV_EVENT_REFRESHオブジェクトに何かが更新されたことを通知する(ユーザーに対して)。
  • LV_EVENT_READY 処理が終了した。
  • LV_EVENT_CANCEL 処理がキャンセルされた。
戻る : Previous


Custom events

英文 自動翻訳

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 lv_event_send(obj, MY_EVENT_1, &some_data)

カスタムイベントコードは、uint32_t MY_EVENT_1 = lv_event_register_id();で登録することができます。

任意のオブジェクトにlv_event_send(obj, MY_EVENT_1, &some_data)で送ることができる。

戻る : Previous


Sending events

英文 自動翻訳

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);
手動でオブジェクトにイベントを送るには、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);
戻る : Previous


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:

  • 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
LV_EVENT_REFRESH は特別なイベントで、オブジェクトの更新をユーザに通知するように設計されているからです。いくつかの例を挙げます。
  • 1つ以上の変数(例えば、現在の時刻)に応じてテキストを更新するようラベルに通知する。
  • 言語が変更されたときにラベルを更新する
  • ある条件が満たされたらボタンを有効にする (例: 正しい PIN が入力された場合)
  • 制限を超えたら、オブジェクトにスタイルを追加/削除する、など。
戻る : Previous


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:

  • lv_event_get_code(e) get the event code
  • lv_event_get_current_target(e) get the object to which an event was sent. I.e. the object whose event handler is being called.
  • lv_event_get_target(e) get the object that originally triggered the event (different from lv_event_get_target if event bubbling is enabled)
  • lv_event_get_user_data(e) get the pointer passed as the last parameter of lv_obj_add_event_cb.
  • lv_event_get_param(e) get the parameter passed as the last parameter of lv_event_send
lv_event_t は、イベントコールバックに渡される唯一のパラメータで、イベントに関するすべてのデータを含んでいます。そこから以下の値を得ることができる。
  • lv_event_get_code(e) イベントコードを取得します。
  • lv_event_get_current_target(e) イベントが送信されたオブジェクトを取得します。すなわち、そのイベントハンドラが呼び出されているオブジェクト。
  • lv_event_get_target(e) イベントが最初にトリガーされたオブジェクトを取得します (以下のイベントとは異なります)。 (イベントバブリングが有効な場合、 lv_event_get_targetとは異なります)。
  • lv_event_get_user_data(e) は、lv_obj_add_event_cbの最後のパラメータとして渡されたポインタを取得します。 .
  • lv_event_get_param(e) は、lv_event_sendの最後のパラメータとして渡されたパラメータを取得します。get the parameter passed as the last parameter of
戻る : Previous


Event bubbling

英文 自動翻訳

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 lv_event_get_original_target(e) in the event handler.

If lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE) が有効な場合、すべてのイベントはオブジェクトの親にも送信されます。


親も LV_OBJ_FLAG_EVENT_BUBBLE を有効にしている場合、イベントはその親に送られ、以下同様となります。


イベントのターゲットパラメータは、常に現在のターゲットオブジェクトであり、元のオブジェクトではありません。


元のターゲットを取得するには、イベントハンドラでlv_event_get_original_target(e)を呼び出します。

戻る : Previous


Examples

英文 自動翻訳

Button click event

LVGL docs example 021.png

Handle multiple events

LVGL docs example 022.png

Event bubbling

LVGL docs example 023.png


戻る : Previous