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

  • has its value changed

  • is redrawn, etc.

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.

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.

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 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_THROW_BEGIN Sent once when the object is released while scrolling but the "momentum" still keeps the content scrolling.

  • 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

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.

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

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

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)

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

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

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

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.

Examples

Button click event

C code  

 GitHub
#include "../lv_examples.h"
#if LV_BUILD_EXAMPLES && LV_USE_SWITCH

static void event_cb(lv_event_t * e)
{
    LV_LOG_USER("Clicked");

    static uint32_t cnt = 1;
    lv_obj_t * btn = lv_event_get_target(e);
    lv_obj_t * label = lv_obj_get_child(btn, 0);
    lv_label_set_text_fmt(label, "%"LV_PRIu32, cnt);
    cnt++;
}

/**
 * Add click event to a button
 */
void lv_example_event_1(void)
{
    lv_obj_t * btn = lv_btn_create(lv_scr_act());
    lv_obj_set_size(btn, 100, 50);
    lv_obj_center(btn);
    lv_obj_add_event_cb(btn, event_cb, LV_EVENT_CLICKED, NULL);

    lv_obj_t * label = lv_label_create(btn);
    lv_label_set_text(label, "Click me!");
    lv_obj_center(label);
}

#endif

MicroPython code  

 GitHub Simulator
class Event_1():
    def __init__(self):
        self.cnt = 1
        #
        # Add click event to a button
        #

        btn = lv.btn(lv.scr_act())
        btn.set_size(100, 50)
        btn.center()
        btn.add_event_cb(self.event_cb, lv.EVENT.CLICKED, None)

        label = lv.label(btn)
        label.set_text("Click me!")
        label.center()

    def event_cb(self,e):
        print("Clicked")

        btn = e.get_target()
        label = btn.get_child(0)
        label.set_text(str(self.cnt))
        self.cnt += 1

evt1 = Event_1()

Handle multiple events

C code  

 GitHub
#include "../lv_examples.h"
#if LV_BUILD_EXAMPLES && LV_USE_SWITCH

static void event_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * label = lv_event_get_user_data(e);

    switch(code) {
        case LV_EVENT_PRESSED:
            lv_label_set_text(label, "The last button event:\nLV_EVENT_PRESSED");
            break;
        case LV_EVENT_CLICKED:
            lv_label_set_text(label, "The last button event:\nLV_EVENT_CLICKED");
            break;
        case LV_EVENT_LONG_PRESSED:
            lv_label_set_text(label, "The last button event:\nLV_EVENT_LONG_PRESSED");
            break;
        case LV_EVENT_LONG_PRESSED_REPEAT:
            lv_label_set_text(label, "The last button event:\nLV_EVENT_LONG_PRESSED_REPEAT");
            break;
        default:
            break;
    }
}

/**
 * Handle multiple events
 */
void lv_example_event_2(void)
{
    lv_obj_t * btn = lv_btn_create(lv_scr_act());
    lv_obj_set_size(btn, 100, 50);
    lv_obj_center(btn);

    lv_obj_t * btn_label = lv_label_create(btn);
    lv_label_set_text(btn_label, "Click me!");
    lv_obj_center(btn_label);

    lv_obj_t * info_label = lv_label_create(lv_scr_act());
    lv_label_set_text(info_label, "The last button event:\nNone");

    lv_obj_add_event_cb(btn, event_cb, LV_EVENT_ALL, info_label);
}

#endif

MicroPython code  

 GitHub Simulator
def event_cb(e,label):
    code = e.get_code()
    if code == lv.EVENT.PRESSED:
        label.set_text("The last button event:\nLV_EVENT_PRESSED")
    elif code == lv.EVENT.CLICKED:
        label.set_text("The last button event:\nLV_EVENT_CLICKED")
    elif code == lv.EVENT.LONG_PRESSED:
        label.set_text("The last button event:\nLV_EVENT_LONG_PRESSED")
    elif code == lv.EVENT.LONG_PRESSED_REPEAT:
        label.set_text("The last button event:\nLV_EVENT_LONG_PRESSED_REPEAT")
