Flags

Some widget attributes can be enabled or disabled using lv_obj_add_flag and lv_obj_remove_flag.

Edit on GitHub

Deprecating Flags

Flags are deprecated in LVGL v9.6 and will be removed in LVGL v10. Use a dedicated function instead, such as lv_obj_set_hidden.

lv_obj_set_user_flag and lv_obj_get_user_flag can be used to replace LV_OBJ_FLAG_USER_1-4, it takes in a bit from 0 to 3 instead of the old flag constant, e.g lv_obj_set_user_flag(obj, 0, true)

Some widget attributes can be enabled or disabled using lv_obj_add_flag(widget, LV_OBJ_FLAG_...) and lv_obj_remove_flag(widget, LV_OBJ_FLAG_...).

To save memory, widgets store these flags in a bitfield. To check if a flag is set, use: lv_obj_has_flag(obj, LV_OBJ_FLAG_...).

The available flags are:

Some examples:

 
/* Hide a Widget */
lv_obj_add_flag(widget, LV_OBJ_FLAG_HIDDEN);

/* Make a Widget non-clickable */
lv_obj_remove_flag(widget, LV_OBJ_FLAG_CLICKABLE);

/* Check if it is clickable */
if(lv_obj_has_flag(widget, LV_OBJ_FLAG_CLICKABLE)) printf("Clickable\n");

Adding and/or Removing Multiple Flags

When adding or removing multiple flags, you have two options:

Option 1: Multiple calls (Recommended)

This approach is clearer and works seamlessly in both C and C++:

 
lv_obj_add_flag(widget, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_flag(widget, LV_OBJ_FLAG_EVENT_BUBBLE);

Option 2: Single call with bitwise OR

You can combine multiple flags in one call using the bitwise OR operator (|). When using a C++ compiler, you must cast the result:

 
lv_obj_add_flag(widget, (lv_obj_flag_t)(LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_EVENT_BUBBLE));

The cast to lv_obj_flag_t is required in C++ due to stricter type checking, but is optional in C.

Last updated on

On this page