From 49b136191fa43f15a5bab46f212cd26cf5b1e48f Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 12 Dec 2018 11:30:17 +0800 Subject: [PATCH 1/4] Update lv_btnm.c Attempt to fix an LV_BORDER_RIGHT drawing issue. --- lv_objx/lv_btnm.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index 73a96e39d..ac47b9c8c 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -437,7 +437,6 @@ static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mo lv_area_t area_tmp; lv_coord_t btn_w; lv_coord_t btn_h; - bool border_mod = false; uint16_t btn_i = 0; uint16_t txt_i = 0; @@ -465,21 +464,8 @@ static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mo else if(btn_i == ext->btn_id_pr && btn_i == ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_TGL_PR); else btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_REL); /*Not possible option, just to be sure*/ - /*On the right buttons clear the border if only right borders are drawn*/ - if(ext->map_p[txt_i + 1][0] == '\0' || ext->map_p[txt_i + 1][0] == '\n') { - if(btn_style->body.border.part == LV_BORDER_RIGHT) { - btn_style->body.border.part = LV_BORDER_NONE; - border_mod = true; - } - } - lv_draw_rect(&area_tmp, mask, btn_style, opa_scale); - if(border_mod) { - border_mod = false; - btn_style->body.border.part = LV_BORDER_RIGHT; - } - /*Calculate the size of the text*/ if(btn_style->glass) btn_style = bg_style; const lv_font_t * font = btn_style->text.font; @@ -493,7 +479,6 @@ static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mo area_tmp.x2 = area_tmp.x1 + txt_size.x; area_tmp.y2 = area_tmp.y1 + txt_size.y; - lv_draw_label(&area_tmp, mask, btn_style, opa_scale, ext->map_p[txt_i], LV_TXT_FLAG_NONE, NULL); } } From 9817e050e088ba96ac15722bcedf57ed4131a0ac Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 14 Dec 2018 13:05:00 -0800 Subject: [PATCH 2/4] Add wrap enable/disable for lv_group Allows for controlling whether focus next/prev will wrap at the boundaries, or if they will stop at the boundaries. --- lv_core/lv_group.c | 31 +++++++++++++++++++++++++++++-- lv_core/lv_group.h | 14 ++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index 4a87067e8..17190f428 100644 --- a/lv_core/lv_group.c +++ b/lv_core/lv_group.c @@ -204,7 +204,10 @@ void lv_group_focus_next(lv_group_t * group) if(group->obj_focus == NULL) obj_next = lv_ll_get_head(&group->obj_ll); else obj_next = lv_ll_get_next(&group->obj_ll, group->obj_focus); - if(obj_next == NULL) obj_next = lv_ll_get_head(&group->obj_ll); + if(obj_next == NULL) { + if(group->wrap) obj_next = lv_ll_get_head(&group->obj_ll); + else obj_next = lv_ll_get_tail(&group->obj_ll); + } group->obj_focus = obj_next; if(group->obj_focus) { @@ -232,7 +235,10 @@ void lv_group_focus_prev(lv_group_t * group) if(group->obj_focus == NULL) obj_next = lv_ll_get_tail(&group->obj_ll); else obj_next = lv_ll_get_prev(&group->obj_ll, group->obj_focus); - if(obj_next == NULL) obj_next = lv_ll_get_tail(&group->obj_ll); + if(obj_next == NULL) { + if(group->wrap) obj_next = lv_ll_get_tail(&group->obj_ll); + else obj_next = lv_ll_get_head(&group->obj_ll); + } group->obj_focus = obj_next; if(group->obj_focus != NULL) { @@ -340,6 +346,16 @@ static void lv_group_refocus(lv_group_t *g) { lv_group_focus_prev(g); } +/** + * Set whether focus next/prev will allow wrapping from first->last or last->first. + * @param group pointer to group + * @param en: true: enable `click_focus` + */ +void lv_group_set_wrap(lv_group_t * group, bool en) +{ + group->wrap = en ? 1 : 0; +} + /** * Modify a style with the set 'style_mod' function. The input style remains unchanged. * @param group pointer to group @@ -428,6 +444,17 @@ bool lv_group_get_click_focus(const lv_group_t * group) return group->click_focus ? true : false; } +/** + * Get whether focus next/prev will allow wrapping from first->last or last->first object. + * @param group pointer to group + * @param en: true: wrapping enabled; false: wrapping disabled + */ +bool lv_group_get_wrap(lv_group_t * group) +{ + if(!group) return false; + return group->wrap ? true : false; +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/lv_core/lv_group.h b/lv_core/lv_group.h index 17f9edb93..c7e3ad531 100644 --- a/lv_core/lv_group.h +++ b/lv_core/lv_group.h @@ -58,6 +58,7 @@ typedef struct _lv_group_t uint8_t editing :1; /*1: Edit mode, 0: Navigate mode*/ uint8_t click_focus :1; /*1: If an object in a group is clicked by an indev then it will be focused */ uint8_t refocus_policy :1; /*1: Focus prev if focused on deletion. 0: Focus prev if focused on deletion.*/ + uint8_t wrap :1; /*1: Focus next/prev can wrap at end of list. 0: Focus next/prev stops at end of list.*/ } lv_group_t; typedef enum _lv_group_refocus_policy_t { @@ -168,6 +169,13 @@ void lv_group_set_editing(lv_group_t * group, bool edit); */ void lv_group_set_click_focus(lv_group_t * group, bool en); +/** + * Set whether focus next/prev will allow wrapping from first->last or last->first object. + * @param group pointer to group + * @param en: true: wrapping enabled; false: wrapping disabled + */ +void lv_group_set_wrap(lv_group_t * group, bool en); + /** * Modify a style with the set 'style_mod' function. The input style remains unchanged. * @param group pointer to group @@ -218,6 +226,12 @@ bool lv_group_get_editing(const lv_group_t * group); */ bool lv_group_get_click_focus(const lv_group_t * group); +/** + * Get whether focus next/prev will allow wrapping from first->last or last->first object. + * @param group pointer to group + * @param en: true: wrapping enabled; false: wrapping disabled + */ +bool lv_group_get_wrap(lv_group_t * group); /********************** * MACROS From 47bdf497b6a6eac52a143ca7f1665217f19dbc4f Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 14 Dec 2018 14:24:47 -0800 Subject: [PATCH 3/4] Fix lv_group wrap behavior when removing head or tail object from group --- lv_core/lv_group.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index 17190f428..e1d216a75 100644 --- a/lv_core/lv_group.c +++ b/lv_core/lv_group.c @@ -340,10 +340,15 @@ void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t p } static void lv_group_refocus(lv_group_t *g) { - if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_NEXT) - lv_group_focus_next(g); - else if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_PREV) - lv_group_focus_prev(g); + /*Refocus must temporarily allow wrapping to work correctly*/ + uint8_t temp_wrap = g->wrap; + + if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_NEXT) + lv_group_focus_next(g); + else if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_PREV) + lv_group_focus_prev(g); + /*Restore wrap property*/ + g->wrap = temp_wrap; } /** From 92747ec37a19d73402c050e6e4b514254a97e764 Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 14 Dec 2018 16:02:29 -0800 Subject: [PATCH 4/4] Fix missing temporary setting of wrap to 1 --- lv_core/lv_group.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index e1d216a75..9c1ed4b54 100644 --- a/lv_core/lv_group.c +++ b/lv_core/lv_group.c @@ -342,6 +342,7 @@ void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t p static void lv_group_refocus(lv_group_t *g) { /*Refocus must temporarily allow wrapping to work correctly*/ uint8_t temp_wrap = g->wrap; + g->wrap = 1; if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_NEXT) lv_group_focus_next(g);