From 8dba219f4280e9ef9ecd1a8d06d8e2bd3dca1e65 Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Thu, 20 Jul 2017 01:09:20 +0200 Subject: [PATCH] lv_group: object types are activated correctly (ddlist open/close, label background, page scrl activate) --- lv_obj/lv_group.c | 28 ++++++++++++++-- lv_obj/lv_group.h | 2 ++ lv_obj/lv_obj.c | 27 +++++++++------ lv_obj/lv_obj.h | 10 ++++++ lv_objx/lv_ddlist.c | 16 ++++++++- lv_objx/lv_label.c | 20 +++++++---- lv_objx/lv_label.h | 2 +- lv_objx/lv_list.c | 6 +++- lv_objx/lv_page.c | 81 ++++++++++++++++++++++++++++++++++++--------- 9 files changed, 154 insertions(+), 38 deletions(-) diff --git a/lv_obj/lv_group.c b/lv_obj/lv_group.c index c4ebeb8d0..0c08952cf 100644 --- a/lv_obj/lv_group.c +++ b/lv_obj/lv_group.c @@ -64,7 +64,10 @@ void lv_group_set_style_cb(lv_group_t * group, void (*style_cb)(lv_style_t * sty void lv_group_activate_next(lv_group_t * group) { - if(group->actve_obj != NULL) lv_obj_inv(*group->actve_obj); + if(group->actve_obj != NULL) { + (*group->actve_obj)->signal_f(*group->actve_obj, LV_SIGNAL_DEACTIVATE, NULL); + lv_obj_inv(*group->actve_obj); + } lv_obj_t ** obj_next; if(group->actve_obj == NULL) obj_next = ll_get_head(&group->obj_ll); @@ -73,7 +76,10 @@ void lv_group_activate_next(lv_group_t * group) if(obj_next == NULL) obj_next = ll_get_head(&group->obj_ll); group->actve_obj = obj_next; - if(group->actve_obj != NULL) lv_obj_inv(*group->actve_obj); + if(group->actve_obj != NULL){ + (*group->actve_obj)->signal_f(*group->actve_obj, LV_SIGNAL_ACTIVATE, NULL); + lv_obj_inv(*group->actve_obj); + } } void lv_group_activate_prev(lv_group_t * group) @@ -91,6 +97,24 @@ void lv_group_activate_prev(lv_group_t * group) } +lv_style_t * lv_group_activate_style(lv_group_t * group, lv_style_t * style) +{ + lv_style_cpy(&group->style_tmp, style); + + if(group->style_activate != NULL) group->style_activate(&group->style_tmp); + else style_activate_def(&group->style_tmp); + + return &group->style_tmp; +} + +lv_obj_t * lv_group_get_active(lv_group_t * group) +{ + if(group == NULL) return NULL; + if(group->actve_obj == NULL) return NULL; + + return *group->actve_obj; +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/lv_obj/lv_group.h b/lv_obj/lv_group.h index c1c7e3bb3..de4acc5ac 100644 --- a/lv_obj/lv_group.h +++ b/lv_obj/lv_group.h @@ -38,6 +38,8 @@ void lv_group_add(lv_group_t * group, lv_obj_t * obj); void lv_group_activate_obj(lv_group_t * group, lv_obj_t * obj); void lv_group_activate_next(lv_group_t * group); void lv_group_activate_prev(lv_group_t * group); +lv_style_t * lv_group_activate_style(lv_group_t * group, lv_style_t * style); +lv_obj_t * lv_group_get_active(lv_group_t * group); /********************** * MACROS diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index aa75c043a..b83465a08 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -1249,20 +1249,13 @@ lv_style_t * lv_obj_get_style(lv_obj_t * obj) par = par->par; } } - +#if LV_OBJ_GROUP != 0 if(obj->group_p != NULL) { - lv_obj_t * active_obj = NULL; - if(((lv_group_t *)obj->group_p)->actve_obj != NULL) { - active_obj = *((lv_group_t *)obj->group_p)->actve_obj; - } - - if(active_obj == obj) { - lv_style_cpy(&((lv_group_t *)obj->group_p)->style_tmp, style_act); - ((lv_group_t *)obj->group_p)->style_activate(&((lv_group_t *)obj->group_p)->style_tmp); - style_act = &((lv_group_t *)obj->group_p)->style_tmp; + if(lv_group_get_active(obj->group_p) == obj) { + style_act = lv_group_activate_style(obj->group_p, style_act); } } - +#endif return style_act; } @@ -1411,6 +1404,18 @@ void * lv_obj_get_free_p(lv_obj_t * obj) } #endif +#if LV_OBJ_GROUP != 0 +/** + * Get the group of the object + * @param obj pointer to an object + * @return the pointer to group of the object + */ +void * lv_obj_get_group(lv_obj_t * obj) +{ + return obj->group_p; +} +#endif + /********************** * STATIC FUNCTIONS **********************/ diff --git a/lv_obj/lv_obj.h b/lv_obj/lv_obj.h index 2004eae21..3212e263c 100644 --- a/lv_obj/lv_obj.h +++ b/lv_obj/lv_obj.h @@ -85,6 +85,8 @@ typedef enum LV_SIGNAL_CORD_CHG, LV_SIGNAL_STYLE_CHG, LV_SIGNAL_REFR_EXT_SIZE, + LV_SIGNAL_ACTIVATE, + LV_SIGNAL_DEACTIVATE, }lv_signal_t; typedef bool (* lv_signal_f_t) (struct __LV_OBJ_T * obj, lv_signal_t sign, void * param); @@ -661,6 +663,14 @@ uint8_t lv_obj_get_free_num(lv_obj_t * obj); void * lv_obj_get_free_p(lv_obj_t * obj); #endif +#if LV_OBJ_GROUP != 0 +/** + * Get the group of the object + * @param obj pointer to an object + * @return the pointer to group of the object + */ +void * lv_obj_get_group(lv_obj_t * obj); +#endif /********************** * MACROS **********************/ diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index 547c31dcd..04ae885e8 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -130,6 +130,20 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param) lv_obj_set_style(ext->opt_label, lv_obj_get_style(ddlist)); lv_ddlist_refr_size(ddlist, 0); } + else if(sign == LV_SIGNAL_ACTIVATE) { + lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); + if(ext->opened == false) { + ext->opened = true; + lv_ddlist_refr_size(ddlist, true); + } + } + else if(sign == LV_SIGNAL_DEACTIVATE) { + lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); + if(ext->opened != false) { + ext->opened = false; + lv_ddlist_refr_size(ddlist, true); + } + } } return valid; @@ -417,7 +431,7 @@ static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist, lv_dispi_t * disp } /** - * Refresh the size of drop down list according its start (open or closed) + * Refresh the size of drop down list according its status (open or closed) * @param ddlist pointer to a drop down list object * @param anim_time animations time for open/close [ms] */ diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 27b046cbd..87e9b936e 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -13,6 +13,7 @@ #include "misc/math/math_base.h" #include "lv_label.h" #include "../lv_obj/lv_obj.h" +#include "../lv_obj/lv_group.h" #include "misc/gfx/text.h" #include "misc/gfx/anim.h" #include "../lv_draw/lv_draw.h" @@ -468,11 +469,9 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos) } x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space; - if(pos->x < x) break; } - return i; } @@ -496,11 +495,20 @@ static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mod /* A label never covers an area */ if(mode == LV_DESIGN_COVER_CHK) return false; else if(mode == LV_DESIGN_DRAW_MAIN) { - /*TEST: draw a background for the label*/ + area_t cords; + lv_style_t * style = lv_obj_get_style(label); + lv_obj_get_cords(label, &cords); + +#if LV_OBJ_GROUP != 0 + lv_group_t * g = lv_obj_get_group(label); + if(lv_group_get_active(g) == label) { + lv_draw_rect(&cords, mask, style); + } +#endif + + /*TEST: draw a background for the label*/ //lv_vfill(&label->cords, mask, COLOR_LIME, OPA_COVER); - area_t cords; - lv_obj_get_cords(label, &cords); lv_label_ext_t * ext = lv_obj_get_ext(label); txt_flag_t flag = TXT_FLAG_NONE; if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR; @@ -512,7 +520,7 @@ static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mod i++; } - lv_draw_label(&cords, mask, lv_obj_get_style(label), ext->txt, flag, &ext->offset); + lv_draw_label(&cords, mask, style, ext->txt, flag, &ext->offset); } diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index a673d34d7..7ae46f895 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -48,7 +48,7 @@ typedef struct lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/ char dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/ uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/ - point_t offset; + point_t offset; /*Text draw position offset*/ uint8_t static_txt :1; /*Flag to indicate the text is static*/ uint8_t recolor :1; /*Enable in-line letter re-coloring*/ uint8_t expand :1; /*Force expand size when solving line length (used by the library with LV_LABEL_LONG_ROLL)*/ diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index feab2526e..afc253ae0 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -108,6 +108,11 @@ bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) /* Include the ancient signal function */ valid = lv_page_signal(list, sign, param); + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + + } return valid; } @@ -211,7 +216,6 @@ void lv_list_down(lv_obj_t * list) } } - /*===================== * Setter functions *====================*/ diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 2f47fce28..e13aada40 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -10,6 +10,7 @@ #if USE_LV_PAGE != 0 #include "misc/math/math_base.h" +#include "../lv_obj/lv_group.h" #include "../lv_objx/lv_page.h" #include "../lv_objx/lv_cont.h" #include "../lv_draw/lv_draw.h" @@ -28,13 +29,15 @@ * STATIC PROTOTYPES **********************/ static void lv_page_sb_refresh(lv_obj_t * main); -static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_t mode); +static bool lv_page_design(lv_obj_t * scrl, const area_t * mask, lv_design_mode_t mode); +static bool lv_scrl_design(lv_obj_t * scrl, const area_t * mask, lv_design_mode_t mode); static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param); /********************** * STATIC VARIABLES **********************/ -static lv_design_f_t ancestor_design_f; +static lv_design_f_t ancestor_page_design_f; +static lv_design_f_t ancestor_scrl_design_f; /********************** * MACROS @@ -72,18 +75,20 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy) ext->sb_width = LV_DPI / 8; /*Will be modified later*/ ext->sb_mode = LV_PAGE_SB_MODE_ON; - if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_page); + if(ancestor_page_design_f == NULL) ancestor_page_design_f = lv_obj_get_design_f(new_page); /*Init the new page object*/ if(copy == NULL) { lv_style_t * style = lv_style_get(LV_STYLE_PRETTY_COLOR, NULL); ext->scrl = lv_cont_create(new_page, NULL); + if(ancestor_scrl_design_f == NULL) ancestor_scrl_design_f = lv_obj_get_design_f(ext->scrl); 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_PROTECT_PARENT); lv_cont_set_fit(ext->scrl, true, true); lv_obj_set_style(ext->scrl, lv_style_get(LV_STYLE_PRETTY, NULL)); + lv_obj_set_design_f(ext->scrl, lv_scrl_design); lv_page_set_sb_width(new_page, style->hpad); lv_page_set_sb_mode(new_page, ext->sb_mode); @@ -534,41 +539,85 @@ lv_style_t * lv_page_get_style_sb(lv_obj_t * page) * LV_DESIGN_DRAW_POST: drawing after every children are drawn * @param return true/false, depends on 'mode' */ -static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_t mode) +static bool lv_page_design(lv_obj_t * scrl, const area_t * mask, lv_design_mode_t mode) { if(mode == LV_DESIGN_COVER_CHK) { - return ancestor_design_f(page, mask, mode); + return ancestor_page_design_f(scrl, mask, mode); } else if(mode == LV_DESIGN_DRAW_MAIN) { - ancestor_design_f(page, mask, mode); + ancestor_page_design_f(scrl, mask, mode); } else if(mode == LV_DESIGN_DRAW_POST) { /*Draw the scroll bars finally*/ - ancestor_design_f(page, mask, mode); - lv_page_ext_t * ext = lv_obj_get_ext(page); + ancestor_page_design_f(scrl, mask, mode); + lv_page_ext_t * ext = lv_obj_get_ext(scrl); /*Draw the scrollbars*/ area_t sb_area; if(ext->sbh_draw != 0) { /*Convert the relative coordinates to absolute*/ area_cpy(&sb_area, &ext->sbh); - sb_area.x1 += page->cords.x1; - sb_area.y1 += page->cords.y1; - sb_area.x2 += page->cords.x1; - sb_area.y2 += page->cords.y1; + sb_area.x1 += scrl->cords.x1; + sb_area.y1 += scrl->cords.y1; + sb_area.x2 += scrl->cords.x1; + sb_area.y2 += scrl->cords.y1; lv_draw_rect(&sb_area, mask, ext->style_sb); } if(ext->sbv_draw != 0) { /*Convert the relative coordinates to absolute*/ area_cpy(&sb_area, &ext->sbv); - sb_area.x1 += page->cords.x1; - sb_area.y1 += page->cords.y1; - sb_area.x2 += page->cords.x1; - sb_area.y2 += page->cords.y1; + sb_area.x1 += scrl->cords.x1; + sb_area.y1 += scrl->cords.y1; + sb_area.x2 += scrl->cords.x1; + sb_area.y2 += scrl->cords.y1; lv_draw_rect(&sb_area, mask, ext->style_sb); } } return true; } +/** + * Handle the drawing related tasks of the scrollable object + * @param scrl pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_scrl_design(lv_obj_t * scrl, const area_t * mask, lv_design_mode_t mode) +{ + if(mode == LV_DESIGN_COVER_CHK) { + return ancestor_page_design_f(scrl, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN) { +#if LV_OBJ_GROUP != 0 + /* If the page is the active in a group and + * the background (page) is not visible (transparent or empty) + * then activate the style of the scrollable*/ + lv_style_t * style_ori = lv_obj_get_style(scrl); + lv_obj_t * page = lv_obj_get_parent(scrl); + lv_style_t * style_page = lv_obj_get_style(page); + lv_group_t * g = lv_obj_get_group(page); + if(style_page->empty != 0 || style_page->opa == OPA_TRANSP) { /*Background is visible?*/ + if(lv_group_get_active(g) == page) { + lv_style_t * style_mod; + style_mod = lv_group_activate_style(g, style_ori); + scrl->style_p = style_mod; /*Temporally change the style to the activated */ + } + } +#endif + ancestor_page_design_f(scrl, mask, mode); + +#if LV_OBJ_GROUP != 0 + scrl->style_p = style_ori; /*Revert the style*/ +#endif + } else if(mode == LV_DESIGN_DRAW_POST) { + ancestor_page_design_f(scrl, mask, mode); + } + + return true; +} + + /** * Refresh the position and size of the scroll bars.