From 5608bf868e8b15a778642a080d7ddd269ded505b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 30 Oct 2017 17:11:56 +0100 Subject: [PATCH] bugfixes --- lv_draw/lv_draw.c | 11 ++++--- lv_obj/lv_obj.c | 3 +- lv_obj/lv_style.c | 23 +++++++++------ lv_obj/lv_style.h | 6 ++-- lv_objx/lv_btnm.c | 3 ++ lv_objx/lv_kb.c | 40 +++++++++++--------------- lv_objx/lv_kb.h | 2 +- lv_objx/lv_label.c | 68 +++++++++++++++++++++++++++++++++----------- lv_objx/lv_label.h | 24 ++++++++++++++-- lv_objx/lv_list.c | 2 +- lv_objx/lv_page.c | 4 +-- lv_objx/lv_ta.c | 8 +++--- lv_objx/lv_tabview.c | 63 +++++++++++++++++++++++++++++----------- lv_objx/lv_tabview.h | 1 + 14 files changed, 174 insertions(+), 84 deletions(-) diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index 1c68dd6b7..3fc8515c7 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -258,7 +258,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_ pos.y = cords_p->y1; /*Align the line to middle if enabled*/ - if(style->text.align == LV_TXT_ALIGN_MID) { + if(style->text.align == LV_TEXT_ALIGN_MID) { line_length = txt_get_width(&txt[line_start], line_end - line_start, font, style->text.space_letter, flag); pos.x += (w - line_length) / 2; @@ -284,6 +284,9 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_ uint32_t letter; while(i < line_end) { letter = txt_utf8_next(txt, &i); + if(letter == ':') { + letter = ':'; + } /*Handle the re-color command*/ if((flag & TXT_FLAG_RECOLOR) != 0) { if(letter == TXT_RECOLOR_CMD) { @@ -333,7 +336,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_ pos.x = cords_p->x1; /*Align to middle*/ - if(style->text.align == LV_TXT_ALIGN_MID) { + if(style->text.align == LV_TEXT_ALIGN_MID) { line_length = txt_get_width(&txt[line_start], line_end - line_start, font, style->text.space_letter, flag); pos.x += (w - line_length) / 2; @@ -400,7 +403,7 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p, #endif /*Read the img. with the FS interface*/ - if(const_data != false) { + if(const_data == false) { uint8_t us_shift = 0; uint8_t us_val = 1; if(upscale != false) { @@ -816,7 +819,7 @@ static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * cord_t width = area_get_width(cords_p); cord_t height = area_get_height(cords_p); uint16_t bwidth = style_p->body.border.width; - opa_t bopa = (uint16_t)((uint16_t) style_p->opa * style_p->body.border.opa) >> 8; + opa_t bopa = (uint32_t)((uint32_t) style_p->opa * style_p->body.border.opa) >> 8; area_t work_area; cord_t length_corr = 0; cord_t corner_size = 0; diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index d7ef549cd..6dba91f12 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -1535,8 +1535,9 @@ static void lv_style_refr_core(void * style_p, lv_obj_t * obj) { lv_obj_t * i; LL_READ(obj->child_ll, i) { - if(i->style_p == style_p || style_p == NULL) { + if(i->style_p == style_p) { refresh_childen_style(i); + lv_obj_refresh_style(i); } lv_style_refr_core(style_p, i); diff --git a/lv_obj/lv_style.c b/lv_obj/lv_style.c index ff3c01f6e..528fd1a5f 100644 --- a/lv_obj/lv_style.c +++ b/lv_obj/lv_style.c @@ -14,7 +14,7 @@ /********************* * DEFINES *********************/ -#define LV_STYLE_ANIM_RES 255 /*Animation max in 1024 steps*/ +#define LV_STYLE_ANIM_RES 256 /*Animation max in 1024 steps*/ #define LV_STYLE_ANIM_SHIFT 8 /*log2(LV_STYLE_ANIM_RES)*/ #define VAL_PROP(v1, v2, r) v1 + (((v2-v1) * r) >> LV_STYLE_ANIM_SHIFT) @@ -24,8 +24,8 @@ * TYPEDEFS **********************/ typedef struct { - const lv_style_t * style_start; - const lv_style_t * style_end; + const lv_style_t style_start; /*Save not only pointers because if same as 'style_anim' then it will be modified too*/ + const lv_style_t style_end; lv_style_t * style_anim; }lv_style_anim_dsc_t; @@ -90,7 +90,7 @@ void lv_style_init (void) lv_style_scr.text.font = font_get(FONT_DEFAULT); lv_style_scr.text.space_letter = 1 << LV_ANTIALIAS; lv_style_scr.text.space_line = 2 << LV_ANTIALIAS; - lv_style_scr.text.align = LV_TXT_ALIGN_LEFT; + lv_style_scr.text.align = LV_TEXT_ALIGN_LEFT; lv_style_scr.image.color = COLOR_MAKE(0x20, 0x20, 0x20); lv_style_scr.image.intense = OPA_TRANSP; @@ -153,7 +153,7 @@ void lv_style_init (void) lv_style_button_off_released.body.border.width = LV_DPI / 50 >= 1 ? LV_DPI / 50 : 1; lv_style_button_off_released.body.border.opa = OPA_70; lv_style_button_off_released.text.color = COLOR_MAKE(0xff, 0xff, 0xff); - lv_style_button_off_released.text.align = LV_TXT_ALIGN_MID; + lv_style_button_off_released.text.align = LV_TEXT_ALIGN_MID; lv_style_button_off_released.body.shadow.color = COLOR_GRAY; lv_style_button_off_released.body.shadow.width = 0; @@ -265,8 +265,8 @@ void lv_style_anim_create(lv_style_anim_t * anim) lv_style_anim_dsc_t * dsc; dsc = dm_alloc(sizeof(lv_style_anim_dsc_t)); dsc->style_anim = anim->style_anim; - dsc->style_start = anim->style_start; - dsc->style_end = anim->style_end; + memcpy(&dsc->style_start, anim->style_start, sizeof(lv_style_t)); + memcpy(&dsc->style_end, anim->style_end, sizeof(lv_style_t)); anim_t a; a.var = (void*)dsc; @@ -296,8 +296,8 @@ void lv_style_anim_create(lv_style_anim_t * anim) */ static void lv_style_aimator(lv_style_anim_dsc_t * dsc, int32_t val) { - const lv_style_t * start = dsc->style_start; - const lv_style_t * end = dsc->style_end; + const lv_style_t * start = &dsc->style_start; + const lv_style_t * end = &dsc->style_end; lv_style_t * act = dsc->style_anim; STYLE_ATTR_ANIM(opa, val); @@ -338,4 +338,9 @@ static void lv_style_aimator(lv_style_anim_dsc_t * dsc, int32_t val) } lv_style_refr_objs(dsc->style_anim); + + + if(val == LV_STYLE_ANIM_RES) { + dm_free(dsc); + } } diff --git a/lv_obj/lv_style.h b/lv_obj/lv_style.h index 0c0e061e3..7778732a0 100644 --- a/lv_obj/lv_style.h +++ b/lv_obj/lv_style.h @@ -29,9 +29,9 @@ extern "C" { **********************/ typedef enum { - LV_TXT_ALIGN_LEFT = 0, - LV_TXT_ALIGN_MID, -}lv_txt_align_t; + LV_TEXT_ALIGN_LEFT = 0, + LV_TEXT_ALIGN_MID, +}lv_text_align_t; /*Shadow types*/ typedef enum diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index 2af9ca309..25a21d4eb 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -460,6 +460,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ ancestor_design_f(btnm, mask, mode); lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); + lv_style_t * bg_style = lv_obj_get_style(btnm); lv_style_t * btn_style; area_t area_btnm; @@ -507,6 +508,8 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ area_tmp.x2 = area_tmp.x1 + txt_size.x; area_tmp.y2 = area_tmp.y1 + txt_size.y; + + if(btn_style->glass) btn_style = bg_style; lv_draw_label(&area_tmp, mask, btn_style, ext->map_p[txt_i], TXT_FLAG_NONE, NULL); } } diff --git a/lv_objx/lv_kb.c b/lv_objx/lv_kb.c index f3089b446..604e80a7a 100644 --- a/lv_objx/lv_kb.c +++ b/lv_objx/lv_kb.c @@ -27,36 +27,36 @@ static bool lv_kb_design(lv_obj_t * kb, const area_t * mask, lv_design_mode_t mode); #endif -static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, uint16_t i); +static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt); /********************** * STATIC VARIABLES **********************/ static const char * kb_map_lc[] = { -"\0051#", "\004q", "\004w", "\004e", "\004r", "\004t", "\004y", "\004u", "\004i", "\004o", "\004p", "\007Del", "\n", -"\006ABC", "\003a", "\003s", "\003d", "\003f", "\003g", "\003h", "\003j", "\003k", "\003l", "\010Enter", "\n", +"\2051#", "\204q", "\204w", "\204e", "\204r", "\204t", "\204y", "\204u", "\204i", "\204o", "\204p", "\207Del", "\n", +"\206ABC", "\203a", "\203s", "\203d", "\203f", "\203g", "\203h", "\203j", "\203k", "\203l", "\207Enter", "\n", "_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n", -"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", "" +"\203Hide", "\203Left", "\206 ", "\203Right", "\203Ok", "" }; static const char * kb_map_uc[] = { -"\0051#", "\004Q", "\004W", "\004E", "\004R", "\004T", "\004Y", "\004U", "\004I", "\004O", "\004P", "\007Del", "\n", -"\006abc", "\003A", "\003S", "\003D", "\003F", "\003G", "\003H", "\003J", "\003K", "\003L", "\010Enter", "\n", +"\2051#", "\204Q", "\204W", "\204E", "\204R", "\204T", "\204Y", "\204U", "\204I", "\204O", "\204P", "\207Del", "\n", +"\206abc", "\203A", "\203S", "\203D", "\203F", "\203G", "\203H", "\203J", "\203K", "\203L", "\2070Enter", "\n", "_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n", -"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", "" +"\203Hide", "\203Left", "\206 ", "\203Right", "\203Ok", "" }; static const char * kb_map_spec[] = { -"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\002Del", "\n", -"\002abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n", +"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\202Del", "\n", +"\202abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n", "\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n", -"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", "" +"\203Hide", "\203Left", "\206 ", "\203Right", "\203Ok", "" }; static const char * kb_map_num[] = { -"1", "2", "3", "\002Hide","\n", -"4", "5", "6", "\002Ok", "\n", -"7", "8", "9", "\002Del", "\n", +"1", "2", "3", "\202Hide","\n", +"4", "5", "6", "\202Ok", "\n", +"7", "8", "9", "\202Del", "\n", "+/-", "0", ".", "Left", "Right", "" }; /********************** @@ -90,7 +90,7 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy) /*Initialize the allocated 'ext' */ ext->ta = NULL; - ext->mode = LV_KB_MODE_TXT; + ext->mode = LV_KB_MODE_TEXT; ext->cur_mng = 0; ext->close_action = NULL; ext->ok_action = NULL; @@ -173,7 +173,7 @@ void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode) { lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); ext->mode = mode; - if(mode == LV_KB_MODE_TXT) lv_btnm_set_map(kb, kb_map_lc); + if(mode == LV_KB_MODE_TEXT) lv_btnm_set_map(kb, kb_map_lc); else if(mode == LV_KB_MODE_NUM) lv_btnm_set_map(kb, kb_map_num); } @@ -315,19 +315,11 @@ static bool lv_kb_design(lv_obj_t * kb, const area_t * mask, lv_design_mode_t mo * @param i the index of the released button from the current btnm map * @return LV_ACTION_RES_INV if the btnm is deleted else LV_ACTION_RES_OK */ -static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, uint16_t i) +static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt) { lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); if(ext->ta == NULL) return LV_ACTION_RES_OK; - const char ** map = lv_btnm_get_map(kb); - const char * txt = map[i]; - - /*Ignore the unit size number of the text*/ - if(txt[0] <= '\011') txt++; /*Ignore length specifier*/ - - if(txt[0] == '\177') return LV_ACTION_RES_OK; /*Don't care hidden buttons*/ - /*Do the corresponding action according to the text of the button*/ if(strcmp(txt, "abc") == 0) { lv_btnm_set_map(kb, kb_map_lc); diff --git a/lv_objx/lv_kb.h b/lv_objx/lv_kb.h index 51dd34ccf..a7e0848d5 100644 --- a/lv_objx/lv_kb.h +++ b/lv_objx/lv_kb.h @@ -28,7 +28,7 @@ extern "C" { **********************/ typedef enum { - LV_KB_MODE_TXT, + LV_KB_MODE_TEXT, LV_KB_MODE_NUM, }lv_kb_mode_t; diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index dcbfee35f..a51462cec 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -86,6 +86,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy) ext->static_txt = 0; ext->recolor = 0; ext->no_break = 0; + ext->body_draw = 0; ext->dot_end = LV_LABEL_DOT_END_INV; ext->long_mode = LV_LABEL_LONG_EXPAND; ext->offset.x = 0; @@ -105,6 +106,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy) lv_label_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_label_set_long_mode(new_label, lv_label_get_long_mode(copy)); lv_label_set_recolor(new_label, lv_label_get_recolor(copy)); + lv_label_set_body_draw(new_label, lv_label_get_body_draw(copy)); if(copy_ext->static_txt == 0) lv_label_set_text(new_label, lv_label_get_text(copy)); else lv_label_set_text_static(new_label, lv_label_get_text(copy)); @@ -310,30 +312,43 @@ void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode) /** * Enable the recoloring by in-line commands * @param label pointer to a label object - * @param recolor true: enable recoloring, false: disable + * @param recolor_enable true: enable recoloring, false: disable */ -void lv_label_set_recolor(lv_obj_t * label, bool recolor) +void lv_label_set_recolor(lv_obj_t * label, bool recolor_enable) { lv_label_ext_t * ext = lv_obj_get_ext_attr(label); - ext->recolor = recolor == false ? 0 : 1; + ext->recolor = recolor_enable == false ? 0 : 1; lv_label_refr_text(label); } /** - * Set the label the ignore (or accept) line breaks on '\n' + * Set the label to ignore (or accept) line breaks on '\n' * @param label pointer to a label object - * @param en true: ignore line breaks, false: make line breaks on '\n' + * @param no_break_enable true: ignore line breaks, false: make line breaks on '\n' */ -void lv_label_set_no_break(lv_obj_t * label, bool en) +void lv_label_set_no_break(lv_obj_t * label, bool no_break_enable) { lv_label_ext_t * ext = lv_obj_get_ext_attr(label); - ext->no_break = en == false ? 0 : 1; + ext->no_break = no_break_enable == false ? 0 : 1; lv_label_refr_text(label); - } + +/** + * Set the label to draw (or not draw) background specified in its style's body + * @param label pointer to a label object + * @param body_enable true: draw body; false: don't draw body + */ +void lv_label_set_body_draw(lv_obj_t *label, bool body_enable) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + ext->body_draw = body_enable == false ? 0 : 1; + + lv_obj_invalidate(label); +} + /*===================== * Getter functions *====================*/ @@ -372,6 +387,29 @@ bool lv_label_get_recolor(lv_obj_t * label) return ext->recolor == 0 ? false : true; } +/** + * Get the no break attribute + * @param label pointer to a label object + * @return true: no_break_enabled (ignore '\n' line breaks); false: make line breaks on '\n' + */ +bool lv_label_get_no_break(lv_obj_t * label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + return ext->no_break == 0 ? false : true; +} + +/** + * Get the body draw attribute + * @param label pointer to a label object + * @return true: draw body; false: don't draw body + */ +bool lv_label_get_body_draw(lv_obj_t *label) +{ + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + return ext->body_draw == 0 ? false : true; +} + + /** * Get the relative x and y coordinates of a letter * @param label pointer to a label object @@ -435,7 +473,7 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) x += (font_get_width(font, letter) >> FONT_ANTIALIAS) + style->text.space_letter; } - if(style->text.align == LV_TXT_ALIGN_MID) { + if(style->text.align == LV_TEXT_ALIGN_MID) { cord_t line_w; line_w = txt_get_width(&txt[line_start], new_line_start - line_start, font, style->text.space_letter, flag); @@ -485,7 +523,7 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos) /*Calculate the x coordinate*/ cord_t x = 0; - if(style->text.align == LV_TXT_ALIGN_MID) { + if(style->text.align == LV_TEXT_ALIGN_MID) { cord_t line_w; line_w = txt_get_width(&txt[line_start], new_line_start - line_start, font, style->text.space_letter, flag); @@ -542,15 +580,13 @@ static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mod } #endif - /*If the style is set explicitly draw background too*/ - if(label->style_p != NULL) { - lv_draw_rect(&cords, mask, style); - } + lv_label_ext_t * ext = lv_obj_get_ext_attr(label); + + if(ext->body_draw) lv_draw_rect(&cords, mask, style); /*TEST: draw a background for the label*/ - //lv_vfill(&label->cords, mask, COLOR_LIME, OPA_COVER); + //lv_vfill(&label->coords, mask, COLOR_LIME, OPA_COVER); - lv_label_ext_t * ext = lv_obj_get_ext_attr(label); txt_flag_t flag = TXT_FLAG_NONE; if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR; if(ext->expand != 0) flag |= TXT_FLAG_EXPAND; diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index fb4fdabb0..898940407 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -54,9 +54,10 @@ typedef struct uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/ 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; /*Ignore real width (used by the library with LV_LABEL_LONG_ROLL)*/ - uint8_t no_break :1; /*Ignore new line characters*/ + uint8_t recolor :1; /*Enable in-line letter re-coloring*/ + uint8_t expand :1; /*Ignore real width (used by the library with LV_LABEL_LONG_ROLL)*/ + uint8_t no_break :1; /*Ignore new line characters*/ + uint8_t body_draw :1; /*Draw background body*/ }lv_label_ext_t; /********************** @@ -137,6 +138,8 @@ void lv_label_set_recolor(lv_obj_t * label, bool recolor); */ void lv_label_set_no_break(lv_obj_t * label, bool en); + +void lv_label_set_body_draw(lv_obj_t *label, bool body_enable); /** * Get the text of a label * @param label pointer to a label object @@ -158,6 +161,21 @@ lv_label_long_mode_t lv_label_get_long_mode(lv_obj_t * label); */ bool lv_label_get_recolor(lv_obj_t * label); + +/** + * Get the no break attribute + * @param label pointer to a label object + * @return true: no_break_enabled (ignore '\n' line breaks); false: make line breaks on '\n' + */ +bool lv_label_get_no_break(lv_obj_t * label); + +/** + * Get the body draw attribute + * @param label pointer to a label object + * @return true: draw body; false: don't draw body + */ +bool lv_label_get_body_draw(lv_obj_t *label); + /** * Get the password mode * @param label pointer to a label object diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index d8e6fc2cb..3c2b18c34 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -243,8 +243,8 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, l lv_obj_t * label = lv_label_create(liste, NULL); lv_label_set_text(label, txt); lv_obj_set_click(label, false); - lv_obj_set_width(label, liste->coords.x2 - label->coords.x1); lv_label_set_long_mode(label, LV_LABEL_LONG_ROLL); + lv_obj_set_width(label, liste->coords.x2 - label->coords.x1); } return liste; diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 282bd32da..c4614bcab 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -193,7 +193,7 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) ext->pr_action(page); } } else if(sign == LV_SIGNAL_RELEASED) { - if(lv_indev_is_dragging(param) == false) { + if(lv_indev_is_dragging(lv_indev_get_act()) == false) { if(ext->rel_action != NULL) { ext->rel_action(page); } @@ -324,7 +324,7 @@ bool lv_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param) page_ext->pr_action(page); } } else if(sign == LV_SIGNAL_RELEASED) { - if(lv_indev_is_dragging(param) == false) { + if(lv_indev_is_dragging(lv_indev_get_act()) == false) { if(page_ext->rel_action != NULL) { page_ext->rel_action(page); } diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 8a47c6505..33f32bd57 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -106,7 +106,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy) lv_obj_set_design_func(ext->page.scrl, lv_ta_scrling_design); lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK); - lv_label_set_text(ext->label, "Text.area"); + lv_label_set_text(ext->label, "Text area"); lv_page_glue_obj(ext->label, true); lv_obj_set_click(ext->label, false); lv_obj_set_style(new_ta, lv_style_get(LV_STYLE_PRETTY)); @@ -847,9 +847,9 @@ static bool lv_ta_scrling_design(lv_obj_t * scrl, const area_t * mask, lv_design /*Draw the cursor too*/ lv_obj_t * ta = lv_obj_get_parent(scrl); lv_ta_ext_t * ta_ext = lv_obj_get_ext_attr(ta); - if(ta_ext->cursor_show == 0 || ta_ext->cursor_state == 0) return true; /*The cursor is not visible now*/ - lv_style_t * label_style = lv_obj_get_style(ta_ext->label); + if(ta_ext->cursor_show == 0 || ta_ext->cursor_state == 0 || label_style->opa == OPA_TRANSP) return true; /*The cursor is not visible now*/ + lv_style_t cur_style; if(ta_ext->cursor_style != NULL) { @@ -932,7 +932,7 @@ static bool lv_ta_scrling_design(lv_obj_t * scrl, const area_t * mask, lv_design /*Get the current letter*/ #if TXT_UTF8 == 0 char letter_buf[2]; - letter_buf[0] = text[byte_pos]; + letter_buf[0] = txt[byte_pos]; letter_buf[1] = '\0'; #else char letter_buf[8] = {0}; diff --git a/lv_objx/lv_tabview.c b/lv_objx/lv_tabview.c index a6873d594..8f58600d0 100644 --- a/lv_objx/lv_tabview.c +++ b/lv_objx/lv_tabview.c @@ -34,7 +34,7 @@ static bool tabscrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param); static void tabpage_pressed_hadler(lv_obj_t * tabview, lv_obj_t * tabpage); static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage); static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage); -static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, uint16_t id); +static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name); /********************** * STATIC VARIABLES @@ -78,6 +78,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy) ext->content = NULL; ext->indic = NULL; ext->tabs = NULL; + ext->anim_time = LV_TABVIEW_ANIM_TIME; ext->tab_name_ptr = dm_alloc(sizeof(char*)); ext->tab_name_ptr[0] = ""; @@ -87,7 +88,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new tab tab*/ if(copy == NULL) { lv_obj_set_size(new_tabview, LV_HOR_RES, LV_VER_RES); - lv_obj_set_style(new_tabview, lv_style_get(LV_STYLE_PRETTY)); + lv_obj_set_style(new_tabview, lv_style_get(LV_STYLE_PLAIN)); ext->tabs = lv_btnm_create(new_tabview, NULL); lv_btnm_set_map(ext->tabs, tab_def); @@ -116,6 +117,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy) ext->tabs = lv_btnm_create(new_tabview, copy_ext->tabs); ext->indic = lv_obj_create(ext->tabs, copy_ext->indic); ext->content = lv_cont_create(new_tabview, copy_ext->content); + ext->anim_time = copy_ext->anim_time; ext->tab_name_ptr = dm_alloc(sizeof(char*)); ext->tab_name_ptr[0] = ""; @@ -184,8 +186,9 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name) /*Create the container page*/ lv_obj_t * h = lv_page_create(ext->content, NULL); - lv_obj_set_size(h, lv_obj_get_width(tabview), lv_obj_get_height(tabview)); - lv_obj_set_style(h, lv_style_get(LV_STYLE_PRETTY_COLOR)); + lv_obj_set_size(h, lv_obj_get_width(tabview), lv_obj_get_height(tabview) - lv_obj_get_height(ext->tabs)); + lv_obj_set_style(h, lv_style_get(LV_STYLE_PLAIN)); + lv_obj_set_style(lv_page_get_scrl(h), lv_style_get(LV_STYLE_TRANSPARENT_TIGHT)); lv_obj_set_signal_func(h, tabpage_signal); lv_page_set_sb_mode(h, LV_PAGE_SB_MODE_AUTO); if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(h)); @@ -231,12 +234,8 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en) ext->tab_act = id >= ext->tab_cnt ? ext->tab_cnt - 1 : id; -#if LV_TABVIEW_ANIM_TIME == 0 - anim_en = false; -#endif - cord_t cont_x = -(lv_obj_get_width(tabview) * id + style->body.padding.inner * id + style->body.padding.hor); - if(anim_en == false) { + if(ext->anim_time == 0 || anim_en == false) { lv_obj_set_x(ext->content, cont_x); } else { anim_t a; @@ -247,7 +246,7 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en) a.path = anim_get_path(ANIM_PATH_LIN); a.end_cb = NULL; a.act_time = 0; - a.time = LV_TABVIEW_ANIM_TIME; + a.time = ext->anim_time; a.playback = 0; a.playback_pause = 0; a.repeat = 0; @@ -260,7 +259,7 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en) lv_style_t * tabs_style = lv_obj_get_style(ext->tabs); cord_t indic_x = indic_width * id + tabs_style->body.padding.inner * id + tabs_style->body.padding.hor; - if(anim_en == false) { + if(ext->anim_time == 0 || anim_en == false ) { lv_obj_set_x(ext->indic, indic_x); } else { anim_t a; @@ -271,7 +270,7 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en) a.path = anim_get_path(ANIM_PATH_LIN); a.end_cb = NULL; a.act_time = 0; - a.time = LV_TABVIEW_ANIM_TIME; + a.time = ext->anim_time; a.playback = 0; a.playback_pause = 0; a.repeat = 0; @@ -282,6 +281,18 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en) lv_btnm_set_toggle(ext->tabs, true, ext->tab_act); } +/** + * Set the animation time of tab view when a new tab is loaded + * @param tabview pointer to Tab view object + * @param anim_time_ms time of animation in milliseconds + */ +void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time_ms) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + ext->anim_time = anim_time_ms; +} + + /*===================== * Getter functions *====================*/ @@ -352,6 +363,17 @@ lv_obj_t * lv_tabview_get_indic(lv_obj_t * tabview) return ext->indic; } +/** + * Get the animation time of tab view when a new tab is loaded + * @param tabview pointer to Tab view object + * @return time of animation in milliseconds + */ +uint16_t lv_tabview_get_anim_time(lv_obj_t * tabview, uint16_t anim_time_ms) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); + return ext->anim_time; +} + /*===================== * Other functions *====================*/ @@ -369,7 +391,7 @@ void lv_tabview_realign(lv_obj_t * tabview) lv_obj_align(ext->content, ext->tabs, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); lv_obj_t * pages = lv_obj_get_child(ext->content, NULL); while(pages != NULL) { - lv_obj_set_size(pages, lv_obj_get_width(tabview), lv_obj_get_height(tabview) - lv_obj_get_height(ext->tabs)); + lv_obj_set_size(pages, lv_obj_get_width(tabview), 200);//lv_obj_get_height(tabview) - lv_obj_get_height(ext->tabs)); pages = lv_obj_get_child(ext->content, pages); } @@ -581,12 +603,21 @@ static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage) * @param id the id of the tab (>= 0) * @return LV_ACTION_RES_OK because the button matrix in not deleted in the function */ -static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, uint16_t id) +static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, const char * tab_name) { lv_obj_t * tab = lv_obj_get_parent(tab_btnm); lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tab); - ext->tab_act = id; - lv_tabview_set_act(tab, id, true); + const char ** tabs_map = lv_btnm_get_map(tab_btnm); + + uint8_t i = 0; + + while(tabs_map[i][0] != '\0') { + if(strcmp(tabs_map[i], tab_name) == 0) break; + i++; + } + + ext->tab_act = i; + lv_tabview_set_act(tab, i, true); return LV_ACTION_RES_OK; } diff --git a/lv_objx/lv_tabview.h b/lv_objx/lv_tabview.h index 173e3f167..583debf1a 100644 --- a/lv_objx/lv_tabview.h +++ b/lv_objx/lv_tabview.h @@ -49,6 +49,7 @@ typedef struct point_t point_last; uint16_t tab_act; uint16_t tab_cnt; + uint16_t anim_time; uint8_t draging :1; uint8_t drag_h :1;