Description
Hi Team,
Hope you all doing good
i have a small doubt with area widget.
i have created an custom view for list using area.
i created 3 labels inside the area widget and assigning text using arrays.
if i click on area i want to print their respective text.
For Example:
if i click on the first area i want to print devicename(“kitchen”) showing in that area. but printing last value “foyer”
attached event handler function also.
What MCU/Processor/Board and compiler are you using?
ARM
What LVGL version are you using?
7
What do you want to achieve?
if i click on area i want to print their respective text.
For Example:
if i click on the first area i want to print devicename(“kitchen”) showing in that area. but printing last value “foyer”
attached event handler function also.
What have you tried so far?
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
The code block(s) should be formatted like:
char *array_devicename[]={"kitchen","bedroom","office","bathroom","foyer"};
char *array_type[]={"Dimmer","Switch","Thermostat","Smart plug","Camera"};
char *array_client[]={"Philips","Tp-Link","iotgizmo","Wemo","Nest"};
int length=sizeof(array_devicename)/sizeof(array_devicename[0]);
for(int i=0;i<length;i++){
// add an area
lv_obj_t * area = lv_obj_create(page, NULL);
lv_obj_set_size(area, 450, 150);
lv_obj_add_style(area, LV_OBJ_PART_MAIN, &style_box);
lv_obj_align(area, NULL, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
// adding stuff to area
//devicename
devicename = lv_label_create(area, NULL);
lv_label_set_recolor(devicename, true);
lv_label_set_text(devicename,array_devicename[i]);
lv_obj_align(devicename,NULL,LV_ALIGN_IN_TOP_LEFT,10,10);
//devicetype
lv_obj_t * devicetype = lv_label_create(area, NULL);
lv_label_set_recolor(devicetype, true);
lv_label_set_text(devicetype,array_type[i]);
lv_obj_align(devicetype,NULL,LV_ALIGN_IN_TOP_MID,0,10);
//client
lv_obj_t * client = lv_label_create(area, NULL);
lv_label_set_recolor(client, true);
lv_label_set_text(client,array_client[i]);
lv_obj_align(client,NULL,LV_ALIGN_IN_TOP_RIGHT,-10,10);
lv_obj_set_click(area, true);
lv_obj_set_drag_parent(area, true); // need this to scroll page properly
lv_obj_set_event_cb(area, page_event_handler);
static void page_event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
const char *clickdev=lv_label_get_text(devicename);
printf("Device ID: %s\n",clickdev);
}
}
Thanks in Advance.
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.