In LittlevGL events are triggered if something happens which might be interesting to the user. For example an object

  • is clicked

  • is dragged

  • its value has changed, etc.

The user can assign a callback function to an object to see these event. In the 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("Short clicked\n");

        case LV_EVENT_CLICKED:

            printf("Long press\n");

            printf("Long press repeat\n");

        case LV_EVENT_RELEASED:


More objects can use the same event callback.

Event types

The following event types exist:

Generic events

Any object can receive these events independently from their type. I.e. these events are sent to Buttons, Labels, Sliders, etc.

General events

Other general events sent by the library.

  • LV_EVENT_DELETE The object is being deleted. Free the related user-allocated data.

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.

To see exactly which events are used by an object type see the particular 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 info 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 its a

  • single number then it’s uint32_t * or int32_t *

  • text then char * or const char *

Send events manually

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

It can be used for example to manually close a message box by simulating a button press:

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

Or to ask refresh in a generic way.

lv_event_send(label, LV_EVENT_REFRESH, NULL);