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

提供: robot-jp wiki
ナビゲーションに移動検索に移動
 
(同じ利用者による、間の11版が非表示)
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]]
 
 
 
== Add events to the object ==
 
{| class="wikitable"
 
!英文
 
!自動翻訳
 
 
|-
 
|-
|
+
|The user can assign a callback function to an object to see these events.  
The user can assign callback functions to an object to see its events.  
 
 
 
 
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_add_event_cb(btn, my_event_cb, LV_EVENT_CLICKED, NULL);  /*Assign an event callback*/
+
|-
+
| colspan="2" |
...
+
<syntaxhighlight lang="C++" style="border: 1px dashed gray;">  
+
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
static void my_event_cb(lv_event_t * event)
+
lv_obj_set_event_cb(btn, my_event_cb);  /*Assign an event callback*/
{
 
    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.
+
...
  
 +
static void my_event_cb(lv_obj_t * obj, lv_event_t event)
 +
{
 +
    switch(event) {
 +
        case LV_EVENT_PRESSED:
 +
            printf("Pressed\n");
 +
            break;
  
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.
+
        case LV_EVENT_SHORT_CLICKED:
 +
            printf("Short clicked\n");
 +
            break;
  
It will be described later in more detail.
+
        case LV_EVENT_CLICKED:
 +
            printf("Clicked\n");
 +
            break;
  
More events can be added to an object, like this:
+
        case LV_EVENT_LONG_PRESSED:
<syntaxhighlight lang="C++" style="border:1px dashed gray;">
+
            printf("Long press\n");
lv_obj_add_event_cb(obj, my_event_cb_1, LV_EVENT_CLICKED, NULL);
+
            break;
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:
+
        case LV_EVENT_LONG_PRESSED_REPEAT:
<syntaxhighlight lang="C++" style="border:1px dashed gray;">
+
            printf("Long press repeat\n");
lv_obj_add_event_cb(obj, increment_on_click, LV_EVENT_CLICKED, &num1);
+
            break;
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''.
+
        case LV_EVENT_RELEASED:
|ユーザーは、オブジェクトにコールバック関数を割り当てて、そのイベントを確認することができます。
+
            printf("Released\n");
 +
            break;
 +
    }
  
実際には、以下のような感じです。
+
      /*Etc.*/
<syntaxhighlight lang="C++" style="border:1px dashed gray;">
+
}
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");
 
}
 
 
</syntaxhighlight>
 
</syntaxhighlight>
この例では、<code style="color: #bb0000;">LV_EVENT_CLICKED</code> は、クリックイベントだけが<code style="color: #bb0000;">my_event_cb</code>を呼び出すことを意味します。
+
|-
 
+
|More objects can use the same ''event callback''.
すべてのオプションについては、イベントコードのリストを参照してください。
+
|より多くのオブジェクトが同じイベント コールバックを使用できます。
 
 
<code style="color: #bb0000;">LV_EVENT_ALL</code>は、すべてのイベントを受信するために使用することができます。
 
 
 
 
 
 
 
<code style="color: #bb0000;">lv_obj_add_event_cb</code>の最後のパラメータは、イベントで利用可能な任意のカスタムデータへのポインタです。
 
 
 
これについては、後で詳しく説明します。
 
 
 
このように、オブジェクトにはさらにイベントを追加することができます。
 
<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>
 
同じイベントコールバックでも、<code style="color: #bb0000;">user_data</code>が異なるオブジェクトに対して使用することができます。
 
 
 
例えば
 
<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>
 
イベントは、追加された順番に呼び出されます。
 
 
 
他のオブジェクトも同じイベントコールバックを使用することができます。
 
 
|}
 
|}
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
  
== Remove event(s) from an object ==
+
==== Event types ====
 
{| class="wikitable"
 
{| class="wikitable"
!英文
+
|The following event types exist:
!自動翻訳
+
|次のイベント タイプが存在します。
|-
+
|}
|
 
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>.
+
===== Generic events =====
|イベントは、<code style="color: #bb0000;">lv_obj_remove_event_cb(obj, event_cb)</code> 関数または  <code style="color: #bb0000;">lv_obj_remove_event_dsc(obj, event_dsc)</code>. でオブジェクトから削除できる。
+
{| class="wikitable"
<code style="color: #bb0000;">event_dsc</code>は<code style="color: #bb0000;">lv_obj_add_event_cb</code>が返すポインタです。
+
|All objects (such as Buttons/Labels/Sliders etc.) receive these generic events regardless of their type.
 +
|すべてのオブジェクト (ボタン/ラベル/スライダーなど) は、タイプに関係なく、これらの一般的なイベントを受け取ります。
 
|}
 
|}
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
  
 +
