diff --git a/src/lv_core/lv_grid.c b/src/lv_core/lv_grid.c index 6d4b3665b..a7a08a588 100644 --- a/src/lv_core/lv_grid.c +++ b/src/lv_core/lv_grid.c @@ -216,7 +216,7 @@ static void calc_implicit_cols(lv_obj_t * cont, _lv_grid_calc_t * calc) uint32_t child_cnt = lv_obj_count_children(cont); - uint32_t col_cnt = (child_cnt / grid->row_dsc_len) + 1; + uint32_t col_cnt = ((child_cnt + grid->row_dsc_len - 1) / grid->row_dsc_len) + 1; /*+ grid->row_dsc_len - 1 to round up*/ /* If `col_dsc_buf_used`, nested a call of this func. will release `col_dsc_buf_used` because it think it taken it. * So mark that if the buffer was taken in this call*/ bool col_dsc_buf_mine = false; @@ -272,7 +272,7 @@ static void calc_implicit_rows(lv_obj_t * cont, _lv_grid_calc_t * calc) lv_grid_t * grid = cont->grid; uint32_t child_cnt = lv_obj_count_children(cont); - uint32_t row_cnt = (child_cnt / grid->col_dsc_len) + 1; + uint32_t row_cnt = ((child_cnt + grid->col_dsc_len - 1) / grid->col_dsc_len) + 1; /*+ grid->col_dsc_len - 1 to round up*/ bool row_dsc_buf_mine = false; /*At worst case all children is gird item prepare place for all of them*/ lv_coord_t * rows_h; diff --git a/src/lv_core/lv_group.c b/src/lv_core/lv_group.c index a926a5a0c..d5567b1ab 100644 --- a/src/lv_core/lv_group.c +++ b/src/lv_core/lv_group.c @@ -31,7 +31,6 @@ static void focus_next_core(lv_group_t * group, void * (*begin)(const lv_ll_t *), void * (*move)(const lv_ll_t *, const void *)); static void lv_group_refocus(lv_group_t * g); -static void obj_to_foreground(lv_obj_t * obj); /********************** * STATIC VARIABLES @@ -241,9 +240,6 @@ void lv_group_focus_obj(lv_obj_t * obj) lv_res_t res = lv_event_send(*g->obj_focus, LV_EVENT_FOCUSED, NULL); if(res != LV_RES_OK) return; lv_obj_invalidate(*g->obj_focus); - - /*If the object or its parent has `top == true` bring it to the foreground*/ - obj_to_foreground(*g->obj_focus); } break; } @@ -490,7 +486,7 @@ static void focus_next_core(lv_group_t * group, void * (*begin)(const lv_ll_t *) if(obj_next == NULL) continue; /*Hidden objects don't receive focus*/ - if(!lv_obj_get_hidden(*obj_next)) break; + if(lv_obj_has_flag(*obj_next, LV_OBJ_FLAG_HIDDEN) == false) break; } if(obj_next == group->obj_focus) return; /*There's only one visible object and it's already focused*/ @@ -508,28 +504,10 @@ static void focus_next_core(lv_group_t * group, void * (*begin)(const lv_ll_t *) lv_res_t res = lv_event_send(*group->obj_focus, LV_EVENT_FOCUSED, NULL); if(res != LV_RES_OK) return; - /*If the object or its parent has `top == true` bring it to the foreground*/ - obj_to_foreground(*group->obj_focus); - lv_obj_invalidate(*group->obj_focus); if(group->focus_cb) group->focus_cb(group); } -static void obj_to_foreground(lv_obj_t * obj) -{ - /*Search for 'top' attribute*/ - lv_obj_t * i = obj; - lv_obj_t * last_top = NULL; - while(i != NULL) { - if(i->top != 0) last_top = i; - i = lv_obj_get_parent(i); - } - - if(last_top != NULL) { - /*Move the last_top object to the foreground*/ - lv_obj_move_foreground(last_top); - } -} #endif /*LV_USE_GROUP != 0*/ diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index e820fe127..3a258729d 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -212,7 +212,7 @@ void lv_indev_set_cursor(lv_indev_t * indev, lv_obj_t * cur_obj) indev->cursor = cur_obj; lv_obj_set_parent(indev->cursor, lv_disp_get_layer_sys(indev->driver.disp)); lv_obj_set_pos(indev->cursor, indev->proc.types.pointer.act_point.x, indev->proc.types.pointer.act_point.y); - lv_obj_set_click(indev->cursor, false); + lv_obj_add_flag(indev->cursor, LV_OBJ_FLAG_CLICKABLE); } #if LV_USE_GROUP @@ -831,7 +831,7 @@ static void indev_proc_press(lv_indev_proc_t * proc) } /*If there is last object but it is not scrolled and not protected also search*/ else if(proc->types.pointer.scroll_obj == NULL && - lv_obj_is_protected(indev_obj_act, LV_PROTECT_PRESS_LOST) == false) { + lv_obj_has_flag(indev_obj_act, LV_OBJ_FLAG_PRESS_LOCK) == false) { indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_sys(disp), &proc->types.pointer.act_point); if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_top(disp), &proc->types.pointer.act_point); @@ -884,19 +884,6 @@ static void indev_proc_press(lv_indev_proc_t * proc) proc->types.pointer.vect.x = 0; proc->types.pointer.vect.y = 0; - /*Search for 'top' attribute*/ - lv_obj_t * i = indev_obj_act; - lv_obj_t * last_top = NULL; - while(i != NULL) { - if(i->top) last_top = i; - i = lv_obj_get_parent(i); - } - - if(last_top != NULL) { - /*Move the last_top object to the foreground*/ - lv_obj_move_foreground(last_top); - } - /*Send a signal about the press*/ lv_signal_send(indev_obj_act, LV_SIGNAL_PRESSED, indev_act); if(indev_reset_check(proc)) return; @@ -1079,10 +1066,10 @@ lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t * point) /*If then the children was not ok, and this obj is clickable * and it or its parent is not hidden then save this object*/ - if(found_p == NULL && lv_obj_get_click(obj) != false) { + if(found_p == NULL && lv_obj_has_flag(obj, LV_OBJ_FLAG_CLICKABLE)) { lv_obj_t * hidden_i = obj; while(hidden_i != NULL) { - if(lv_obj_get_hidden(hidden_i) == true) break; + if(lv_obj_has_flag(obj, LV_OBJ_FLAG_HIDDEN) == true) break; hidden_i = lv_obj_get_parent(hidden_i); } /*No parent found with hidden == true*/ @@ -1101,7 +1088,7 @@ static void indev_click_focus(lv_indev_proc_t * proc) { /*Handle click focus*/ lv_obj_t * obj_to_focus = lv_obj_get_focused_obj(indev_obj_act); - if(lv_obj_is_protected(indev_obj_act, LV_PROTECT_CLICK_FOCUS) == false && + if(lv_obj_has_flag(indev_obj_act, LV_OBJ_FLAG_PRESS_LOCK) == false && proc->types.pointer.last_pressed != obj_to_focus) { #if LV_USE_GROUP lv_group_t * g_act = lv_obj_get_group(indev_obj_act); @@ -1362,7 +1349,7 @@ static void indev_gesture(lv_indev_proc_t * proc) lv_obj_t * gesture_obj = proc->types.pointer.act_obj; /*If gesture parent is active check recursively the gesture attribute*/ - while(gesture_obj && lv_obj_get_gesture_parent(gesture_obj)) { + while(gesture_obj && lv_obj_has_flag(gesture_obj, LV_OBJ_FLAG_GESTURE_BUBBLE)) { gesture_obj = lv_obj_get_parent(gesture_obj); } diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 193d977dd..f314a9c9e 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -329,14 +329,9 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) /*Set attributes*/ new_obj->adv_hittest = 0; - new_obj->click = 1; new_obj->scroll_mode = LV_SCROLL_MODE_AUTO; - new_obj->hidden = 0; - new_obj->top = 0; - new_obj->protect = LV_PROTECT_NONE; - new_obj->parent_event = 0; - new_obj->gesture_parent = parent ? 1 : 0; - new_obj->focus_parent = 0; + new_obj->flags = LV_OBJ_FLAG_CLICKABLE; + if(parent) new_obj->flags |= LV_OBJ_FLAG_GESTURE_BUBBLE; new_obj->state = LV_STATE_DEFAULT; new_obj->scroll.x = 0; new_obj->scroll.y = 0; @@ -374,14 +369,8 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) /*Copy attributes*/ new_obj->adv_hittest = copy->adv_hittest; - new_obj->click = copy->click; + new_obj->flags = copy->flags; new_obj->scroll_mode = copy->scroll_mode; - new_obj->hidden = copy->hidden; - new_obj->top = copy->top; - new_obj->parent_event = copy->parent_event; - - new_obj->protect = copy->protect; - new_obj->gesture_parent = copy->gesture_parent; #if LV_USE_GROUP /*Add to the same group*/ @@ -533,7 +522,7 @@ void lv_obj_invalidate(const lv_obj_t * obj) */ bool lv_obj_area_is_visible(const lv_obj_t * obj, lv_area_t * area) { - if(lv_obj_get_hidden(obj)) return false; + if(lv_obj_has_flag(obj, LV_OBJ_FLAG_HIDDEN)) return false; /*Invalidate the object only if it belongs to the curent or previous'*/ lv_obj_t * obj_scr = lv_obj_get_screen(obj); @@ -562,7 +551,7 @@ bool lv_obj_area_is_visible(const lv_obj_t * obj, lv_area_t * area) while(par != NULL) { is_common = _lv_area_intersect(area, area, &par->coords); if(is_common == false) return false; /*If no common parts with parent break;*/ - if(lv_obj_get_hidden(par)) return false; /*If the parent is hidden then the child is hidden and won't be drawn*/ + if(lv_obj_has_flag(par, LV_OBJ_FLAG_HIDDEN)) return false; /*If the parent is hidden then the child is hidden and won't be drawn*/ par = lv_obj_get_parent(par); } @@ -794,12 +783,6 @@ static bool refr_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) lv_obj_t * par = lv_obj_get_parent(obj); if(par != NULL) par->signal_cb(par, LV_SIGNAL_CHILD_CHG, obj); - /*Tell the children the parent's size has changed*/ - lv_obj_t * i; - _LV_LL_READ(obj->child_ll, i) { - i->signal_cb(i, LV_SIGNAL_PARENT_SIZE_CHG, &ori); - } - /*Invalidate the new area*/ lv_obj_invalidate(obj); return true; @@ -1763,25 +1746,6 @@ void _lv_obj_disable_style_caching(lv_obj_t * obj, bool dis) * Attribute set *----------------*/ -/** - * Hide an object. It won't be visible and clickable. - * @param obj pointer to an object - * @param en true: hide the object - */ -void lv_obj_set_hidden(lv_obj_t * obj, bool en) -{ - LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - - if(!obj->hidden) lv_obj_invalidate(obj); /*Invalidate when not hidden (hidden objects are ignored) */ - - obj->hidden = en == false ? 0 : 1; - - if(!obj->hidden) lv_obj_invalidate(obj); /*Invalidate when not hidden (hidden objects are ignored) */ - - lv_obj_t * par = lv_obj_get_parent(obj); - if(par) par->signal_cb(par, LV_SIGNAL_CHILD_CHG, obj); -} - /** * Set whether advanced hit-testing is enabled on an object * @param obj pointer to an object @@ -1794,31 +1758,6 @@ void lv_obj_set_adv_hittest(lv_obj_t * obj, bool en) obj->adv_hittest = en == false ? 0 : 1; } -/** - * Enable or disable the clicking of an object - * @param obj pointer to an object - * @param en true: make the object clickable - */ -void lv_obj_set_click(lv_obj_t * obj, bool en) -{ - LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - - obj->click = (en == true ? 1 : 0); -} - -/** - * Enable to bring this object to the foreground if it - * or any of its children is clicked - * @param obj pointer to an object - * @param en true: enable the auto top feature - */ -void lv_obj_set_top(lv_obj_t * obj, bool en) -{ - LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - - obj->top = (en == true ? 1 : 0); -} - /** * Set how the scrollbars should behave. * @param obj pointer to an object @@ -1833,54 +1772,6 @@ void lv_obj_set_scroll_mode(lv_obj_t * obj, lv_scroll_mode_t mode) lv_obj_invalidate(obj); } -/** -* Enable to use parent for gesture related operations. -* If trying to gesture the object the parent will be moved instead -* @param obj pointer to an object -* @param en true: enable the 'gesture parent' for the object -*/ -void lv_obj_set_gesture_parent(lv_obj_t * obj, bool en) -{ - obj->gesture_parent = (en == true ? 1 : 0); -} - -/** -* Enable to use parent for focus state. -* When object is focused the parent will get the state instead (visual only) -* @param obj pointer to an object -* @param en true: enable the 'focus parent' for the object -*/ -void lv_obj_set_focus_parent(lv_obj_t * obj, bool en) -{ - if(lv_obj_is_focused(obj)) { - if(en) { - obj->focus_parent = 1; - lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED); - lv_obj_set_state(lv_obj_get_focused_obj(obj), LV_STATE_FOCUSED); - } - else { - lv_obj_clear_state(lv_obj_get_focused_obj(obj), LV_STATE_FOCUSED | LV_STATE_EDITED); - lv_obj_set_state(obj, LV_STATE_FOCUSED); - obj->focus_parent = 0; - } - } - else { - obj->focus_parent = (en == true ? 1 : 0); - } -} - -/** - * Propagate the events to the parent too - * @param obj pointer to an object - * @param en true: enable the event propagation - */ -void lv_obj_set_parent_event(lv_obj_t * obj, bool en) -{ - LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - - obj->parent_event = (en == true ? 1 : 0); -} - /** * Set the base direction of the object * @param obj pointer to an object @@ -1903,31 +1794,24 @@ void lv_obj_set_base_dir(lv_obj_t * obj, lv_bidi_dir_t dir) base_dir_refr_children(obj); } -/** - * Set a bit or bits in the protect filed - * @param obj pointer to an object - * @param prot 'OR'-ed values from `lv_protect_t` - */ -void lv_obj_add_protect(lv_obj_t * obj, uint8_t prot) + +void lv_obj_add_flag(lv_obj_t * obj, lv_obj_flag_t f) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - obj->protect |= prot; + obj->flags |= f; } -/** - * Clear a bit or bits in the protect filed - * @param obj pointer to an object - * @param prot 'OR'-ed values from `lv_protect_t` - */ -void lv_obj_clear_protect(lv_obj_t * obj, uint8_t prot) + + +void lv_obj_clear_flag(lv_obj_t * obj, lv_obj_flag_t f) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - prot = (~prot) & 0xFF; - obj->protect &= prot; + obj->flags &= (~f); } + /** * Set the state (fully overwrite) of an object. * If specified in the styles a transition animation will be started @@ -2001,6 +1885,7 @@ void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state) } + /** * Add a given state or states to the object. The other state bits will remain unchanged. * If specified in the styles a transition animation will be started @@ -2185,7 +2070,7 @@ lv_res_t lv_event_send_func(lv_event_cb_t event_xcb, lv_obj_t * obj, lv_event_t } if(obj) { - if(obj->parent_event && obj->parent) { + if(lv_obj_has_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE) && obj->parent) { lv_res_t res = lv_event_send(obj->parent, event, data); if(res != LV_RES_OK) { return LV_RES_INV; @@ -3124,16 +3009,11 @@ lv_style_t * lv_obj_get_local_style(lv_obj_t * obj, uint8_t part) * Attribute get *----------------*/ -/** - * Get the hidden attribute of an object - * @param obj pointer to an object - * @return true: the object is hidden - */ -bool lv_obj_get_hidden(const lv_obj_t * obj) +bool lv_obj_has_flag(lv_obj_t * obj, lv_obj_flag_t f) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - return obj->hidden == 0 ? false : true; + return obj->flags & f ? true : false; } /** @@ -3148,29 +3028,6 @@ bool lv_obj_get_adv_hittest(const lv_obj_t * obj) return obj->adv_hittest == 0 ? false : true; } -/** - * Get the click enable attribute of an object - * @param obj pointer to an object - * @return true: the object is clickable - */ -bool lv_obj_get_click(const lv_obj_t * obj) -{ - LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - - return obj->click == 0 ? false : true; -} - -/** - * Get the top enable attribute of an object - * @param obj pointer to an object - * @return true: the auto top feature is enabled - */ -bool lv_obj_get_top(const lv_obj_t * obj) -{ - LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - - return obj->top == 0 ? false : true; -} /** * Get how the scrollbars should behave. @@ -3184,39 +3041,6 @@ lv_scroll_mode_t lv_obj_get_scroll_mode(lv_obj_t * obj) return obj->scroll_mode; } -/** -* Get the gesture parent attribute of an object -* @param obj pointer to an object -* @return true: gesture parent is enabled -*/ -bool lv_obj_get_gesture_parent(const lv_obj_t * obj) -{ - return obj->gesture_parent == 0 ? false : true; -} - -/** -* Get the focus parent attribute of an object -* @param obj pointer to an object -* @return true: focus parent is enabled -*/ -bool lv_obj_get_focus_parent(const lv_obj_t * obj) -{ - return obj->focus_parent == 0 ? false : true; -} - -/** - * Get the parent event attribute of an object - * @param obj pointer to an object - * @return true: parent event is enabled - */ -bool lv_obj_get_parent_event(const lv_obj_t * obj) -{ - LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - - return obj->parent_event == 0 ? false : true; -} - - lv_bidi_dir_t lv_obj_get_base_dir(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); @@ -3237,31 +3061,6 @@ lv_bidi_dir_t lv_obj_get_base_dir(const lv_obj_t * obj) #endif } -/** - * Get the protect field of an object - * @param obj pointer to an object - * @return protect field ('OR'ed values of `lv_protect_t`) - */ -uint8_t lv_obj_get_protect(const lv_obj_t * obj) -{ - LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - - 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_protect_t`) - * @return false: none of the given bits are set, true: at least one bit is set - */ -bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot) -{ - LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - - return (obj->protect & prot) == 0 ? false : true; -} - lv_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); @@ -4159,7 +3958,7 @@ lv_obj_t * lv_obj_get_focused_obj(const lv_obj_t * obj) { if(obj == NULL) return NULL; const lv_obj_t * focus_obj = obj; - while(lv_obj_get_focus_parent(focus_obj) != false && focus_obj != NULL) { + while(lv_obj_has_flag(focus_obj, LV_OBJ_FLAG_FOCUS_BUBBLE) != false && focus_obj != NULL) { focus_obj = lv_obj_get_parent(focus_obj); } @@ -4193,9 +3992,6 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) } } else if(sign == LV_SIGNAL_CHILD_CHG) { - /*Return 'invalid' if the child change signal is not enabled*/ - if(lv_obj_is_protected(obj, LV_PROTECT_CHILD_CHG) != false) res = LV_RES_INV; - if(obj->w_set == LV_SIZE_AUTO || obj->h_set == LV_SIZE_AUTO) { lv_obj_set_size(obj, obj->w_set, obj->h_set); } @@ -4208,11 +4004,6 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) lv_grid_full_refr(obj); } } - -// else if(lv_obj_is_content_sensitive(obj)) { -// lv_grid_full_refr(lv_obj_get_parent(obj)); -// } - } else if(sign == LV_SIGNAL_SCROLL) { @@ -4252,11 +4043,13 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) obj->ext_draw_pad = LV_MATH_MAX(obj->ext_draw_pad, d); } else if(sign == LV_SIGNAL_STYLE_CHG) { - lv_obj_t * child = lv_obj_get_child(obj, NULL); - while(child) { - lv_obj_set_pos(child, child->x_set, child->y_set); - child = lv_obj_get_child(obj, child); - } + if(lv_obj_is_grid_item(obj)) lv_grid_full_refr(obj); + +// lv_obj_t * child = lv_obj_get_child(obj, NULL); +// while(child) { +// lv_obj_set_pos(child, child->x_set, child->y_set); +// child = lv_obj_get_child(obj, child); +// } if(obj->w_set == LV_SIZE_AUTO || obj->h_set == LV_SIZE_AUTO) { diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index cbfd9aef3..0ad5e0593 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -126,7 +126,6 @@ enum { LV_SIGNAL_CLEANUP, /**< Object is being deleted */ LV_SIGNAL_CHILD_CHG, /**< Child was removed/added */ LV_SIGNAL_COORD_CHG, /**< Object coordinates/size have changed */ - LV_SIGNAL_PARENT_SIZE_CHG, /**< Parent's size has changed */ LV_SIGNAL_STYLE_CHG, /**< Object's style has changed */ LV_SIGNAL_BASE_DIR_CHG, /**