btn = lv.btn(lv.scr_act())
btn.set_size(100, 50)
btn.center()

btn_label = lv.label(btn)
btn_label.set_text("Click me!")
btn_label.center()

info_label = lv.label(lv.scr_act())
info_label.set_text("The last button event:\nNone")

btn.add_event_cb(lambda e: event_cb(e,info_label), lv.EVENT.ALL, None)

Event bubbling

C code  

 GitHub
#include "../lv_examples.h"
#if LV_BUILD_EXAMPLES && LV_USE_FLEX

static void event_cb(lv_event_t * e)
{
    /*The original target of the event. Can be the buttons or the container*/
    lv_obj_t * target = lv_event_get_target(e);

    /*The current target is always the container as the event is added to it*/
    lv_obj_t * cont = lv_event_get_current_target(e);

    /*If container was clicked do nothing*/
    if(target == cont) return;

    /*Make the clicked buttons red*/
    lv_obj_set_style_bg_color(target, lv_palette_main(LV_PALETTE_RED), 0);
}

/**
 * Demonstrate event bubbling
 */
void lv_example_event_3(void)
{

    lv_obj_t * cont = lv_obj_create(lv_scr_act());
    lv_obj_set_size(cont, 290, 200);
    lv_obj_center(cont);
    lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP);

    uint32_t i;
    for(i = 0; i < 30; i++) {
        lv_obj_t * btn = lv_btn_create(cont);
        lv_obj_set_size(btn, 80, 50);
        lv_obj_add_flag(btn, LV_OBJ_FLAG_EVENT_BUBBLE);

        lv_obj_t * label = lv_label_create(btn);
        lv_label_set_text_fmt(label, "%"LV_PRIu32, i);
        lv_obj_center(label);
    }

    lv_obj_add_event_cb(cont, event_cb, LV_EVENT_CLICKED, NULL);
}

#endif

MicroPython code  

 GitHub Simulator
def event_cb(e):

    # The original target of the event. Can be the buttons or the container
    target = e.get_target()
    # print(type(target))

    # If container was clicked do nothing
    if type(target) != type(lv.btn()):
        return

    # Make the clicked buttons red
    target.set_style_bg_color(lv.palette_main(lv.PALETTE.RED), 0)

#
# Demonstrate event bubbling
#

cont = lv.obj(lv.scr_act())
cont.set_size(320, 200)
cont.center()
cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)

for i in range(30):
    btn = lv.btn(cont)
    btn.set_size(80, 50)
    btn.add_flag(lv.obj.FLAG.EVENT_BUBBLE)

    label = lv.label(btn)
    label.set_text(str(i))
    label.center()

cont.add_event_cb(event_cb, lv.EVENT.CLICKED, None)

Draw event

C code  

 GitHub
#include "../lv_examples.h"

#if LV_BUILD_EXAMPLES

static uint32_t size = 0;
static bool size_dec = false;

static void timer_cb(lv_timer_t * timer)
{
    lv_obj_invalidate(timer->user_data);
    if(size_dec) size--;
    else size++;

    if(size == 50) size_dec = true;
    else if(size == 0) size_dec = false;
}

static void event_cb(lv_event_t * e)
{
    lv_obj_t * obj = lv_event_get_target(e);
    lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
    if(dsc->class_p == &lv_obj_class && dsc->part == LV_PART_MAIN) {
        lv_draw_rect_dsc_t draw_dsc;
        lv_draw_rect_dsc_init(&draw_dsc);
        draw_dsc.bg_color = lv_color_hex(0xffaaaa);
        draw_dsc.radius = LV_RADIUS_CIRCLE;
        draw_dsc.border_color = lv_color_hex(0xff5555);
        draw_dsc.border_width = 2;
        draw_dsc.outline_color = lv_color_hex(0xff0000);
        draw_dsc.outline_pad = 3;
        draw_dsc.outline_width = 2;

        lv_area_t a;
        a.x1 = 0;
        a.y1 = 0;
        a.x2 = size;
        a.y2 = size;
        lv_area_align(&obj->coords, &a, LV_ALIGN_CENTER, 0, 0);

        lv_draw_rect(dsc->draw_ctx, &draw_dsc, &a);
    }
}