====== Related to the input devices ======
 +
{| class="wikitable"
 +
|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 [[App:Library:LVGL:docs:Overview:Input devices|<u>'''Overview of input devices'''</u>]] section to learn more about them.
  
== Event codes ==
+
* '''LV_EVENT_PRESSED''' The object has been pressed
{| class="wikitable"
+
* '''LV_EVENT_PRESSING''' The object is being pressed (sent continuously while pressing)
!英文
+
* '''LV_EVENT_PRESS_LOST''' The input device is still being pressed but is no longer on the object
!自動翻訳
+
* '''LV_EVENT_SHORT_CLICKED''' Released before <code style="color: #bb0000;">LV_INDEV_LONG_PRESS_TIME</code> time. Not called if dragged.
|-
+
* '''LV_EVENT_LONG_PRESSED''' Pressing for <code style="color: #bb0000;">LV_INDEV_LONG_PRESS_TIME</code> time. Not called if dragged.
|
+
* '''LV_EVENT_LONG_PRESSED_REPEAT''' Called after <code style="color: #bb0000;">LV_INDEV_LONG_PRESS_TIME</code> in every <code style="color: #bb0000;">LV_INDEV_LONG_PRESS_REP_TIME</code> ms. Not called if dragged.
The event codes can be grouped into these categories:
+
* '''LV_EVENT_CLICKED''' Called on release if not dragged (regardless to long press)
 +
* '''LV_EVENT_RELEASED''' Called in every case when the object has been released even if it was dragged. Not called if slid from the object while pressing and released outside of the object. In this case, <code style="color: #bb0000;">LV_EVENT_PRESS_LOST</code> is sent.
 +
|これらは、ユーザーがオブジェクトを押したり離したりしたときに送信されます。ポインターだけでなく、キーパッド、エンコーダー、ボタン入力デバイスにも使用できます。詳細については、入力デバイスの概要セクションをご覧ください。
  
* Input device events
+
* '''LV_EVENT_PRESSED''' オブジェクトが押されました
* Drawing events
+
* '''LV_EVENT_PRESSING''' オブジェクトが押されている (押されている間、連続して送信される)
* Other events
+
* '''LV_EVENT_PRESS_LOST''' 入力デバイスはまだ押されていますが、オブジェクト上にはありません
* Special events
+
* '''LV_EVENT_SHORT_CLICKED''' <code style="color: #bb0000;">LV_INDEV_LONG_PRESS_TIME</code> 時間前に解放されました。ドラッグしても呼び出されません。
* Custom events
+
* '''LV_EVENT_LONG_PRESSED''' <code style="color: #bb0000;">LV_INDEV_LONG_PRESS_TIME</code> 時間押す。ドラッグしても呼び出されません。
 +
* '''LV_EVENT_LONG_PRESSED_REPEAT''' <code style="color: #bb0000;">LV_INDEV_LONG_PRESS_REP_TIME</code> ミリ秒ごとに <code style="color: #bb0000;">LV_INDEV_LONG_PRESS_TIME</code> の後に呼び出されます。ドラッグしても呼び出されません。
 +
* '''LV_EVENT_CLICKED''' ドラッグされていない場合、リリース時に呼び出されます (長押しに関係なく)
 +
* '''LV_EVENT_RELEASED''' ドラッグされた場合でも、オブジェクトが解放された場合に毎回呼び出されます。押しながらオブジェクトからスライドし、オブジェクトの外で離した場合は呼び出されません。この場合、<code style="color: #bb0000;">LV_EVENT_PRESS_LOST</code> が送信されます。
 +
|}
  
All objects (such as Buttons/Labels/Sliders etc.) regardless their type receive the ''Input device'', ''Drawing'' and ''Other'' events.
+
====== Related to pointer ======
 +
{| class="wikitable"
 +
|These events are sent only by pointer-like input devices (E.g. mouse or touchpad)
  
However, the ''Special events'' are specific to a particular widget type. See the widgets' documentation to learn when they are sent,
+
* '''LV_EVENT_DRAG_BEGIN''' Dragging of the object has started
 +
* '''LV_EVENT_DRAG_END''' Dragging finished (including drag throw)
 +
* '''LV_EVENT_DRAG_THROW_BEGIN''' Drag throw started (released after drag with "momentum")
 +
|これらのイベントは、ポインターのような入力デバイス (マウスやタッチパッドなど) によってのみ送信されます。
  
''Custom events'' are added by the user and are never sent by LVGL.
+
* '''LV_EVENT_DRAG_BEGIN''' オブジェクトのドラッグを開始しました
 +
* '''LV_EVENT_DRAG_END''' ドラッグ終了(ドラッグスロー含む)
 +
* '''LV_EVENT_DRAG_THROW_BEGIN''' ドラッグ投げ開始(「勢い」でドラッグ後リリース)
 +
|}
  
The following event codes exist:
+
====== Related to keypad and encoder ======
|イベントコードは、以下のカテゴリーに分類されます。
+
{| class="wikitable"
 +
|These events are sent by keypad and encoder input devices. Learn more about ''Groups'' in [overview/indev](Input devices) section.
  
* 入力デバイスイベント
+
* '''LV_EVENT_KEY''' A ''Key'' is sent to the object. Typically when it was pressed or repeated after a long press. The key can be retrived by <code style="color: #bb0000;">uint32_t * key = lv_event_get_data()</code>
* 描画イベント
+
* '''LV_EVENT_FOCUSED''' The object is focused in its group
* その他のイベント
+
* '''LV_EVENT_DEFOCUSED''' The object is defocused in its group
* 特殊イベント
+
|これらのイベントは、キーパッドとエンコーダの入力デバイスによって送信されます。 グループの詳細については、[概要/indev](入力デバイス) セクションを参照してください。
* カスタムイベント
 
  
すべてのオブジェクト(ボタン/ラベル/スライダーなど)は、そのタイプに関係なく、Input device、Drawing、Otherの各イベントを受け取ります。
+
* '''LV_EVENT_KEY''' オブジェクトにキーが送信されます。 通常、長押しの後に押された、または繰り返されたとき。 キーは <code style="color: #bb0000;">uint32_t * key = lv_event_get_data()</code> で取得できます
 +
* '''LV_EVENT_FOCUSED''' オブジェクトはそのグループにフォーカスされています
 +
* '''LV_EVENT_DEFOCUSED''' オブジェクトはそのグループ内で焦点が合っていません
 +
|}
  
しかし、特別なイベントは、特定のウィジェットタイプに固有のものです。いつ送信されるかは、ウィジェットのドキュメントを参照してください。
+
====== General events ======
 +
{| class="wikitable"
 +
|Other general events sent by the library.
  
カスタムイベントはユーザが追加するもので、LVGLから送信されることはありません。
+
* '''LV_EVENT_DELETE''' The object is being deleted. Free the related user-allocated data.
 +
|図書館から送られるその他の一般的なイベント。
  
以下のイベントコードが存在する。
+
* '''LV_EVENT_DELETE''' オブジェクトは削除中です。 関連するユーザー割り当てデータを解放します。
 
|}
 
|}
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
 
  
=== Input device events ===
+
===== Special events =====
 
