lv_obj: protect field added (opa_protect and child_chg_off moved here)
This commit is contained in:
@@ -48,10 +48,10 @@ static ll_dsc_t scr_ll;
|
||||
static lv_objs_t lv_objs_def = {.color = COLOR_MAKE(0xa0, 0xc0, 0xe0), .transp = 0};
|
||||
static lv_objs_t lv_objs_scr = {.color = LV_OBJ_DEF_SCR_COLOR, .transp = 0};
|
||||
static lv_objs_t lv_objs_transp = {.transp = 1};
|
||||
|
||||
/*
|
||||
#ifdef LV_IMG_DEF_WALLPAPER
|
||||
LV_IMG_DECLARE(LV_IMG_DEF_WALLPAPER);
|
||||
#endif
|
||||
#endif*/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@@ -80,10 +80,10 @@ void lv_init(void)
|
||||
/*Create the default screen*/
|
||||
ll_init(&scr_ll, sizeof(lv_obj_t));
|
||||
#ifdef LV_IMG_DEF_WALLPAPER
|
||||
lv_img_create_file("def_wp", LV_IMG_DEF_WALLPAPER);
|
||||
// lv_img_create_file("def_wp", LV_IMG_DEF_WALLPAPER);
|
||||
def_scr = lv_img_create(NULL, NULL);
|
||||
lv_img_set_auto_size(def_scr, false);
|
||||
lv_img_set_file(def_scr, "U:/def_wp");
|
||||
lv_img_set_file(def_scr, LV_IMG_DEF_WALLPAPER);
|
||||
#else
|
||||
def_scr = lv_obj_create(NULL, NULL);
|
||||
#endif
|
||||
@@ -206,8 +206,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
|
||||
new_obj->style_iso = 0;
|
||||
new_obj->hidden = 0;
|
||||
new_obj->top_en = 0;
|
||||
new_obj->child_chg_off = 0;
|
||||
new_obj->opa_protect = 0;
|
||||
new_obj->protect = LV_OBJ_PROT_NONE;
|
||||
|
||||
new_obj->ext = NULL;
|
||||
}
|
||||
@@ -244,8 +243,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
|
||||
new_obj->style_iso = 0;
|
||||
new_obj->hidden = 0;
|
||||
new_obj->top_en = 0;
|
||||
new_obj->child_chg_off = 0;
|
||||
new_obj->opa_protect = 0;
|
||||
new_obj->protect = LV_OBJ_PROT_NONE;
|
||||
|
||||
new_obj->ext = NULL;
|
||||
|
||||
@@ -265,7 +263,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
|
||||
new_obj->hidden = copy->hidden;
|
||||
new_obj->style_iso = copy->style_iso;
|
||||
new_obj->top_en = copy->top_en;
|
||||
new_obj->opa_protect = copy->opa_protect;
|
||||
new_obj->protect = copy->protect;
|
||||
|
||||
if(copy->style_iso == 0) {
|
||||
new_obj->style_p = copy->style_p;
|
||||
@@ -356,7 +354,7 @@ bool lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_CHILD_CHG:
|
||||
/*Return 'invalid' if the child change signal is not enabled*/
|
||||
if(obj->child_chg_off != 0) valid = false;
|
||||
if(lv_obj_is_protected(obj, LV_OBJ_PROT_CHILD_CHG) != false) valid = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -875,7 +873,8 @@ void lv_obj_set_opar(lv_obj_t * obj, uint8_t opa)
|
||||
lv_obj_set_opar(i, opa);
|
||||
}
|
||||
|
||||
if(obj->opa_protect == 0) obj->opa = opa;
|
||||
/*Set the opacity is the object is not protected*/
|
||||
if(lv_obj_is_protected(obj, LV_OBJ_PROT_OPA) == false) obj->opa = opa;
|
||||
|
||||
lv_obj_inv(obj);
|
||||
}
|
||||
@@ -953,14 +952,26 @@ void lv_obj_set_drag_parent(lv_obj_t * obj, bool en)
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not let 'lv_obj_set_opar' to set the opacity
|
||||
* Set a bit or bits in the protect filed
|
||||
* @param obj pointer to an object
|
||||
* @param en true: enable the 'opa_protect' for the object
|
||||
* @param prot 'OR'-ed values from lv_obj_prot_t
|
||||
*/
|
||||
void lv_obj_set_opa_protect(lv_obj_t * obj, bool en)
|
||||
void lv_obj_set_protect(lv_obj_t * obj, uint8_t prot)
|
||||
{
|
||||
obj->opa_protect = (en == true ? 1 : 0);
|
||||
obj->protect |= prot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a bit or bits in the protect filed
|
||||
* @param obj pointer to an object
|
||||
* @param prot 'OR'-ed values from lv_obj_prot_t
|
||||
*/
|
||||
void lv_obj_clr_protect(lv_obj_t * obj, uint8_t prot)
|
||||
{
|
||||
prot = (~prot) & 0xFF;
|
||||
obj->protect &= prot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the signal function of an object.
|
||||
* Always call the previous signal function in the new.
|
||||
@@ -1373,13 +1384,24 @@ bool lv_obj_get_style_iso(lv_obj_t * obj)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the opa_protect attribute of an object
|
||||
* Get the protect field of an object
|
||||
* @param obj pointer to an object
|
||||
* @return true: opa_protect is enabled
|
||||
* @return protect field ('OR'ed values of lv_obj_prot_t)
|
||||
*/
|
||||
bool lv_obj_get_opa_protect(lv_obj_t * obj)
|
||||
uint8_t lv_obj_get_protect(lv_obj_t * obj)
|
||||
{
|
||||
return obj->opa_protect == 0 ? false : true;
|
||||
return obj->protect ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check at least one bit of a given protect bitfield is set
|
||||
* @param obj pointer to an object
|
||||
* @param prot protect bits to test ('OR'ed values of lv_obj_prot_t)
|
||||
* @return false: none of the given bits are set, true: at least one bit is set
|
||||
*/
|
||||
bool lv_obj_is_protected(lv_obj_t * obj, uint8_t prot)
|
||||
{
|
||||
return (obj->protect & prot) == 0 ? false : true ;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,15 +92,17 @@ typedef struct __LV_OBJ_T
|
||||
#endif
|
||||
|
||||
/*Attributes and states*/
|
||||
uint16_t click_en :1; /*1: can be pressed by a display input device*/
|
||||
uint16_t drag_en :1; /*1: enable the dragging*/
|
||||
uint16_t drag_throw_en:1; /*1: Enable throwing with drag*/
|
||||
uint16_t drag_parent :1; /*1. Parent will be dragged instead*/
|
||||
uint16_t style_iso :1; /*1: The object has got an own style*/
|
||||
uint16_t hidden :1; /*1: Object is hidden*/
|
||||
uint16_t top_en :1; /*1: If the object or its children is clicked it goes to the foreground*/
|
||||
uint16_t child_chg_off:1; /*1: Disable the child change signal. Used by the library*/
|
||||
uint16_t opa_protect :1; /*1: Do not let 'lv_obj_set_opar' to set the opacity*/
|
||||
uint8_t click_en :1; /*1: can be pressed by a display input device*/
|
||||
uint8_t drag_en :1; /*1: enable the dragging*/
|
||||
uint8_t drag_throw_en:1; /*1: Enable throwing with drag*/
|
||||
uint8_t drag_parent :1; /*1. Parent will be dragged instead*/
|
||||
uint8_t style_iso :1; /*1: The object has got an own style*/
|
||||
uint8_t hidden :1; /*1: Object is hidden*/
|
||||
uint8_t top_en :1; /*1: If the object or its children is clicked it goes to the foreground*/
|
||||
uint8_t reserved :1;
|
||||
|
||||
uint8_t protect; /*Automatically happening actions can be prevented. 'OR'ed values from lv_obj_prot_t*/
|
||||
|
||||
cord_t ext_size; /*EXTtend the size of the object in every direction. Used to draw shadow, shine etc.*/
|
||||
|
||||
uint8_t free_num; /*Application specific identifier (set it freely)*/
|
||||
@@ -109,6 +111,14 @@ typedef struct __LV_OBJ_T
|
||||
|
||||
}lv_obj_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LV_OBJ_PROT_NONE = 0x00,
|
||||
LV_OBJ_PROT_CHILD_CHG = 0x01, /*Disable the child change signal. Used by the library*/
|
||||
LV_OBJ_PROT_OPA = 0x02, /*Prevent lv_obj_set_opar to modify the opacity*/
|
||||
LV_OBJ_PROT_PARENT = 0x04, /*Prevent automatic (hidden) parent change (e.g. in lv_page)*/
|
||||
}lv_obj_protect_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LV_ALIGN_CENTER = 0,
|
||||
@@ -204,7 +214,8 @@ void lv_obj_set_top(lv_obj_t * obj, bool en);
|
||||
void lv_obj_set_drag(lv_obj_t * obj, bool en);
|
||||
void lv_obj_set_drag_throw(lv_obj_t * obj, bool en);
|
||||
void lv_obj_set_drag_parent(lv_obj_t * obj, bool en);
|
||||
void lv_obj_set_opa_protect(lv_obj_t * obj, bool en);
|
||||
void lv_obj_set_protect(lv_obj_t * obj, uint8_t prot);
|
||||
void lv_obj_clr_protect(lv_obj_t * obj, uint8_t prot);
|
||||
/*Other set*/
|
||||
void lv_obj_set_signal_f(lv_obj_t * obj, lv_signal_f_t fp);
|
||||
void lv_obj_set_design_f(lv_obj_t * obj, lv_design_f_t fp);
|
||||
@@ -242,7 +253,8 @@ bool lv_obj_get_drag(lv_obj_t * obj);
|
||||
bool lv_obj_get_drag_throw(lv_obj_t * obj);
|
||||
bool lv_obj_get_drag_parent(lv_obj_t * obj);
|
||||
bool lv_obj_get_style_iso(lv_obj_t * obj);
|
||||
bool lv_obj_get_opa_potect(lv_obj_t * obj);
|
||||
uint8_t lv_obj_get_protect(lv_obj_t * obj);
|
||||
bool lv_obj_is_protected(lv_obj_t * obj, uint8_t prot);
|
||||
|
||||
/*Virtual functions get*/
|
||||
lv_design_f_t lv_obj_get_design_f(lv_obj_t * obj);
|
||||
|
||||
@@ -82,6 +82,7 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
lv_obj_set_signal_f(ext->scrl, lv_scrl_signal);
|
||||
lv_obj_set_drag(ext->scrl, true);
|
||||
lv_obj_set_drag_throw(ext->scrl, true);
|
||||
lv_obj_set_protect(ext->scrl, LV_OBJ_PROT_PARENT);
|
||||
lv_rect_set_fit(ext->scrl, true, true);
|
||||
lv_obj_set_style(ext->scrl, &pages->scrl_rects);
|
||||
|
||||
@@ -135,10 +136,10 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
|
||||
lv_pages_t * pages = lv_obj_get_style(page);
|
||||
lv_obj_t * child;
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_CHILD_CHG: /*Be sure, only scrollable object is on the page*/
|
||||
case LV_SIGNAL_CHILD_CHG: /*Move children to the scrollable object*/
|
||||
child = lv_obj_get_child(page, NULL);
|
||||
while(child != NULL) {
|
||||
if(child != ext->scrl) {
|
||||
if(lv_obj_is_protected(child, LV_OBJ_PROT_PARENT) == false) {
|
||||
lv_obj_t * tmp = child;
|
||||
child = lv_obj_get_child(page, child); /*Get the next child before move this*/
|
||||
lv_obj_set_parent(tmp, ext->scrl);
|
||||
@@ -410,8 +411,8 @@ void lv_page_focus(lv_obj_t * page, lv_obj_t * obj, bool anim_en)
|
||||
a.fp = (anim_fp_t) lv_obj_set_y;
|
||||
anim_create(&a);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*=====================
|
||||
|
||||
@@ -411,7 +411,6 @@ static void lv_rect_layout_col(lv_obj_t * rect)
|
||||
|
||||
switch(type) {
|
||||
case LV_RECT_LAYOUT_COL_L:
|
||||
hpad_corr = style->hpad;
|
||||
align = LV_ALIGN_IN_TOP_LEFT;
|
||||
break;
|
||||
case LV_RECT_LAYOUT_COL_M:
|
||||
@@ -430,7 +429,7 @@ static void lv_rect_layout_col(lv_obj_t * rect)
|
||||
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
rect->child_chg_off = 1;
|
||||
lv_obj_set_protect(rect, LV_OBJ_PROT_CHILD_CHG);
|
||||
/* Align the children */
|
||||
cord_t last_cord = style->vpad;
|
||||
LL_READ_BACK(rect->child_ll, child) {
|
||||
@@ -440,7 +439,7 @@ static void lv_rect_layout_col(lv_obj_t * rect)
|
||||
last_cord += lv_obj_get_height(child) + style->opad;
|
||||
}
|
||||
|
||||
rect->child_chg_off = 0;
|
||||
lv_obj_clr_protect(rect, LV_OBJ_PROT_CHILD_CHG);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -478,7 +477,7 @@ static void lv_rect_layout_row(lv_obj_t * rect)
|
||||
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
rect->child_chg_off = 1;
|
||||
lv_obj_set_protect(rect, LV_OBJ_PROT_CHILD_CHG);
|
||||
|
||||
/* Align the children */
|
||||
cord_t last_cord = style->hpad;
|
||||
@@ -489,7 +488,7 @@ static void lv_rect_layout_row(lv_obj_t * rect)
|
||||
last_cord += lv_obj_get_width(child) + style->opad;
|
||||
}
|
||||
|
||||
rect->child_chg_off = 0;
|
||||
lv_obj_clr_protect(rect, LV_OBJ_PROT_CHILD_CHG);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -514,7 +513,7 @@ static void lv_rect_layout_center(lv_obj_t * rect)
|
||||
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
rect->child_chg_off = 1;
|
||||
lv_obj_set_protect(rect, LV_OBJ_PROT_CHILD_CHG);
|
||||
|
||||
/* Align the children */
|
||||
cord_t last_cord = - (h_tot / 2);
|
||||
@@ -525,7 +524,7 @@ static void lv_rect_layout_center(lv_obj_t * rect)
|
||||
last_cord += lv_obj_get_height(child) + style->opad;
|
||||
}
|
||||
|
||||
rect->child_chg_off = 0;
|
||||
lv_obj_clr_protect(rect, LV_OBJ_PROT_CHILD_CHG);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -547,7 +546,7 @@ static void lv_rect_layout_pretty(lv_obj_t * rect)
|
||||
child_rs = ll_get_tail(&rect->child_ll); /*Set the row starter child*/
|
||||
if(child_rs == NULL) return; /*Return if no child*/
|
||||
|
||||
rect->child_chg_off = 1;
|
||||
lv_obj_set_protect(rect, LV_OBJ_PROT_CHILD_CHG);
|
||||
|
||||
child_rc = child_rs; /*Initially the the row starter and closer is the same*/
|
||||
while(child_rs != NULL) {
|
||||
@@ -555,7 +554,8 @@ static void lv_rect_layout_pretty(lv_obj_t * rect)
|
||||
cord_t w_row = style->hpad * 2; /*The width is minimum the left-right hpad*/
|
||||
uint32_t obj_num = 0;
|
||||
|
||||
/*Find the row closer object and collect some data*/ do {
|
||||
/*Find the row closer object and collect some data*/
|
||||
do {
|
||||
if(lv_obj_get_hidden(child_rc) == false) {
|
||||
if(w_row + lv_obj_get_width(child_rc) > w_obj) break; /*If the next object is already not fit then break*/
|
||||
w_row += lv_obj_get_width(child_rc) + style->opad; /*Add the object width + opad*/
|
||||
@@ -601,7 +601,7 @@ static void lv_rect_layout_pretty(lv_obj_t * rect)
|
||||
child_rs = ll_get_prev(&rect->child_ll, child_rc); /*Go to the next object*/
|
||||
child_rc = child_rs;
|
||||
}
|
||||
rect->child_chg_off = 0;
|
||||
lv_obj_clr_protect(rect, LV_OBJ_PROT_CHILD_CHG);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -626,7 +626,7 @@ static void lv_rect_layout_grid(lv_obj_t * rect)
|
||||
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
rect->child_chg_off = 1;
|
||||
lv_obj_set_protect(rect, LV_OBJ_PROT_CHILD_CHG);
|
||||
|
||||
/* Align the children */
|
||||
cord_t act_x = style->hpad;
|
||||
@@ -650,8 +650,7 @@ static void lv_rect_layout_grid(lv_obj_t * rect)
|
||||
}
|
||||
}
|
||||
|
||||
rect->child_chg_off = 0;
|
||||
|
||||
lv_obj_clr_protect(rect, LV_OBJ_PROT_CHILD_CHG);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user