Getting the object name of a widget

I want to filter in the event routine of a textarea to determine the object name of the ta that fired the event so I can use the same event handler for multiple ta’s.

What is the correct syntax to the the object name?

Here is my example
if(ta.objectname() == ta1) do something

This does not seem to work, looking for the correct syntax.


Use lv_obj_get_type.

Here is the code that I tried:

lv_obj_type_t *buff;
  if(buff == pwd_ta)
    Serial.println("Not pwd_ta");

But, it did not work.
Can you be a bit more specific?


This should work:

    lv_obj_type_t buf;
    lv_obj_get_type(obj, &buf);

    uint8_t i = 0;
    while(buf.type[i] != NULL) {
        if(!strcmp(buf.type[i], "lv_textarea")) { /* use lv_ta for 6.1 and under */
            /* It inherits from a text area*/

Well, I think there is some confusion here. What I really need is the name of the textarea.
For my application I have 2 textareas each with a different name, i.e. ta1 and ta2.
In the event handler I need to filter on which specific textarea fired the event, either ta1 or ta2.
Getting the object type won’t distinguish which textarea the event was fired.

Make sense?


Whoops… I misunderstood what you wanted. I thought you were trying to distinguish types of objects. If you are trying to determine which object, then this is much easier. Just keep the object reference in a global variable and compare it to the one passed to the event handler.

lv_obj_t * ta1, * ta2;

void create(void) {
    /* create text areas */
    ta1 = lv_textarea_create(lv_scr_act(), NULL);
void event_cb(lv_obj_t * obj, lv_event_t event)
    if(obj == ta1) { /* ta1 */ }
    else if(obj == ta2) { /* ta2 */ }

That’s what I was looking for…Thanks!!
Works perfectly!!

I would like to try this solution, but how do we use lv_obj_add_event_cb() for adding an event function with 2 arguments lv_obj_t * obj and lv_event_t event ?

If I try to add an event with two arguments, I have an error.

void ui_event_MyEvent(lv_obj_t * obj, lv_event_t * e) { 

lv_obj_add_event_cb(MyObject, ui_event_MyEventl, LV_EVENT_ALL, NULL);

error: invalid conversion from ‘void ()(lv_obj_t, lv_event_t*)’ {aka ‘void ()(_lv_obj_t, _lv_event_t*)’} to ‘lv_event_cb_t’ {aka ‘void ()(_lv_event_t)’}

Thanks !

void ui_event_MyEvent(lv_event_t *e) { 
    lv_obj_t *obj = lv_event_get_target_obj(e);