{| class="wikitable"
 
{| class="wikitable"
!英文
+
|These events are specific to a particular object type.
!自動翻訳
 
|-
 
|
 
* <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>
 
|
 
*<code style="color: #bb0000;">LV_EVENT_PRESSED</code> オブジェクトが押された。
 
*<code style="color: #bb0000;">LV_EVENT_PRESSING</code> オブジェクトが押されている (押されている間、連続して呼び出される)
 
*<code style="color: #bb0000;">LV_EVENT_PRESS_LOST</code> オブジェクトが押されているが、カーソルや指をオブジェクトからスライドさせている状態
 
*<code style="color: #bb0000;">LV_EVENT_SHORT_CLICKED</code> オブジェクトが短時間押され、その後離された。スクロールしている場合は呼び出されない
 
*<code style="color: #bb0000;">LV_EVENT_LONG_PRESSED</code> 入力デバイスドライバで指定された<code style="color: #bb0000;">long_press_time</code> 以上、オブジェクトが押された状態。スクロールしている場合は呼び出されない。
 
*<code style="color: #bb0000;">LV_EVENT_LONG_PRESSED_REPEAT</code> :<code style="color: #bb0000;">long_press_time</code> の後に <code style="color: #bb0000;">long_press_repeat_time</code> ms毎に呼び出される。スクロールしている間は呼び出されない。
 
*<code style="color: #bb0000;">LV_EVENT_CLICKED</code> オブジェクトがスクロールしなかった場合、リリース時に呼び出されます (長押しに関係なく)。
 
*<code style="color: #bb0000;">LV_EVENT_RELEASED</code> オブジェクトが解放されたときに毎回呼び出されます。
 
*<code style="color: #bb0000;">LV_EVENT_SCROLL_BEGIN</code> スクロールが開始されます。イベントパラメータは<code style="color: #bb0000;">NULL</code> か、必要に応じて変更可能なスクロールアニメーション記述子を持つ<code style="color: #bb0000;">lv_anim_t *</code> です。descriptor that can be modified if required.
 
*<code style="color: #bb0000;">LV_EVENT_SCROLL_END</code> スクロールが終了します。
 
*<code style="color: #bb0000;">LV_EVENT_SCROLL</code> オブジェクトがスクロールされました。
 
*<code style="color: #bb0000;">LV_EVENT_GESTURE</code> ジェスチャが検出されました。<code style="color: #bb0000;">lv_indev_get_gesture_dir(lv_indev_get_act());</code>でジェスチャーを取得します。
 
*<code style="color: #bb0000;">LV_EVENT_KEY</code> キーがオブジェクトに送信される。キーは<code style="color: #bb0000;">lv_indev_get_key(lv_indev_get_act());</code>で取得する。
 
*<code style="color: #bb0000;">LV_EVENT_FOCUSED</code>  オブジェクトがフォーカスされた。
 
*<code style="color: #bb0000;">LV_EVENT_DEFOCUSED</code> オブジェクトがフォーカスされていない.
 
*<code style="color: #bb0000;">LV_EVENT_LEAVE</code> オブジェクトはフォーカスされていないが、選択されている。
 
*<code style="color: #bb0000;">LV_EVENT_HIT_TEST</code> 高度なヒットテストを実行します。 <code style="color: #bb0000;">lv_hit_test_info_t * a = lv_event_get_hit_test_info(e)</code> を使って<code style="color: #bb0000;">a->point</code> がオブジェクトをクリックできるかどうかをチェックします。クリックできない場合は<code style="color: #bb0000;">a->res = false</code>をセットする。
 
|}
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
  
 +
* '''LV_EVENT_VALUE_CHANGED''' The object value has changed (e.g. for a [[App:Library:LVGL:docs:Widgets:Slider (lv slider)|<u>'''Slider'''</u>]])
 +
* '''LV_EVENT_INSERT''' Something is inserted to the object. (Typically to a [[App:Library:LVGL:docs:Widgets:Text area (lv textarea)|<u>'''Text area'''</u>]])
 +
* '''LV_EVENT_APPLY''' "Ok", "Apply" or similar specific button has clicked. (Typically from a [[App:Library:LVGL:docs:Widgets:Keyboard (lv keyboard)|<u>'''Keyboard'''</u>]] object)
 +
* '''LV_EVENT_CANCEL''' "Close", "Cancel" or similar specific button has clicked. (Typically from a Keyboard object)
 +
* '''LV_EVENT_REFRESH''' Query to refresh the object. Never sent by the library but can be sent by the user.
  
=== Drawing events ===
 
{| class="wikitable"
 
!英文
 
!自動翻訳
 
|-
 
|
 
* <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.
+
Visit particular [[App:Library:LVGL:docs:Widgets|'''<u>Object type's documentation</u>''']] to understand which events are used by an object type.
|
+
|これらのイベントは、特定のオブジェクト タイプに固有です。
*<code style="color: #bb0000;">LV_EVENT_COVER_CHECK</code> オブジェクトが領域を完全に覆っているかどうかをチェックする。イベントパラメータは <code style="color: #bb0000;">lv_cover_check_info_t *</code>です。
 
*<code style="color: #bb0000;">LV_EVENT_REFR_EXT_DRAW_SIZE</code> オブジェクトの周りに必要な余分な描画領域を取得します (例:シャドウ). イベントパラメータは <code style="color: #bb0000;">lv_coord_t *</code> で、サイズを格納する。より大きな値で上書きするだけです。
 
*<code style="color: #bb0000;">LV_EVENT_DRAW_MAIN_BEGIN</code> メイン描画フェーズを開始します。
 
*<code style="color: #bb0000;">LV_EVENT_DRAW_MAIN</code> メイン描画を実行します。
 
*<code style="color: #bb0000;">LV_EVENT_DRAW_MAIN_END</code> 主描画フェーズの終了
 
*<code style="color: #bb0000;">LV_EVENT_DRAW_POST_BEGIN</code> ポスト描画フェーズの開始(すべての子の描画が終了したとき)
 
*<code style="color: #bb0000;">LV_EVENT_DRAW_POST</code> ポスト描画フェーズを実行します (すべての子供が描画されたとき)
 
*<code style="color: #bb0000;">LV_EVENT_DRAW_POST_END</code> ポスト描画フェーズを終了する(すべての子プロセスが描画された場合)。
 
*<code style="color: #bb0000;">LV_EVENT_DRAW_PART_BEGIN</code> パーツの描画を開始します。イベントパラメータは <code style="color: #bb0000;">lv_obj_draw_dsc_t *</code>です。詳しくはこちらで。
 
*<code style="color: #bb0000;">LV_EVENT_DRAW_PART_END</code> パーツの描画を終了します。イベントパラメータは <code style="color: #bb0000;">lv_obj_draw_dsc_t *</code>詳細はこちら。
 
  
In <code style="color: #bb0000;">LV_EVENT_DRAW_...</code>イベントでは、ウィジェットのプロパティを調整することはできません。例えば、 <code style="color: #bb0000;">lv_obj_set_width()</code>. を呼び出すことはできません。つまり、<code style="color: #bb0000;">get</code> 関数のみが呼び出せます。
+
* '''LV_EVENT_VALUE_CHANGED''' オブジェクトの値が変更されました (例: [[App:Library:LVGL:docs:Widgets:Slider (lv slider)|<u>'''Slider'''</u>]] の場合)
|}
+
* '''LV_EVENT_INSERT''' オブジェクトに何かが挿入されました。 (通常は[[App:Library:LVGL:docs:Widgets:Text area (lv textarea)|<u>'''Text area'''</u>]]に)
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
+
* '''LV_EVENT_APPLY''' 「OK」、「適用」などの特定のボタンがクリックされた。 (通常は [[App:Library:LVGL:docs:Widgets:Keyboard (lv keyboard)|<u>'''Keyboard'''</u>]] オブジェクトから)
 +
* '''LV_EVENT_CANCEL''' 「閉じる」「キャンセル」などの特定のボタンがクリックされた。 (通常は Keyboard オブジェクトから)
 +
* '''LV_EVENT_REFRESH''' オブジェクトをリフレッシュするクエリ。 ライブラリによって送信されることはありませんが、ユーザーによって送信される可能性があります。
  
  
=== Other events ===
+
オブジェクト タイプで使用されるイベントを理解するには、特定の[[App:Library:LVGL:docs:Widgets|'''<u>Object type's documentation</u>''']]を参照してください。
{| class="wikitable"
 
!英文
 
!自動翻訳
 
|-
 
|
 
* <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
 
|
 
*<code style="color: #bb0000;">LV_EVENT_DELETE</code> オブジェクトが削除された
 
*<code style="color: #bb0000;">LV_EVENT_CHILD_CHANGED</code> 子が削除/追加されました。
 
*<code style="color: #bb0000;">LV_EVENT_CHILD_CREATED</code> 子が作成されました。常にすべての親にバブルアップされます。
 
*<code style="color: #bb0000;">LV_EVENT_CHILD_DELETED</code> 子が削除された、常にすべての親にバブルアップされる
 
*<code style="color: #bb0000;">LV_EVENT_SIZE_CHANGED</code> オブジェクトの座標/サイズが変更されました。
 
*<code style="color: #bb0000;">LV_EVENT_STYLE_CHANGED</code> オブジェクトのスタイルが変更された
 
*<code style="color: #bb0000;">LV_EVENT_BASE_DIR_CHANGED</code> ベースディレクトリが変更されました。
 
*<code style="color: #bb0000;">LV_EVENT_GET_SELF_SIZE</code> ウィジェットの内部サイズの取得
 
*<code style="color: #bb0000;">LV_EVENT_SCREEN_UNLOAD_START</code> 画面のアンロードが開始された、lv_scr_load/lv_scr_load_animが呼ばれるとすぐに起動される
 
*<code style="color: #bb0000;">LV_EVENT_SCREEN_LOAD_START</code> スクリーンのロードを開始し、スクリーンチェンジのディレイが切れたときに発行されます。
 
*<code style="color: #bb0000;">LV_EVENT_SCREEN_LOADED</code> スクリーンがロードされた、すべてのアニメーションが終了したときに呼び出される
 
*<code style="color: #bb0000;">LV_EVENT_SCREEN_UNLOADED</code> スクリーンがアンロードされた、すべてのアニメーションが終了したときに呼び出されます。
 
 
|}
 
|}
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
 
  
=== Special events ===
+
=== Custom data ===
 
