在显示GUI的过程中需要对某些对象进行临时隐藏或临时显示,因此需要对该对象的FLAG进行配置就可以实现对象的显示和隐藏了.
调用如下接口可以实现:
lv_obj_add_flag(user_obj, LV_OBJ_FLAG_HIDDEN);//隐藏对象lv_obj_clear_flag(user_obj, LV_OBJ_FLAG_HIDDEN);//取消隐藏
实现的函数如下:
/*-----------------* Attribute set*----------------*/void lv_obj_add_flag(lv_obj_t * obj, lv_obj_flag_t f)
{LV_ASSERT_OBJ(obj, MY_CLASS);bool was_on_layout = lv_obj_is_layout_positioned(obj);if(f & LV_OBJ_FLAG_HIDDEN) lv_obj_invalidate(obj);obj->flags |= f;if(f & LV_OBJ_FLAG_HIDDEN) {lv_obj_invalidate(obj);}if((was_on_layout != lv_obj_is_layout_positioned(obj)) || (f & (LV_OBJ_FLAG_LAYOUT_1 | LV_OBJ_FLAG_LAYOUT_2))) {lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));lv_obj_mark_layout_as_dirty(obj);}if(f & LV_OBJ_FLAG_SCROLLABLE) {lv_area_t hor_area, ver_area;lv_obj_get_scrollbar_area(obj, &hor_area, &ver_area);lv_obj_invalidate_area(obj, &hor_area);lv_obj_invalidate_area(obj, &ver_area);}
}
void lv_obj_clear_flag(lv_obj_t * obj, lv_obj_flag_t f)
{LV_ASSERT_OBJ(obj, MY_CLASS);bool was_on_layout = lv_obj_is_layout_positioned(obj);if(f & LV_OBJ_FLAG_SCROLLABLE) {lv_area_t hor_area, ver_area;lv_obj_get_scrollbar_area(obj, &hor_area, &ver_area);lv_obj_invalidate_area(obj, &hor_area);lv_obj_invalidate_area(obj, &ver_area);}obj->flags &= (~f);if(f & LV_OBJ_FLAG_HIDDEN) {lv_obj_invalidate(obj);if(lv_obj_is_layout_positioned(obj)) {lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));lv_obj_mark_layout_as_dirty(obj);}}if((was_on_layout != lv_obj_is_layout_positioned(obj)) || (f & (LV_OBJ_FLAG_LAYOUT_1 | LV_OBJ_FLAG_LAYOUT_2))) {lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));}}
其中还有很多其他配置如下:
/*** On/Off features controlling the object's behavior.* OR-ed values are possible*/
enum {LV_OBJ_FLAG_HIDDEN = (1L << 0), /**< Make the object hidden. (Like it wasn't there at all)*/LV_OBJ_FLAG_CLICKABLE = (1L << 1), /**< Make the object clickable by the input devices*/LV_OBJ_FLAG_CLICK_FOCUSABLE = (1L << 2), /**< Add focused state to the object when clicked*/LV_OBJ_FLAG_CHECKABLE = (1L << 3), /**< Toggle checked state when the object is clicked*/LV_OBJ_FLAG_SCROLLABLE = (1L << 4), /**< Make the object scrollable*/LV_OBJ_FLAG_SCROLL_ELASTIC = (1L << 5), /**< Allow scrolling inside but with slower speed*/LV_OBJ_FLAG_SCROLL_MOMENTUM = (1L << 6), /**< Make the object scroll further when "thrown"*/LV_OBJ_FLAG_SCROLL_ONE = (1L << 7), /**< Allow scrolling only one snappable children*/LV_OBJ_FLAG_SCROLL_CHAIN_HOR = (1L << 8), /**< Allow propagating the horizontal scroll to a parent*/LV_OBJ_FLAG_SCROLL_CHAIN_VER = (1L << 9), /**< Allow propagating the vertical scroll to a parent*/LV_OBJ_FLAG_SCROLL_CHAIN = (LV_OBJ_FLAG_SCROLL_CHAIN_HOR | LV_OBJ_FLAG_SCROLL_CHAIN_VER),LV_OBJ_FLAG_SCROLL_ON_FOCUS = (1L << 10), /**< Automatically scroll object to make it visible when focused*/LV_OBJ_FLAG_SCROLL_WITH_ARROW = (1L << 11), /**< Allow scrolling the focused object with arrow keys*/LV_OBJ_FLAG_SNAPPABLE = (1L << 12), /**< If scroll snap is enabled on the parent it can snap to this object*/LV_OBJ_FLAG_PRESS_LOCK = (1L << 13), /**< Keep the object pressed even if the press slid from the object*/LV_OBJ_FLAG_EVENT_BUBBLE = (1L << 14), /**< Propagate the events to the parent too*/LV_OBJ_FLAG_GESTURE_BUBBLE = (1L << 15), /**< Propagate the gestures to the parent*/LV_OBJ_FLAG_ADV_HITTEST = (1L << 16), /**< Allow performing more accurate hit (click) test. E.g. consider rounded corners.*/LV_OBJ_FLAG_IGNORE_LAYOUT = (1L << 17), /**< Make the object position-able by the layouts*/LV_OBJ_FLAG_FLOATING = (1L << 18), /**< Do not scroll the object when the parent scrolls and ignore layout*/LV_OBJ_FLAG_OVERFLOW_VISIBLE = (1L << 19), /**< Do not clip the children's content to the parent's boundary*/LV_OBJ_FLAG_LAYOUT_1 = (1L << 23), /**< Custom flag, free to use by layouts*/LV_OBJ_FLAG_LAYOUT_2 = (1L << 24), /**< Custom flag, free to use by layouts*/LV_OBJ_FLAG_WIDGET_1 = (1L << 25), /**< Custom flag, free to use by widget*/LV_OBJ_FLAG_WIDGET_2 = (1L << 26), /**< Custom flag, free to use by widget*/LV_OBJ_FLAG_USER_1 = (1L << 27), /**< Custom flag, free to use by user*/LV_OBJ_FLAG_USER_2 = (1L << 28), /**< Custom flag, free to use by user*/LV_OBJ_FLAG_USER_3 = (1L << 29), /**< Custom flag, free to use by user*/LV_OBJ_FLAG_USER_4 = (1L << 30), /**< Custom flag, free to use by user*/};