Description
Hello, i started to learn lvgl. So i tried to write a simple programm. I have button and led.
I want on the led when the button is pressed.I achieved this.But I think there is a better way to do it.
What MCU/Processor/Board and compiler are you using?
Simulator, gcc
What LVGL version are you using?
lvgl 7.3.1
What do you want to achieve?
I want to send custom data to callback function when button pressed, like in lv_event_send(obj, LV_EVENT_…, &custom_data).
I have read the documentation but cannot find something similar to what I want. If I missed something, please tell me which section I should read
Code to reproduce
My code
#include "../../lv_examples.h"
static lv_obj_t * led;
static void btn_event_cb(lv_obj_t * btn, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
lv_led_on(lednext);
}
}
void myfunc(void)
{
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_pos(btn, 10, 10);
lv_obj_set_size(btn, 120, 50);
lednext = lv_led_create(lv_scr_act(),NULL);
lv_led_off(led);
lv_obj_set_size(ledt,20,20);
lv_obj_set_pos(ledn,140,25);
lv_obj_t * label = lv_label_create(btn, NULL);
lv_label_set_text(label, "Next");
lv_obj_set_event_cb(btn,btn_event_cb);
}