/**
 * Demonstrate the usage of draw event
 */
void lv_example_event_4(void)
{
    lv_obj_t * cont = lv_obj_create(lv_scr_act());
    lv_obj_set_size(cont, 200, 200);
    lv_obj_center(cont);
    lv_obj_add_event_cb(cont, event_cb, LV_EVENT_DRAW_PART_END, NULL);
    lv_timer_create(timer_cb, 30, cont);
}

#endif

MicroPython code  

 GitHub Simulator
class LV_Example_Event_4:

    def __init__(self):
        #
        # Demonstrate the usage of draw event
        #
        self.size = 0
        self.size_dec = False
        self.cont = lv.obj(lv.scr_act())
        self.cont.set_size(200, 200)
        self.cont.center()
        self.cont.add_event_cb(self.event_cb, lv.EVENT.DRAW_PART_END, None)
        lv.timer_create(self.timer_cb, 30, None)
        
    def timer_cb(self,timer) :
        self.cont.invalidate()
        if self.size_dec :
            self.size -= 1
        else :
            self.size += 1

        if self.size == 50 :
            self.size_dec = True
        elif self.size == 0:
            self.size_dec = False

    def event_cb(self,e) :
        obj = e.get_target()
        dsc = e.get_draw_part_dsc()
        if dsc.class_p == lv.obj_class and dsc.part == lv.PART.MAIN :
            draw_dsc = lv.draw_rect_dsc_t()
            draw_dsc.init()
            draw_dsc.bg_color = lv.color_hex(0xffaaaa)
            draw_dsc.radius = lv.RADIUS_CIRCLE
            draw_dsc.border_color = lv.color_hex(0xff5555)
            draw_dsc.border_width = 2
            draw_dsc.outline_color = lv.color_hex(0xff0000)
            draw_dsc.outline_pad = 3
            draw_dsc.outline_width = 2
            
            a = lv.area_t()
            a.x1 = 0
            a.y1 = 0
            a.x2 = self.size
            a.y2 = self.size
            coords = lv.area_t()
            obj.get_coords(coords)
            coords.align(a, lv.ALIGN.CENTER, 0, 0)
            
            dsc.draw_ctx.rect(draw_dsc, a)

lv_example_event_4 = LV_Example_Event_4()

API

Typedefs

typedef struct _lv_event_t lv_event_t
typedef void (*lv_event_cb_t)(lv_event_t *e)

Event callback. Events are used to notify the user of some action being taken on the object. For details, see ::lv_event_t.

Enums

enum lv_event_code_t

Type of event being sent to the object.

Values:

enumerator LV_EVENT_ALL
enumerator LV_EVENT_PRESSED

Input device events The object has been pressed

enumerator LV_EVENT_PRESSING

The object is being pressed (called continuously while pressing)

enumerator LV_EVENT_PRESS_LOST

The object is still being pressed but slid cursor/finger off of the object

enumerator LV_EVENT_SHORT_CLICKED

The object was pressed for a short period of time, then released it. Not called if scrolled.

enumerator LV_EVENT_LONG_PRESSED

Object has been pressed for at least long_press_time. Not called if scrolled.

enumerator LV_EVENT_LONG_PRESSED_REPEAT

Called after long_press_time in every long_press_repeat_time ms. Not called if scrolled.

enumerator LV_EVENT_CLICKED

Called on release if not scrolled (regardless to long press)

enumerator LV_EVENT_RELEASED

Called in every cases when the object has been released

enumerator LV_EVENT_SCROLL_BEGIN

Scrolling begins. The event parameter is a pointer to the animation of the scroll. Can be modified

enumerator LV_EVENT_SCROLL_THROW_BEGIN
enumerator LV_EVENT_SCROLL_END

Scrolling ends

enumerator LV_EVENT_SCROLL

Scrolling

enumerator LV_EVENT_GESTURE

A gesture is detected. Get the gesture with lv_indev_get_gesture_dir(lv_indev_get_act());

enumerator LV_EVENT_KEY

A key is sent to the object. Get the key with lv_indev_get_key(lv_indev_get_act());