{| class="wikitable"
 
{| class="wikitable"
!英文
+
|Some events might contain custom data. For example, <code style="color: #bb0000;">LV_EVENT_VALUE_CHANGED</code> in some cases tells the new value. For more information, see the particular [[App:Library:LVGL:docs:Widgets|'''<u>Object type's documentation</u>''']]. To get the custom data in the event callback use <code style="color: #bb0000;">lv_event_get_data()</code>.
!自動翻訳
 
|-
 
|
 
* <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
 
|
 
*<code style="color: #bb0000;">LV_EVENT_VALUE_CHANGED</code> オブジェクトの値が変更された(スライダーが移動した)。
 
*<code style="color: #bb0000;">LV_EVENT_INSERT</code> オブジェクトにテキストが挿入された。イベントデータが <code style="color: #bb0000;">char *</code> で挿入されています。
 
*<code style="color: #bb0000;">LV_EVENT_REFRESH</code>オブジェクトに何かが更新されたことを通知する(ユーザーに対して)。
 
*<code style="color: #bb0000;">LV_EVENT_READY</code> 処理が終了した。
 
*<code style="color: #bb0000;">LV_EVENT_CANCEL</code> 処理がキャンセルされた。
 
|}
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
  
 +
The type of the custom data depends on the sending object but if it's a
  
=== Custom events ===
+
* single number then it's <code style="color: #bb0000;">uint32_t *</code> or <code style="color: #bb0000;">int32_t *</code>
{| class="wikitable"
+
* text then <code style="color: #bb0000;">char *</code> or <code style="color: #bb0000;">const char *</code>
!英文
+
|一部のイベントには、カスタム データが含まれる場合があります。 たとえば、場合によっては <code style="color: #bb0000;">LV_EVENT_VALUE_CHANGED</code> が新しい値を示します。 詳細については、特定の[[App:Library:LVGL:docs:Widgets|'''<u>Object type's documentation</u>''']]を参照してください。 イベント コールバックでカスタム データを取得するには、<code style="color: #bb0000;">lv_event_get_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>
+
カスタム データのタイプは送信オブジェクトによって異なりますが、
|カスタムイベントコードは、<code style="color: #bb0000;">uint32_t MY_EVENT_1 = lv_event_register_id();</code>で登録することができます。
 
  
任意のオブジェクトに<code style="color: #bb0000;">lv_event_send(obj, MY_EVENT_1, &some_data)</code>で送ることができる。 
+
* 単一の数値の場合は <code style="color: #bb0000;">uint32_t *</code> または <code style="color: #bb0000;">int32_t *</code>
 +
* text の次に <code style="color: #bb0000;">char *</code> または <code style="color: #bb0000;">const char *</code>
 
|}
 
|}
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
  
  
== Sending events ==
+
=== Send events manually ===
 +
