In Lvgl Editor generated code the LV_OBJ_FLAG_HIDDEN is local to the function. So say if a screen has 7 labels for example and label 5 has a hidden flag how to externally toggle this flag since these variables aren’t static or globals ?
Recommended: Use LVGL Subjects
In globals.xml:
<int name="subject_toggle" value="1" />
In your screen XML:
<lv_label name="my_label" text="Hello LVGL">
<bind_flag_if_eq subject="subject_toggle" flag="hidden" ref_value="1" />
</lv_label>
This way you just update the subject value and the flag is handled automatically.
Alternative: Find the object by name
If you give the label a name, you can retrieve it later:
lv_obj_t *screen = main_create(); // reference to your screen
lv_obj_t *my_label = lv_obj_find_by_name(screen, "my_label");
if (my_label) {
lv_obj_set_flag(my_label, LV_OBJ_FLAG_HIDDEN, false);
}
1 Like
Thank you for this suggestion. This would work.
Can something similar be done with lv_image as well ? Say you have an image that’s displayed under certain conditions and when those external conditions change the image is hidden and another image is shown in its place ?
The screens are created with the required images and only the one that needs to be displayed is shown the others are hidden and toggled according.
Yes, it works with any LVGL object, including lv_image