From f4c0055c5ab69546bf1efd3c8054524787cb4935 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 3 May 2019 19:25:58 +0200 Subject: [PATCH] add lv_obj_move_foreground/background --- src/lv_core/lv_disp.c | 2 +- src/lv_core/lv_group.c | 3 +-- src/lv_core/lv_indev.c | 5 +---- src/lv_core/lv_obj.c | 45 ++++++++++++++++++++++++++++++++----- src/lv_core/lv_obj.h | 12 ++++++++++ src/lv_draw/lv_draw_basic.c | 3 +-- src/lv_misc/lv_ll.c | 37 +++++++++++++++++++++--------- src/lv_misc/lv_ll.h | 4 +++- 8 files changed, 86 insertions(+), 25 deletions(-) diff --git a/src/lv_core/lv_disp.c b/src/lv_core/lv_disp.c index a59debbcf..cf2f49d51 100644 --- a/src/lv_core/lv_disp.c +++ b/src/lv_core/lv_disp.c @@ -112,7 +112,7 @@ void lv_disp_assign_screen(lv_disp_t * disp, lv_obj_t * scr) if(old_disp == disp) return; - lv_ll_chg_list(&old_disp->scr_ll, &disp->scr_ll, scr); + lv_ll_chg_list(&old_disp->scr_ll, &disp->scr_ll, scr, true); } /** diff --git a/src/lv_core/lv_group.c b/src/lv_core/lv_group.c index e054657f1..8a2328985 100644 --- a/src/lv_core/lv_group.c +++ b/src/lv_core/lv_group.c @@ -671,8 +671,7 @@ static void obj_to_foreground(lv_obj_t * obj) /*Move the last_top object to the foreground*/ lv_obj_t * par = lv_obj_get_parent(last_top); /*After list change it will be the new head*/ - lv_ll_chg_list(&par->child_ll, &par->child_ll, last_top); - lv_obj_invalidate(last_top); + lv_obj_move_foreground(last_top); } } diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index 8727ca8a1..8ee40a230 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -738,10 +738,7 @@ static void indev_proc_press(lv_indev_proc_t * proc) if(last_top != NULL) { /*Move the last_top object to the foreground*/ - lv_obj_t * par = lv_obj_get_parent(last_top); - /*After list change it will be the new head*/ - lv_ll_chg_list(&par->child_ll, &par->child_ll, last_top); - lv_obj_invalidate(last_top); + lv_obj_move_foreground(last_top); } /*Send a signal about the press*/ diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 45361d92d..3114c5211 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -214,7 +214,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) else { LV_LOG_TRACE("Object create started"); - new_obj = lv_ll_ins_head(&(parent)->child_ll); + new_obj = lv_ll_ins_head(&parent->child_ll); lv_mem_assert(new_obj); if(new_obj == NULL) return NULL; @@ -428,8 +428,7 @@ lv_res_t lv_obj_del(lv_obj_t * obj) lv_ll_rem(&(par->child_ll), obj); } - /* Reset all input devices if - * the object to delete is used*/ + /* Reset all input devices if the object to delete is used*/ lv_indev_t * indev = lv_indev_get_next(NULL); while(indev) { if(indev->proc.types.pointer.act_obj == obj || indev->proc.types.pointer.last_obj == obj) { @@ -552,7 +551,7 @@ void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent) lv_obj_t * old_par = obj->par; - lv_ll_chg_list(&obj->par->child_ll, &parent->child_ll, obj); + lv_ll_chg_list(&obj->par->child_ll, &parent->child_ll, obj, true); obj->par = parent; lv_obj_set_pos(obj, old_pos.x, old_pos.y); @@ -565,6 +564,42 @@ void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent) lv_obj_invalidate(obj); } +/** + * Move and object to the foreground + * @param obj pointer to an object + */ +void lv_obj_move_foreground(lv_obj_t * obj) +{ + lv_obj_t * parent = lv_obj_get_parent(obj); + + lv_obj_invalidate(parent); + + lv_ll_chg_list(&parent->child_ll, &parent->child_ll, obj, true); + + /*Notify the new parent about the child*/ + parent->signal_cb(parent, LV_SIGNAL_CHILD_CHG, obj); + + lv_obj_invalidate(parent); +} + +/** + * Move and object to the background + * @param obj pointer to an object + */ +void lv_obj_move_background(lv_obj_t * obj) +{ + lv_obj_t * parent = lv_obj_get_parent(obj); + + lv_obj_invalidate(parent); + + lv_ll_chg_list(&parent->child_ll, &parent->child_ll, obj, false); + + /*Notify the new parent about the child*/ + parent->signal_cb(parent, LV_SIGNAL_CHILD_CHG, obj); + + lv_obj_invalidate(parent); +} + /*-------------------- * Coordinate set * ------------------*/ @@ -2017,7 +2052,7 @@ void * lv_obj_get_group(const lv_obj_t * obj) } /** - * Tell whether the ohe object is the focused object of a group or not. + * Tell whether the object is the focused object of a group or not. * @param obj pointer to an object * @return true: the object is focused, false: the object is not focused or not in a group */ diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 2280a1c64..435c86a93 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -328,6 +328,18 @@ void lv_obj_invalidate(const lv_obj_t * obj); */ void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent); +/** + * Move and object to the foreground + * @param obj pointer to an object + */ +void lv_obj_move_foreground(lv_obj_t * obj); + +/** + * Move and object to the background + * @param obj pointer to an object + */ +void lv_obj_move_background(lv_obj_t * obj); + /*-------------------- * Coordinate set * ------------------*/ diff --git a/src/lv_draw/lv_draw_basic.c b/src/lv_draw/lv_draw_basic.c index c0e93b28e..e3ce5f365 100644 --- a/src/lv_draw/lv_draw_basic.c +++ b/src/lv_draw/lv_draw_basic.c @@ -336,8 +336,7 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, const lv (row + pos_y) - vdb->area.y1, color, px_opa); } else { if(px_opa > LV_OPA_MAX) *vdb_buf_tmp = color; - else if(px_opa < LV_OPA_MIN) continue; - else { + else if(px_opa > LV_OPA_MIN) { #if LV_COLOR_SCREEN_TRANSP == 0 *vdb_buf_tmp = lv_color_mix(color, *vdb_buf_tmp, px_opa); #else diff --git a/src/lv_misc/lv_ll.c b/src/lv_misc/lv_ll.c index dd5432b94..755a76ccb 100644 --- a/src/lv_misc/lv_ll.c +++ b/src/lv_misc/lv_ll.c @@ -214,22 +214,39 @@ void lv_ll_clear(lv_ll_t * ll_p) * @param ll_ori_p pointer to the original (old) linked list * @param ll_new_p pointer to the new linked list * @param node pointer to a node + * @param head true: be the head in the new list + * false be the head in the new list */ -void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node) +void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node, bool head) { lv_ll_rem(ll_ori_p, node); - /*Set node as head*/ - node_set_prev(ll_new_p, node, NULL); - node_set_next(ll_new_p, node, ll_new_p->head); + if(head) { + /*Set node as head*/ + node_set_prev(ll_new_p, node, NULL); + node_set_next(ll_new_p, node, ll_new_p->head); - if(ll_new_p->head != NULL) { /*If there is old head then before it goes the new*/ - node_set_prev(ll_new_p, ll_new_p->head, node); - } + if(ll_new_p->head != NULL) { /*If there is old head then before it goes the new*/ + node_set_prev(ll_new_p, ll_new_p->head, node); + } - ll_new_p->head = node; /*Set the new head in the dsc.*/ - if(ll_new_p->tail == NULL) { /*If there is no tail (first node) set the tail too*/ - ll_new_p->tail = node; + ll_new_p->head = node; /*Set the new head in the dsc.*/ + if(ll_new_p->tail == NULL) { /*If there is no tail (first node) set the tail too*/ + ll_new_p->tail = node; + } + } else { + /*Set node as tail*/ + node_set_prev(ll_new_p, node, ll_new_p->tail); + node_set_next(ll_new_p, node, NULL); + + if(ll_new_p->tail != NULL) { /*If there is old tail then after it goes the new*/ + node_set_next(ll_new_p, ll_new_p->tail, node); + } + + ll_new_p->tail = node; /*Set the new tail in the dsc.*/ + if(ll_new_p->head == NULL) { /*If there is no head (first node) set the head too*/ + ll_new_p->head = node; + } } } diff --git a/src/lv_misc/lv_ll.h b/src/lv_misc/lv_ll.h index bad5383ac..d289269ac 100644 --- a/src/lv_misc/lv_ll.h +++ b/src/lv_misc/lv_ll.h @@ -89,8 +89,10 @@ void lv_ll_clear(lv_ll_t * ll_p); * @param ll_ori_p pointer to the original (old) linked list * @param ll_new_p pointer to the new linked list * @param node pointer to a node + * @param head true: be the head in the new list + * false be the head in the new list */ -void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node); +void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node, bool head); /** * Return with head node of the linked list