==== Arbitrary events ====
 
{| class="wikitable"
 
{| class="wikitable"
!英文
+
|To manually send events to an object, use <code style="color: #bb0000;">lv_event_send(obj, LV_EVENT_..., &custom_data)</code>.
!自動翻訳
 
|-
 
|
 
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):
+
For example, it can be used to manually close a message box by simulating a button press (although there are simpler ways of doing this):
<syntaxhighlight lang="C++" style="border:1px dashed gray;">
+
|イベントをオブジェクトに手動で送信するには、<code style="color: #bb0000;">lv_event_send(obj, LV_EVENT_..., &custom_data)</code> を使用します。
/*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>
 
|手動でオブジェクトにイベントを送るには、<code style="color: #bb0000;">lv_event_send(obj, <EVENT_CODE> &some_data)</code>.を使ってください。
 
  
例えば、ボタンを押したように見えるメッセージボックスを手動で閉じることができます(もっと簡単な方法もありますが)。
+
たとえば、ボタンの押下をシミュレートすることにより、メッセージ ボックスを手動で閉じるために使用できます (ただし、これを行うより簡単な方法があります)。
<syntaxhighlight lang="C++" style="border:1px dashed gray;">
+
|-
/*Simulate the press of the first button (indexes start from zero)*/
+
| colspan="2" |
uint32_t btn_id = 0;
+
<syntaxhighlight lang="C++" style="border: 1px dashed gray;">  
lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id);
+
/*Simulate the press of the first button (indexes start from zero)*/
</syntaxhighlight>
+
uint32_t btn_id = 0;
 +
lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id);
 +
</syntaxhighlight>  
 
|}
 
|}
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
  
 
+
==== Refresh event ====
=== Refresh event ===
 
 
{| class="wikitable"
 
{| class="wikitable"
!英文
+
|<code style="color: #bb0000;">LV_EVENT_REFRESH</code> is special event because it's designed to be used by the user to notify an object to refresh itself. Some examples:
!自動翻訳
 
|-
 
|
 
<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)
 
* notify a label to refresh its text according to one or more variables (e.g. current time)
360行目: 210行目:
 
* 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> は特別なイベントで、オブジェクトの更新をユーザに通知するように設計されているからです。いくつかの例を挙げます。
 
  
* 1つ以上の変数(例えば、現在の時刻)に応じてテキストを更新するようラベルに通知する。
+
To simplest way to handle similar cases is utilizing the following functions.
* 言語が変更されたときにラベルを更新する
 
* ある条件が満たされたらボタンを有効にする (例: 正しい PIN が入力された場合)
 
* 制限を超えたら、オブジェクトにスタイルを追加/削除する、など。
 
|}
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
  
 +
<code style="color: #bb0000;">lv_event_send_refresh(obj)</code> is just a wrapper to <code style="color: #bb0000;">lv_event_send(obj, LV_EVENT_REFRESH, NULL)</code>.
  
== Fields of lv_event_t ==
+
So it simply sends an <code style="color: #bb0000;">LV_EVENT_REFRESH</code> to an object.
{| class="wikitable"
 
!英文
 
!自動翻訳
 
|-
 
|
 
<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_send_refresh_recursive(obj)</code> sends <code style="color: #bb0000;">LV_EVENT_REFRESH</code> event to an object and all of its children. If <code style="color: #bb0000;">NULL</code> is passed as parameter all objects of all displays will be refreshed.
* <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_REFRESH</code> は、オブジェクト自体を更新するように通知するためにユーザーが使用するように設計されているため、特別なイベントです。 いくつかの例:
* <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>
 
|<code style="color: #bb0000;">lv_event_t</code> は、イベントコールバックに渡される唯一のパラメータで、イベントに関するすべてのデータを含んでいます。そこから以下の値を得ることができる。
 
  
*<code style="color: #bb0000;">lv_event_get_code(e)</code> イベントコードを取得します。
+
* 1 つまたは複数の変数 (現在の時刻など) に従ってテキストを更新するようにラベルに通知します。
*<code style="color: #bb0000;">lv_event_get_current_target(e)</code> イベントが送信されたオブジェクトを取得します。すなわち、そのイベントハンドラが呼び出されているオブジェクト。
+
* 言語が変更されたときにラベルを更新する
*<code style="color: #bb0000;">lv_event_get_target(e)</code> イベントが最初にトリガーされたオブジェクトを取得します (以下のイベントとは異なります)。 (イベントバブリングが有効な場合、 <code style="color: #bb0000;">lv_event_get_target</code>とは異なります)。
+
* いくつかの条件が満たされた場合にボタンを有効にする (: 正しい PIN が入力された)
*<code style="color: #bb0000;">lv_event_get_user_data(e)</code> は、<code style="color: #bb0000;">lv_obj_add_event_cb</code>の最後のパラメータとして渡されたポインタを取得します。 .
+
* 制限を超えた場合のオブジェクトへの/からのスタイルの追加/削除など
*<code style="color: #bb0000;">lv_event_get_param(e)</code> は、<code style="color: #bb0000;">lv_event_send</code>の最後のパラメータとして渡されたパラメータを取得します。get the parameter passed as the last parameter of
 
|}
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
  
 +
同様のケースを処理する最も簡単な方法は、次の関数を利用することです。
  
== Event bubbling ==
+
<code style="color: #bb0000;">lv_event_send_refresh(obj)</code> は、<code style="color: #bb0000;">lv_event_send(obj, LV_EVENT_REFRESH, NULL)</code> の単なるラッパーです。
{| class="wikitable"
 
!英文
 
!自動翻訳
 
|-
 
|
 
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.
 
|If <code style="color: #bb0000;">lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE)</code> が有効な場合、すべてのイベントはオブジェクトの親にも送信されます。
 
 
 
 
 