enumerator LV_EVENT_FOCUSED

The object is focused

enumerator LV_EVENT_DEFOCUSED

The object is defocused

enumerator LV_EVENT_LEAVE

The object is defocused but still selected

enumerator LV_EVENT_HIT_TEST

Perform advanced hit-testing

enumerator LV_EVENT_COVER_CHECK

Drawing events Check if the object fully covers an area. The event parameter is lv_cover_check_info_t *.

enumerator LV_EVENT_REFR_EXT_DRAW_SIZE

Get the required extra draw area around the object (e.g. for shadow). The event parameter is lv_coord_t * to store the size.

enumerator LV_EVENT_DRAW_MAIN_BEGIN

Starting the main drawing phase

enumerator LV_EVENT_DRAW_MAIN

Perform the main drawing

enumerator LV_EVENT_DRAW_MAIN_END

Finishing the main drawing phase

enumerator LV_EVENT_DRAW_POST_BEGIN

Starting the post draw phase (when all children are drawn)

enumerator LV_EVENT_DRAW_POST

Perform the post draw phase (when all children are drawn)

enumerator LV_EVENT_DRAW_POST_END

Finishing the post draw phase (when all children are drawn)

enumerator LV_EVENT_DRAW_PART_BEGIN

Starting to draw a part. The event parameter is lv_obj_draw_dsc_t *.

enumerator LV_EVENT_DRAW_PART_END

Finishing to draw a part. The event parameter is lv_obj_draw_dsc_t *.

enumerator LV_EVENT_VALUE_CHANGED

Special events The object's value has changed (i.e. slider moved)

enumerator LV_EVENT_INSERT

A text is inserted to the object. The event data is char * being inserted.

enumerator LV_EVENT_REFRESH

Notify the object to refresh something on it (for the user)

enumerator LV_EVENT_READY

A process has finished

enumerator LV_EVENT_CANCEL

A process has been cancelled

enumerator LV_EVENT_DELETE

Other events Object is being deleted

enumerator LV_EVENT_CHILD_CHANGED

Child was removed, added, or its size, position were changed

enumerator LV_EVENT_CHILD_CREATED

Child was created, always bubbles up to all parents

enumerator LV_EVENT_CHILD_DELETED

Child was deleted, always bubbles up to all parents

enumerator LV_EVENT_SCREEN_UNLOAD_START

A screen unload started, fired immediately when scr_load is called

enumerator LV_EVENT_SCREEN_LOAD_START

A screen load started, fired when the screen change delay is expired

enumerator LV_EVENT_SCREEN_LOADED

A screen was loaded

enumerator LV_EVENT_SCREEN_UNLOADED

A screen was unloaded

enumerator LV_EVENT_SIZE_CHANGED

Object coordinates/size have changed

enumerator LV_EVENT_STYLE_CHANGED

Object's style has changed

enumerator LV_EVENT_LAYOUT_CHANGED

The children position has changed due to a layout recalculation

enumerator LV_EVENT_GET_SELF_SIZE

Get the internal size of a widget

enumerator LV_EVENT_MSG_RECEIVED

Events of optional LVGL components

enumerator _LV_EVENT_LAST
enumerator LV_EVENT_PREPROCESS

Number of default events

Functions

lv_res_t lv_event_send(struct _lv_obj_t *obj, lv_event_code_t event_code, void *param)

Send an event to the object

Parameters
  • obj -- pointer to an object

  • event_code -- the type of the event from lv_event_t

  • param -- arbitrary data depending on the widget type and the event. (Usually NULL)

Returns

LV_RES_OK: obj was not deleted in the event; LV_RES_INV: obj was deleted in the event_code

lv_res_t lv_obj_event_base(const lv_obj_class_t *class_p, lv_event_t *e)

Used by the widgets internally to call the ancestor widget types's event handler

Parameters
  • class_p -- pointer to the class of the widget (NOT the ancestor class)

  • e -- pointer to the event descriptor

Returns

LV_RES_OK: the target object was not deleted in the event; LV_RES_INV: it was deleted in the event_code

