From f504d016444e765a52919565e5eb2f706eede474 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Sun, 9 Dec 2018 20:51:32 -0500 Subject: [PATCH 1/6] Add lv_ddlist_set_align and lv_ddlist_get_align --- lv_objx/lv_ddlist.c | 40 +++++++++++++++++++++++++++++++++++++++- lv_objx/lv_ddlist.h | 14 ++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index 5ee00fa63..66baf77f8 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -287,6 +287,12 @@ void lv_ddlist_set_style(lv_obj_t * ddlist, lv_ddlist_style_t type, lv_style_t * } } +void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + lv_label_set_align(ext->label, align); +} /*===================== * Getter functions *====================*/ @@ -407,6 +413,14 @@ lv_style_t * lv_ddlist_get_style(const lv_obj_t * ddlist, lv_ddlist_style_t type /*To avoid warning*/ return NULL; } + +lv_label_align_t lv_ddlist_get_align(const lv_obj_t *ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + return lv_label_get_align(ext->label); +} + /*===================== * Other functions *====================*/ @@ -447,6 +461,29 @@ void lv_ddlist_close(lv_obj_t * ddlist, bool anim_en) * STATIC FUNCTIONS **********************/ +/** + * Get the text alignment flag for a drop down list. + * @param ddlist drop down list + * @return text alignment flag + */ +static lv_txt_flag_t lv_ddlist_get_txt_flag(const lv_obj_t *ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + lv_label_align_t align = lv_label_get_align(ext->label); + + switch(align) + { + default: + case LV_LABEL_ALIGN_LEFT: + return LV_TXT_FLAG_NONE; + case LV_LABEL_ALIGN_CENTER: + return LV_TXT_FLAG_CENTER; + case LV_LABEL_ALIGN_RIGHT: + return LV_TXT_FLAG_RIGHT; + } +} + /** * Handle the drawing related tasks of the drop down lists * @param ddlist pointer to an object @@ -517,8 +554,9 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_desig lv_style_copy(&new_style, style); new_style.text.color = sel_style->text.color; new_style.text.opa = sel_style->text.opa; + lv_txt_flag_t flag = lv_ddlist_get_txt_flag(ddlist); lv_draw_label(&ext->label->coords, &mask_sel, &new_style, opa_scale, - lv_label_get_text(ext->label), LV_TXT_FLAG_NONE, NULL); + lv_label_get_text(ext->label), flag, NULL); } } diff --git a/lv_objx/lv_ddlist.h b/lv_objx/lv_ddlist.h index d928d6520..4c9207463 100644 --- a/lv_objx/lv_ddlist.h +++ b/lv_objx/lv_ddlist.h @@ -150,6 +150,13 @@ void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time); * */ void lv_ddlist_set_style(lv_obj_t *ddlist, lv_ddlist_style_t type, lv_style_t *style); +/** + * Set the alignment of the labels in a drop down list + * @param ddlist pointer to a drop down list object + * @param align alignment of labels + */ +void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align); + /*===================== * Getter functions *====================*/ @@ -220,6 +227,13 @@ uint16_t lv_ddlist_get_anim_time(const lv_obj_t * ddlist); */ lv_style_t * lv_ddlist_get_style(const lv_obj_t *ddlist, lv_ddlist_style_t type); +/** + * Get the alignment of the labels in a drop down list + * @param ddlist pointer to a drop down list object + * @return alignment of labels + */ +lv_label_align_t lv_ddlist_get_align(const lv_obj_t *ddlist); + /*===================== * Other functions *====================*/ From e60482ca0e97d9e51d5b5cbcbcfd87fdb3a4d369 Mon Sep 17 00:00:00 2001 From: Martin Herancourt Date: Tue, 11 Dec 2018 10:21:22 +0100 Subject: [PATCH 2/6] minor fixes --- lv_objx/lv_list.c | 15 ++++++++------- lv_themes/lv_theme_alien.c | 2 -- lv_themes/lv_theme_mono.c | 4 +--- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index dc8213e58..a9c4cd84f 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -391,10 +391,10 @@ lv_obj_t * lv_list_get_btn_img(const lv_obj_t * btn) } /** - * Get the next button from list. (Starts from the bottom button) + * Get the previous button from list. (Starts from the top button) * @param list pointer to a list object - * @param prev_btn pointer to button. Search the next after it. - * @return pointer to the next button or NULL when no more buttons + * @param prev_btn pointer to button. Search the previous before it. + * @return pointer to the previous button or NULL when no more buttons */ lv_obj_t * lv_list_get_prev_btn(const lv_obj_t * list, lv_obj_t * prev_btn) { @@ -416,11 +416,12 @@ lv_obj_t * lv_list_get_prev_btn(const lv_obj_t * list, lv_obj_t * prev_btn) } -/** - * Get the previous button from list. (Starts from the top button) + + /** + * Get the next button from list. (Starts from the bottom button) * @param list pointer to a list object - * @param prev_btn pointer to button. Search the previous before it. - * @return pointer to the previous button or NULL when no more buttons + * @param prev_btn pointer to button. Search the next after it. + * @return pointer to the next button or NULL when no more buttons */ lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn) { diff --git a/lv_themes/lv_theme_alien.c b/lv_themes/lv_theme_alien.c index 386efb61e..d271f8610 100644 --- a/lv_themes/lv_theme_alien.c +++ b/lv_themes/lv_theme_alien.c @@ -28,8 +28,6 @@ static uint16_t _hue; static lv_font_t * _font; -static lv_font_t * _font; -static lv_font_t * _font; static lv_theme_t theme; static lv_style_t def; diff --git a/lv_themes/lv_theme_mono.c b/lv_themes/lv_theme_mono.c index 4fee86a58..f456caec1 100644 --- a/lv_themes/lv_theme_mono.c +++ b/lv_themes/lv_theme_mono.c @@ -36,7 +36,6 @@ static lv_style_t light_frame; static lv_style_t dark_frame; /*Saved input parameters*/ -static uint16_t _hue; static lv_font_t * _font; @@ -421,7 +420,7 @@ static void win_init(void) /** * Initialize the mono theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color + * @param hue [0..360] hue value from HSV color space to define the theme's base color; is not used in lv_theme_mono * @param font pointer to a font (NULL to use the default) * @return pointer to the initialized theme */ @@ -429,7 +428,6 @@ lv_theme_t * lv_theme_mono_init(uint16_t hue, lv_font_t * font) { if(font == NULL) font = LV_FONT_DEFAULT; - _hue = hue; _font = font; /*For backward compatibility initialize all theme elements with a default style */ From e68c3ab725f869a57a3810c9996998b1b84e79c4 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 11 Dec 2018 18:00:32 +0100 Subject: [PATCH 3/6] line draw updates with width = 1 --- lv_draw/lv_draw_line.c | 68 +++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/lv_draw/lv_draw_line.c b/lv_draw/lv_draw_line.c index 9e461f1c9..600cdc986 100644 --- a/lv_draw/lv_draw_line.c +++ b/lv_draw/lv_draw_line.c @@ -73,7 +73,7 @@ static bool line_next_x(line_draw_t * line); * @param opa_scale scale down all opacities by the factor */ void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, - const lv_style_t * style, lv_opa_t opa_scale) + const lv_style_t * style, lv_opa_t opa_scale) { if(style->line.width == 0) return; @@ -279,16 +279,12 @@ static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_ width = i; #if LV_ANTIALIAS width--; - #endif break; } line_next(&pattern_line); } - } else { - pattern[0].x = 0; - pattern[0].y = 0; } #if LV_ANTIALIAS @@ -299,12 +295,22 @@ static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_ aa_last_corner = 0; #endif + lv_coord_t x_center_ofs = 0; + lv_coord_t y_center_ofs = 0; + if(width != 0) { + x_center_ofs = pattern[width - 1].x / 2; + y_center_ofs = pattern[width - 1].y / 2; + } + else { + if(main_line->hor && main_line->p1.y >= main_line->p2.y + dir_ori) pattern[0].y --; + if(!main_line->hor && main_line->p1.x >= main_line->p2.x + dir_ori) pattern[0].x --; + } /* Make the coordinates relative to the center */ for(i = 0; i < width; i++) { - pattern[i].x -= pattern[width - 1].x / 2; - pattern[i].y -= pattern[width - 1].y / 2; + pattern[i].x -= x_center_ofs; + pattern[i].y -= y_center_ofs; #if LV_ANTIALIAS if(i != 0) { if(main_line->hor) { @@ -312,16 +318,16 @@ static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_ lv_coord_t seg_w = pattern[i].y - pattern[aa_last_corner].y; if(main_line->sy < 0) { lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w + 1, - seg_w, mask, style->line.color, opa); + seg_w, mask, style->line.color, opa); lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w + 1, - -seg_w, mask, style->line.color, opa); + -seg_w, mask, style->line.color, opa); } else { lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y, - seg_w, mask, style->line.color, opa); + seg_w, mask, style->line.color, opa); lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y, - -seg_w, mask, style->line.color, opa); + -seg_w, mask, style->line.color, opa); } aa_last_corner = i; } @@ -330,16 +336,16 @@ static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_ lv_coord_t seg_w = pattern[i].x - pattern[aa_last_corner].x; if(main_line->sx < 0) { lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x + seg_w + 1, main_line->p1.y + pattern[aa_last_corner].y - 1, - seg_w, mask, style->line.color, opa); + seg_w, mask, style->line.color, opa); lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x + seg_w + 1, main_line->p2.y + pattern[aa_last_corner].y + 1, - -seg_w, mask, style->line.color, opa); + -seg_w, mask, style->line.color, opa); } else { lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1, - seg_w, mask, style->line.color, opa); + seg_w, mask, style->line.color, opa); lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x, main_line->p2.y + pattern[aa_last_corner].y + 1, - -seg_w, mask, style->line.color, opa); + -seg_w, mask, style->line.color, opa); } aa_last_corner = i; } @@ -358,33 +364,33 @@ static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_ lv_coord_t seg_w = pattern[width_safe - 1].y - pattern[aa_last_corner].y; if(main_line->sy < 0) { lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w, - seg_w + main_line->sy, mask, style->line.color, opa); + seg_w + main_line->sy, mask, style->line.color, opa); lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w, - -(seg_w + main_line->sy), mask, style->line.color, opa); + -(seg_w + main_line->sy), mask, style->line.color, opa); } else { lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y, - seg_w + main_line->sy, mask, style->line.color, opa); + seg_w + main_line->sy, mask, style->line.color, opa); lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y, - -(seg_w + main_line->sy), mask, style->line.color, opa); + -(seg_w + main_line->sy), mask, style->line.color, opa); } } else { lv_coord_t seg_w = pattern[width_safe - 1].x - pattern[aa_last_corner].x; if(main_line->sx < 0) { lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x + seg_w, main_line->p1.y + pattern[aa_last_corner].y - 1, - seg_w + main_line->sx, mask, style->line.color, opa); + seg_w + main_line->sx, mask, style->line.color, opa); lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x + seg_w, main_line->p2.y + pattern[aa_last_corner].y + 1, - -(seg_w + main_line->sx), mask, style->line.color, opa); + -(seg_w + main_line->sx), mask, style->line.color, opa); } else { lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1, - seg_w + main_line->sx, mask, style->line.color, opa); + seg_w + main_line->sx, mask, style->line.color, opa); lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x, main_line->p2.y + pattern[aa_last_corner].y + 1, - -(seg_w + main_line->sx), mask, style->line.color, opa); + -(seg_w + main_line->sx), mask, style->line.color, opa); } } @@ -441,9 +447,9 @@ static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_ #if LV_ANTIALIAS lv_draw_aa_hor_seg(prev_p.x + pattern[0].x, prev_p.y + pattern[0].y - aa_shift1, - -(main_line->p_act.x - prev_p.x), mask, style->line.color, opa); + -(main_line->p_act.x - prev_p.x), mask, style->line.color, opa); lv_draw_aa_hor_seg(prev_p.x + pattern[width_safe - 1].x, prev_p.y + pattern[width_safe - 1].y + aa_shift2, - main_line->p_act.x - prev_p.x, mask, style->line.color, opa); + main_line->p_act.x - prev_p.x, mask, style->line.color, opa); #endif first_run = false; @@ -468,9 +474,9 @@ static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_ #if LV_ANTIALIAS lv_draw_aa_hor_seg(prev_p.x + pattern[0].x, prev_p.y + pattern[0].y - aa_shift1, - -(main_line->p_act.x - prev_p.x + 1), mask, style->line.color, opa); + -(main_line->p_act.x - prev_p.x + 1), mask, style->line.color, opa); lv_draw_aa_hor_seg(prev_p.x + pattern[width_safe - 1].x, prev_p.y + pattern[width_safe - 1].y + aa_shift2, - main_line->p_act.x - prev_p.x + 1, mask, style->line.color, opa); + main_line->p_act.x - prev_p.x + 1, mask, style->line.color, opa); #endif } /*Rather a vertical line*/ @@ -495,9 +501,9 @@ static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_ #if LV_ANTIALIAS lv_draw_aa_ver_seg(prev_p.x + pattern[0].x - aa_shift1, prev_p.y + pattern[0].y, - -(main_line->p_act.y - prev_p.y), mask, style->line.color, opa); + -(main_line->p_act.y - prev_p.y), mask, style->line.color, opa); lv_draw_aa_ver_seg(prev_p.x + pattern[width_safe - 1].x + aa_shift2, prev_p.y + pattern[width_safe - 1].y, - main_line->p_act.y - prev_p.y, mask, style->line.color, opa); + main_line->p_act.y - prev_p.y, mask, style->line.color, opa); #endif first_run = false; @@ -524,9 +530,9 @@ static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_ #if LV_ANTIALIAS lv_draw_aa_ver_seg(prev_p.x + pattern[0].x - aa_shift1, prev_p.y + pattern[0].y, - -(main_line->p_act.y - prev_p.y + 1), mask, style->line.color, opa); + -(main_line->p_act.y - prev_p.y + 1), mask, style->line.color, opa); lv_draw_aa_ver_seg(prev_p.x + pattern[width_safe - 1].x + aa_shift2, prev_p.y + pattern[width_safe - 1].y, - main_line->p_act.y - prev_p.y + 1, mask, style->line.color, opa); + main_line->p_act.y - prev_p.y + 1, mask, style->line.color, opa); #endif } } From a7bc41b528600e489307aa6dc389b42a01264952 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 12 Dec 2018 09:08:10 +0100 Subject: [PATCH 4/6] ddlist and roller delete fix --- lv_objx/lv_ddlist.c | 3 +++ lv_objx/lv_roller.c | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index 66baf77f8..657d4e5c9 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -470,6 +470,9 @@ static lv_txt_flag_t lv_ddlist_get_txt_flag(const lv_obj_t *ddlist) { lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + /*The label might be already deleted so just return with some value*/ + if(!ext->label) return LV_TXT_FLAG_CENTER; + lv_label_align_t align = lv_label_get_align(ext->label); switch(align) diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index 8f70c484d..db7d6b04c 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -334,10 +334,8 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); lv_align_t obj_align = LV_ALIGN_IN_LEFT_MID; - - { + if(ext->ddlist.label) { lv_label_align_t label_align = lv_label_get_align(ext->ddlist.label); - if(LV_LABEL_ALIGN_CENTER == label_align) obj_align = LV_ALIGN_CENTER; else if(LV_LABEL_ALIGN_RIGHT == label_align) obj_align = LV_ALIGN_IN_RIGHT_MID; } From 86de6f5fbc027c05506bb7bd625b46c2b832c372 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 12 Dec 2018 18:55:32 +0100 Subject: [PATCH 5/6] lv_font: fix typo --- lv_misc/lv_font.c | 2 +- lv_misc/lv_font.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lv_misc/lv_font.c b/lv_misc/lv_font.c index c9fd008c5..a794be888 100644 --- a/lv_misc/lv_font.c +++ b/lv_misc/lv_font.c @@ -50,7 +50,7 @@ void lv_font_init(void) * Create a pair from font name and font dsc. get function. After it 'font_get' can be used for this font * @param name name of the font * @param dsc_get_fp the font descriptor get function - * @param parent add this font as charter set extension of 'parent' + * @param parent add this font as character set extension of 'parent' */ void lv_font_add(lv_font_t * child, lv_font_t * parent) { diff --git a/lv_misc/lv_font.h b/lv_misc/lv_font.h index bbf56fd57..a26b73a95 100644 --- a/lv_misc/lv_font.h +++ b/lv_misc/lv_font.h @@ -73,8 +73,9 @@ void lv_font_init(void); /** * Create a pair from font name and font dsc. get function. After it 'font_get' can be used for this font - * @param child pointer to a font to join to the 'parent' - * @param parent pointer to a font. 'child' will be joined here + * @param name name of the font + * @param dsc_get_fp the font descriptor get function + * @param parent add this font as character set extension of 'parent' */ void lv_font_add(lv_font_t *child, lv_font_t *parent); From 6c552e8447e249e7fe729dca76409d41dfb4e710 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 12 Dec 2018 23:45:06 +0100 Subject: [PATCH 6/6] ta: fix cursor draw with LV_TXT_UTF8 == 0 --- lv_objx/lv_ta.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index f3dd9e7ee..9d3195946 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -966,11 +966,12 @@ static bool lv_ta_scrollable_design(lv_obj_t * scrl, const lv_area_t * mask, lv_ uint32_t byte_pos; #if LV_TXT_UTF8 != 0 byte_pos = lv_txt_encoded_get_byte_id(txt, cur_pos); + uint32_t letter = lv_txt_encoded_next(&txt[byte_pos], NULL); #else byte_pos = cur_pos; + uint32_t letter = txt[byte_pos]; #endif - uint32_t letter = lv_txt_encoded_next(&txt[byte_pos], NULL); lv_coord_t letter_h = lv_font_get_height(label_style->text.font); /*Set letter_w (set not 0 on non printable but valid chars)*/ lv_coord_t letter_w; @@ -1003,6 +1004,7 @@ static bool lv_ta_scrollable_design(lv_obj_t * scrl, const lv_area_t * mask, lv_ } } + /*Draw he cursor according to the type*/ lv_area_t cur_area; if(ext->cursor.type == LV_CURSOR_LINE) {