親も <code style="color: #bb0000;">LV_OBJ_FLAG_EVENT_BUBBLE</code> を有効にしている場合、イベントはその親に送られ、以下同様となります。
 
 
 
 
 
イベントのターゲットパラメータは、常に現在のターゲットオブジェクトであり、元のオブジェクトではありません。
 
  
 +
したがって、<code style="color: #bb0000;">LV_EVENT_REFRESH</code> をオブジェクトに送信するだけです。
  
元のターゲットを取得するには、イベントハンドラで<code style="color: #bb0000;">lv_event_get_original_target(e)</code>を呼び出します。
+
<code style="color: #bb0000;">lv_event_send_refresh_recursive(obj)</code> は、<code style="color: #bb0000;">LV_EVENT_REFRESH</code> イベントをオブジェクトとそのすべての子に送信します。 パラメータとして <code style="color: #bb0000;">NULL</code> が渡された場合、すべてのディスプレイのすべてのオブジェクトがリフレッシュされます。
 
|}
 
|}
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
:[[App:Library:LVGL:docs:Overview#Events|戻る : Previous]]
 
 
== Examples ==
 
{| class="wikitable"
 
!英文
 
!自動翻訳
 
|-
 
|
 
=== Button click event ===
 
[[file:LVGL docs example 021.png|link=https://docs.lvgl.io/8.2/overview/event.html#button-click-event]]
 
|
 
|-
 
|
 
=== Handle multiple events ===
 
[[file:LVGL docs example 022.png|link=https://docs.lvgl.io/8.2/overview/event.html#handle-multiple-events]]
 
|
 
|-
 
|
 
=== Event bubbling ===
 
[[file:LVGL docs example 023.png|link=https://docs.lvgl.io/8.2/overview/event.html#id1]]
 
|
 
|}
 
 
 
 
[[App:Library:LVGL#Overview|戻る : Previous]]
 

2022年8月31日 (水) 20:22時点における最新版

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では、ユーザが興味を持ちそうなことが起こったときに、イベントが発生します。
  • クリックされたとき
  • スクロールされたとき
  • その値が変更されたとき
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. より多くのオブジェクトが同じイベント コールバックを使用できます。
戻る : Previous

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.
  • LV_EVENT_PRESSED The object has been pressed
  • LV_EVENT_PRESSING The object is being pressed (sent continuously while pressing)
  • LV_EVENT_PRESS_LOST The input device is still being pressed but is no longer on the object
  • LV_EVENT_SHORT_CLICKED Released before LV_INDEV_LONG_PRESS_TIME time. Not called if dragged.
  • LV_EVENT_LONG_PRESSED Pressing for LV_INDEV_LONG_PRESS_TIME time. Not called if dragged.
  • LV_EVENT_LONG_PRESSED_REPEAT Called after LV_INDEV_LONG_PRESS_TIME in every LV_INDEV_LONG_PRESS_REP_TIME ms. Not called if dragged.
  • LV_EVENT_CLICKED Called on release if not dragged (regardless to long press)
  • LV_EVENT_RELEASED Called in every case when the object has been released even if it was dragged. Not called if slid from the object while pressing and released outside of the object. In this case, LV_EVENT_PRESS_LOST is sent.
これらは、ユーザーがオブジェクトを押したり離したりしたときに送信されます。ポインターだけでなく、キーパッド、エンコーダー、ボタン入力デバイスにも使用できます。詳細については、入力デバイスの概要セクションをご覧ください。
  • LV_EVENT_PRESSED オブジェクトが押されました
  • LV_EVENT_PRESSING オブジェクトが押されている (押されている間、連続して送信される)
  • LV_EVENT_PRESS_LOST 入力デバイスはまだ押されていますが、オブジェクト上にはありません
  • LV_EVENT_SHORT_CLICKED LV_INDEV_LONG_PRESS_TIME 時間前に解放されました。ドラッグしても呼び出されません。
  • LV_EVENT_LONG_PRESSED LV_INDEV_LONG_PRESS_TIME 時間押す。ドラッグしても呼び出されません。
  • LV_EVENT_LONG_PRESSED_REPEAT LV_INDEV_LONG_PRESS_REP_TIME ミリ秒ごとに LV_INDEV_LONG_PRESS_TIME の後に呼び出されます。ドラッグしても呼び出されません。
  • LV_EVENT_CLICKED ドラッグされていない場合、リリース時に呼び出されます (長押しに関係なく)
  • LV_EVENT_RELEASED ドラッグされた場合でも、オブジェクトが解放された場合に毎回呼び出されます。押しながらオブジェクトからスライドし、オブジェクトの外で離した場合は呼び出されません。この場合、LV_EVENT_PRESS_LOST が送信されます。
Related to pointer
These events are sent only by pointer-like input devices (E.g. mouse or touchpad)
  • LV_EVENT_DRAG_BEGIN Dragging of the object has started
  • LV_EVENT_DRAG_END Dragging finished (including drag throw)
  • LV_EVENT_DRAG_THROW_BEGIN Drag throw started (released after drag with "momentum")
これらのイベントは、ポインターのような入力デバイス (マウスやタッチパッドなど) によってのみ送信されます。
  • LV_EVENT_DRAG_BEGIN オブジェクトのドラッグを開始しました
  • LV_EVENT_DRAG_END ドラッグ終了(ドラッグスロー含む)
  • LV_EVENT_DRAG_THROW_BEGIN ドラッグ投げ開始(「勢い」でドラッグ後リリース)
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.
  • LV_EVENT_KEY A Key is sent to the object. Typically when it was pressed or repeated after a long press. The key can be retrived by uint32_t * key = lv_event_get_data()
  • LV_EVENT_FOCUSED The object is focused in its group
  • LV_EVENT_DEFOCUSED The object is defocused in its group
これらのイベントは、キーパッドとエンコーダの入力デバイスによって送信されます。 グループの詳細については、[概要/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.
  • LV_EVENT_DELETE The object is being deleted. Free the related user-allocated data.
図書館から送られるその他の一般的なイベント。
  • LV_EVENT_DELETE オブジェクトは削除中です。 関連するユーザー割り当てデータを解放します。
Special events
These events are specific to a particular object type.
  • LV_EVENT_VALUE_CHANGED The object value has changed (e.g. for a Slider)
  • LV_EVENT_INSERT Something is inserted to the object. (Typically to a Text area)
  • LV_EVENT_APPLY "Ok", "Apply" or similar specific button has clicked. (Typically from a Keyboard object)
  • LV_EVENT_CANCEL "Close", "Cancel" or similar specific button has clicked. (Typically from a Keyboard object)
  • LV_EVENT_REFRESH Query to refresh the object. Never sent by the library but can be sent by the user.


Visit particular Object type's documentation to understand which events are used by an object type.

これらのイベントは、特定のオブジェクト タイプに固有です。
  • LV_EVENT_VALUE_CHANGED オブジェクトの値が変更されました (例: Slider の場合)
  • LV_EVENT_INSERT オブジェクトに何かが挿入されました。 (通常はText areaに)
  • LV_EVENT_APPLY 「OK」、「適用」などの特定のボタンがクリックされた。 (通常は Keyboard オブジェクトから)
  • LV_EVENT_CANCEL 「閉じる」「キャンセル」などの特定のボタンがクリックされた。 (通常は Keyboard オブジェクトから)
  • LV_EVENT_REFRESH オブジェクトをリフレッシュするクエリ。 ライブラリによって送信されることはありませんが、ユーザーによって送信される可能性があります。


オブジェクト タイプで使用されるイベントを理解するには、特定のObject type's documentationを参照してください。

Custom data

Some events might contain custom data. For example, LV_EVENT_VALUE_CHANGED in some cases tells the new value. For more information, see the particular Object type's documentation. To get the custom data in the event callback use lv_event_get_data().

The type of the custom data depends on the sending object but if it's a

  • single number then it's uint32_t * or int32_t *
  • text then char * or const char *
一部のイベントには、カスタム データが含まれる場合があります。 たとえば、場合によっては LV_EVENT_VALUE_CHANGED が新しい値を示します。 詳細については、特定のObject type's documentationを参照してください。 イベント コールバックでカスタム データを取得するには、lv_event_get_data() を使用します。

カスタム データのタイプは送信オブジェクトによって異なりますが、

  • 単一の数値の場合は uint32_t * または int32_t *
  • text の次に char * または const char *
戻る : Previous


Send events manually

Arbitrary events

To manually send events to an object, use lv_event_send(obj, LV_EVENT_..., &custom_data).

For example, it can be used to manually close a message box by simulating a button press (although there are simpler ways of doing this):

イベントをオブジェクトに手動で送信するには、lv_event_send(obj, LV_EVENT_..., &custom_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 special event because it's designed to be used by the user to 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

To simplest way to handle similar cases is utilizing the following functions.

lv_event_send_refresh(obj) is just a wrapper to lv_event_send(obj, LV_EVENT_REFRESH, NULL).

So it simply sends an LV_EVENT_REFRESH to an object.

lv_event_send_refresh_recursive(obj) sends LV_EVENT_REFRESH event to an object and all of its children. If NULL is passed as parameter all objects of all displays will be refreshed.

LV_EVENT_REFRESH は、オブジェクト自体を更新するように通知するためにユーザーが使用するように設計されているため、特別なイベントです。 いくつかの例:
  • 1 つまたは複数の変数 (現在の時刻など) に従ってテキストを更新するようにラベルに通知します。
  • 言語が変更されたときにラベルを更新する
  • いくつかの条件が満たされた場合にボタンを有効にする (例: 正しい PIN が入力された)
  • 制限を超えた場合のオブジェクトへの/からのスタイルの追加/削除など

同様のケースを処理する最も簡単な方法は、次の関数を利用することです。

lv_event_send_refresh(obj) は、lv_event_send(obj, LV_EVENT_REFRESH, NULL) の単なるラッパーです。

したがって、LV_EVENT_REFRESH をオブジェクトに送信するだけです。

lv_event_send_refresh_recursive(obj) は、LV_EVENT_REFRESH イベントをオブジェクトとそのすべての子に送信します。 パラメータとして NULL が渡された場合、すべてのディスプレイのすべてのオブジェクトがリフレッシュされます。

戻る : Previous