struct _lv_obj_t *lv_event_get_target(lv_event_t *e)

Get the object originally targeted by the event. It's the same even if the event is bubbled.

Parameters

e -- pointer to the event descriptor

Returns

the target of the event_code

struct _lv_obj_t *lv_event_get_current_target(lv_event_t *e)

Get the current target of the event. It's the object which event handler being called. If the event is not bubbled it's the same as "normal" target.

Parameters

e -- pointer to the event descriptor

Returns

pointer to the current target of the event_code

lv_event_code_t lv_event_get_code(lv_event_t *e)

Get the event code of an event

Parameters

e -- pointer to the event descriptor

Returns

the event code. (E.g. LV_EVENT_CLICKED, LV_EVENT_FOCUSED, etc)

void *lv_event_get_param(lv_event_t *e)

Get the parameter passed when the event was sent

Parameters

e -- pointer to the event descriptor

Returns

pointer to the parameter

void *lv_event_get_user_data(lv_event_t *e)

Get the user_data passed when the event was registered on the object

Parameters

e -- pointer to the event descriptor

Returns

pointer to the user_data

void lv_event_stop_bubbling(lv_event_t *e)

Stop the event from bubbling. This is only valid when called in the middle of an event processing chain.

Parameters

e -- pointer to the event descriptor

void lv_event_stop_processing(lv_event_t *e)

Stop processing this event. This is only valid when called in the middle of an event processing chain.

Parameters

e -- pointer to the event descriptor

uint32_t lv_event_register_id(void)
void _lv_event_mark_deleted(struct _lv_obj_t *obj)

Nested events can be called and one of them might belong to an object that is being deleted. Mark this object's event_temp_data deleted to know that its lv_event_send should return LV_RES_INV

Parameters

obj -- pointer to an object to mark as deleted

struct _lv_event_dsc_t *lv_obj_add_event_cb(struct _lv_obj_t *obj, lv_event_cb_t event_cb, lv_event_code_t filter, void *user_data)

Add an event handler function for an object. Used by the user to react on event which happens with the object. An object can have multiple event handler. They will be called in the same order as they were added.

Parameters
  • obj -- pointer to an object

  • filter -- and event code (e.g. LV_EVENT_CLICKED) on which the event should be called. LV_EVENT_ALL can be sued the receive all the events.

  • event_cb -- the new event function

  • user_data -- custom data data will be available in event_cb

Returns

a pointer the event descriptor. Can be used in lv_obj_remove_event_dsc

bool lv_obj_remove_event_cb(struct _lv_obj_t *obj, lv_event_cb_t event_cb)

Remove an event handler function for an object.

Parameters
  • obj -- pointer to an object

  • event_cb -- the event function to remove, or NULL to remove the firstly added event callback

Returns

true if any event handlers were removed

bool lv_obj_remove_event_cb_with_user_data(struct _lv_obj_t *obj, lv_event_cb_t event_cb, const void *event_user_data)

Remove an event handler function with a specific user_data from an object.

Parameters
  • obj -- pointer to an object

  • event_cb -- the event function to remove, or NULL only user_data matters.

  • event_user_data -- the user_data specified in lv_obj_add_event_cb

Returns

true if any event handlers were removed

bool lv_obj_remove_event_dsc(struct _lv_obj_t *obj, struct _lv_event_dsc_t *event_dsc)

DEPRECATED because doesn't work if multiple event handlers are added to an object. Remove an event handler function for an object.

Parameters
  • obj -- pointer to an object

  • event_dsc -- pointer to an event descriptor to remove (returned by lv_obj_add_event_cb)

Returns

true if any event handlers were removed

void *lv_obj_get_event_user_data(struct _lv_obj_t *obj, lv_event_cb_t event_cb)

The user data of an event object event callback. Always the first match with event_cb will be returned.

Parameters
  • obj -- pointer to an object

  • event_cb -- the event function

Returns

the user_data

lv_indev_t *lv_event_get_indev(lv_event_t *e)

Get the input device passed as parameter to indev related events.

Parameters

e -- pointer to an event

Returns

the indev that triggered the event or NULL if called on a not indev related event

