Lvgl: btn action callback function

Created on 19 Dec 2018  路  6Comments  路  Source: lvgl/lvgl

I need to add a function into button callback , and pass more than one lv_obj into that funcytion as arguments, i have gone through the documentation but couldn't find such function to set callback on button function and obj with that.
Can you tell me if it is possible what I am trying to achieve here?

question

Most helpful comment

In additionfree_ptr can any data type, like

    static struct
    {
      lv_obj_t * obj1;
      lv_obj_t * obj2;
      lv_obj_t * obj3;
    }my_data;

    lv_obj_set_free_ptr(alloc_label, &my_data);

All 6 comments

I don't really understand.

I need to add a function into button callback , and pass more than one lv_obj into that funcytion

Is it your own function? Then it can have any prototype, like

void my_func(lv_obj_t * x, lv_obj_t * y)
{
   lv_obj_set_size(x, 20, 30);
   lv_obj_set_size(x, 60, 80);
}

@kisvegabor I think what @MShahrukh0 might mean is that they want to be able to pass more than one lv_obj to their button callback. In that case maybe using lv_obj_set_free_ptr could help.

yes @embeddedt you are right that's exactly what i meant, can you please elaborate with the help of an small example?

Normally you set the button callback with lv_btn_set_action. I am going to assume that you want the first argument to your callback to be the button object, and you want to pass an unrelated second object.

Here's a partial example.

lv_obj_t *obj2 = ...;
lv_obj_t *btn = lv_btn_create(lv_scr_act(), NULL);
lv_btn_set_action(btn, LV_BTN_ACTION_CLICK, my_action);
lv_obj_set_free_ptr(btn, obj2);

...

lv_res_t my_action(lv_obj_t *btn)
{
    lv_obj_t *obj2 = lv_obj_get_free_ptr(btn);
}

You can see how I set the free_ptr of the button to obj2, and then retrieve the value later inside the callback with lv_obj_get_free_ptr.

In additionfree_ptr can any data type, like

    static struct
    {
      lv_obj_t * obj1;
      lv_obj_t * obj2;
      lv_obj_t * obj3;
    }my_data;

    lv_obj_set_free_ptr(alloc_label, &my_data);

As there was no activity here for a while I suppose the issue is solved.

If it's not working feel free the comment here and reopen this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Avamander picture Avamander  路  4Comments

kisvegabor picture kisvegabor  路  4Comments

MichaelVLV picture MichaelVLV  路  4Comments

DeonMarais64 picture DeonMarais64  路  4Comments

curly-brace picture curly-brace  路  5Comments