lv_obj_draw_part_dsc_t *lv_event_get_draw_part_dsc(lv_event_t *e)

Get the part draw descriptor passed as parameter to LV_EVENT_DRAW_PART_BEGIN/END.

Parameters

e -- pointer to an event

Returns

the part draw descriptor to hook the drawing or NULL if called on an unrelated event

lv_draw_ctx_t *lv_event_get_draw_ctx(lv_event_t *e)

Get the draw context which should be the first parameter of the draw functions. Namely: LV_EVENT_DRAW_MAIN/POST, LV_EVENT_DRAW_MAIN/POST_BEGIN, LV_EVENT_DRAW_MAIN/POST_END

Parameters

e -- pointer to an event

Returns

pointer to a draw context or NULL if called on an unrelated event

const lv_area_t *lv_event_get_old_size(lv_event_t *e)

Get the old area of the object before its size was changed. Can be used in LV_EVENT_SIZE_CHANGED

Parameters

e -- pointer to an event

Returns

the old absolute area of the object or NULL if called on an unrelated event

uint32_t lv_event_get_key(lv_event_t *e)

Get the key passed as parameter to an event. Can be used in LV_EVENT_KEY

Parameters

e -- pointer to an event

Returns

the triggering key or NULL if called on an unrelated event

lv_anim_t *lv_event_get_scroll_anim(lv_event_t *e)

Get the animation descriptor of a scrolling. Can be used in LV_EVENT_SCROLL_BEGIN

Parameters

e -- pointer to an event

Returns

the animation that will scroll the object. (can be modified as required)

void lv_event_set_ext_draw_size(lv_event_t *e, lv_coord_t size)

Set the new extra draw size. Can be used in LV_EVENT_REFR_EXT_DRAW_SIZE

Parameters
  • e -- pointer to an event

  • size -- The new extra draw size

lv_point_t *lv_event_get_self_size_info(lv_event_t *e)

Get a pointer to an lv_point_t variable in which the self size should be saved (width in point->x and height point->y). Can be used in LV_EVENT_GET_SELF_SIZE

Parameters

e -- pointer to an event

Returns

pointer to lv_point_t or NULL if called on an unrelated event

lv_hit_test_info_t *lv_event_get_hit_test_info(lv_event_t *e)

Get a pointer to an lv_hit_test_info_t variable in which the hit test result should be saved. Can be used in LV_EVENT_HIT_TEST

Parameters

e -- pointer to an event

Returns

pointer to lv_hit_test_info_t or NULL if called on an unrelated event

const lv_area_t *lv_event_get_cover_area(lv_event_t *e)

Get a pointer to an area which should be examined whether the object fully covers it or not. Can be used in LV_EVENT_HIT_TEST

Parameters

e -- pointer to an event

Returns

an area with absolute coordinates to check

void lv_event_set_cover_res(lv_event_t *e, lv_cover_res_t res)

Set the result of cover checking. Can be used in LV_EVENT_COVER_CHECK

Parameters
struct _lv_event_t

Public Members

struct _lv_obj_t *target
struct _lv_obj_t *current_target
lv_event_code_t code
void *user_data
void *param
struct _lv_event_t *prev
uint8_t deleted
uint8_t stop_processing
uint8_t stop_bubbling
struct lv_hit_test_info_t
#include <lv_event.h>

Used as the event parameter of LV_EVENT_HIT_TEST to check if an point can click the object or not. res should be set like this:

  • If already set to false an other event wants that point non clickable. If you want to respect it leave it as false or set true to overwrite it.

  • If already set true and point shouldn't be clickable set to false

  • If already set to true you agree that point can click the object leave it as true

Public Members

const lv_point_t *point

A point relative to screen to check if it can click the object or not

bool res

true: point can click the object; false: it cannot

struct lv_cover_check_info_t
#include <lv_event.h>

Used as the event parameter of LV_EVENT_COVER_CHECK to check if an area is covered by the object or not. In the event use const lv_area_t * area = lv_event_get_cover_area(e) to get the area to check and lv_event_set_cover_res(e, res) to set the result.

Public Members

lv_cover_res_t res
const lv_area_t *area