From 577fc7b528d96ba46a5f5810a6e603b4ca410bba Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 9 Oct 2017 16:11:54 +0200 Subject: [PATCH 1/3] lv_page: refresh size according to vpad/hpad on STYLE_CHANGE --- lv_objx/lv_cont.c | 16 +++++----------- lv_objx/lv_page.c | 20 ++++++++++++-------- lv_objx/lv_ta.c | 14 +++++++++++--- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lv_objx/lv_cont.c b/lv_objx/lv_cont.c index 793fb1447..f754ba847 100644 --- a/lv_objx/lv_cont.c +++ b/lv_objx/lv_cont.c @@ -116,24 +116,18 @@ bool lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param) /* The object can be deleted so check its validity and then * make the object specific signal handling */ if(valid != false) { - switch(sign) { - case LV_SIGNAL_STYLE_CHG: /*Recalculate the padding if the style changed*/ + if(sign == LV_SIGNAL_STYLE_CHG) { /*Recalculate the padding if the style changed*/ lv_cont_refr_layout(cont); lv_cont_refr_autofit(cont); - break; - case LV_SIGNAL_CHILD_CHG: + } else if(sign == LV_SIGNAL_CHILD_CHG) { lv_cont_refr_layout(cont); lv_cont_refr_autofit(cont); - break; - case LV_SIGNAL_CORD_CHG: - if(lv_obj_get_width(cont) != area_get_width(param) || - lv_obj_get_height(cont) != area_get_height(param)) { + } else if(sign == LV_SIGNAL_CORD_CHG) { + if(lv_obj_get_width(cont) != area_get_width(param) || + lv_obj_get_height(cont) != area_get_height(param)) { lv_cont_refr_layout(cont); lv_cont_refr_autofit(cont); } - break; - default: - break; } } diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index fa95a22c0..bf8d2c81f 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -157,6 +157,8 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) lv_style_t * style = lv_obj_get_style(page); if(lv_cont_get_hfit(ext->scrl) == false) { lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->hpad); + } else { + ext->scrl->signal_f(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->cords); } if(ext->sb_mode == LV_PAGE_SB_MODE_ON) { @@ -172,8 +174,8 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) lv_style_t * style = lv_obj_get_style(page); /*Refresh the scrollbar and notify the scrl if the size is changed*/ if(ext->scrl != NULL && - (lv_obj_get_width(page) != area_get_width(param) || - lv_obj_get_height(page) != area_get_height(param))) { + (lv_obj_get_width(page) != area_get_width(param) || + lv_obj_get_height(page) != area_get_height(param))) { if(lv_cont_get_hfit(ext->scrl) == false) { lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->hpad); @@ -181,9 +183,9 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) ext->scrl->signal_f(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->cords); - /*The scrollbars are important olny if they are visible now*/ + /*The scrollbars are important only if they are visible now*/ if(ext->sbh_draw != 0 || ext->sbv_draw != 0) - lv_page_sb_refresh(page); + lv_page_sb_refresh(page); } } else if(sign == LV_SIGNAL_PRESSED) { @@ -224,6 +226,12 @@ bool lv_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param) lv_page_ext_t * page_ext = lv_obj_get_ext(page); if(sign == LV_SIGNAL_CORD_CHG) { + + /*Be sure the width of the scrollable is correct*/ + if(lv_cont_get_hfit(scrl) == false) { + lv_obj_set_width(scrl, lv_obj_get_width(page) - 2 * page_style->hpad); + } + cord_t new_x; cord_t new_y; bool refr_x = false; @@ -278,10 +286,6 @@ bool lv_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param) } lv_page_sb_refresh(page); - } else if(sign == LV_SIGNAL_CORD_CHG) { - if(lv_cont_get_hfit(scrl) == false) { - lv_obj_set_width(scrl, lv_obj_get_width(page) - 2 * page_style->hpad); - } } else if(sign == LV_SIGNAL_DRAG_BEGIN) { if(page_ext->sb_mode == LV_PAGE_SB_MODE_DRAG ) { cord_t sbh_pad = MATH_MAX(page_ext->sb_width, page_style->hpad); diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 10a1f7880..e24ca52fa 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -172,9 +172,16 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) } else if(sign == LV_SIGNAL_STYLE_CHG) { if(ext->label) { lv_obj_t * scrl = lv_page_get_scrl(ta); + lv_style_t * style_ta = lv_obj_get_style(ta); lv_style_t * style_scrl = lv_obj_get_style(scrl); - lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->hpad); - lv_obj_set_pos(ext->label, style_scrl->hpad, style_scrl->vpad); + if(ext->one_line) { /*In one line mode refresh the Text Area height because 'vpad' can modify it*/ + lv_style_t * style_label = lv_obj_get_style(ext->label); + cord_t font_h = font_get_height(style_label->font) >> FONT_ANTIALIAS; + lv_obj_set_height(ta, font_h + (style_ta->vpad + style_scrl->vpad) * 2); + } else { /*In not one line mode refresh the Label width because 'hpad' can modify it*/ + lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->hpad); + lv_obj_set_pos(ext->label, style_scrl->hpad, style_scrl->vpad); /*Be sure the Label is in the correct position*/ + } lv_label_set_text(ext->label, NULL); lv_obj_refr_ext_size(lv_page_get_scrl(ta)); @@ -669,12 +676,13 @@ void lv_ta_set_one_line(lv_obj_t * ta, bool en) if(en != false) { lv_ta_ext_t * ext = lv_obj_get_ext(ta); lv_style_t * style_ta = lv_obj_get_style(ta); + lv_style_t * style_scrl = lv_obj_get_style(lv_page_get_scrl(ta)); lv_style_t * style_label = lv_obj_get_style(ext->label); cord_t font_h = font_get_height(style_label->font) >> FONT_ANTIALIAS; ext->one_line = 1; lv_cont_set_fit(lv_page_get_scrl(ta), true, true); - lv_obj_set_height(ta, font_h + style_ta->vpad * 2); + lv_obj_set_height(ta, font_h + (style_ta->vpad + style_scrl->vpad) * 2); lv_label_set_long_mode(ext->label, LV_LABEL_LONG_EXPAND); lv_label_set_no_break(ext->label, true); lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->hpad, style_ta->vpad); From 748009735c569df3a65fe4fff05d466c12c21a49 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 9 Oct 2017 16:30:47 +0200 Subject: [PATCH 2/3] lv_ta: apply hpad/vpad on cursor position/size --- lv_objx/lv_ta.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index e24ca52fa..2e70ef951 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -866,6 +866,8 @@ static bool lv_ta_scrling_design(lv_obj_t * scrl, const area_t * mask, lv_design cur_style.radius = 0; cur_style.empty = 0; cur_style.opa = OPA_COVER; + cur_style.hpad = 0; + cur_style.vpad = 0; } uint16_t cur_pos = lv_ta_get_cursor_pos(ta); @@ -911,16 +913,16 @@ static bool lv_ta_scrling_design(lv_obj_t * scrl, const area_t * mask, lv_design /*Draw he cursor according to the type*/ area_t cur_area; if(ta_ext->cursor_type == LV_TA_CURSOR_LINE) { - cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1 - (cur_style.line_width >> 1) - (cur_style.line_width & 0x1); - cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1; - cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + (cur_style.line_width >> 1); - cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + letter_h; + cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1 + cur_style.hpad - (cur_style.line_width >> 1) - (cur_style.line_width & 0x1); + cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1 + cur_style.vpad; + cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + cur_style.hpad + (cur_style.line_width >> 1); + cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + cur_style.vpad + letter_h; lv_draw_rect(&cur_area, mask, &cur_style); } else if(ta_ext->cursor_type == LV_TA_CURSOR_BLOCK) { - cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1; - cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1; - cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + letter_w; - cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + letter_h; + cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1 - cur_style.hpad; + cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1 - cur_style.vpad; + cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + cur_style.hpad + letter_w; + cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + cur_style.vpad + letter_h; lv_draw_rect(&cur_area, mask, &cur_style); @@ -933,22 +935,24 @@ static bool lv_ta_scrling_design(lv_obj_t * scrl, const area_t * mask, lv_design char letter_buf[8] = {0}; memcpy(letter_buf, &txt[byte_pos], txt_utf8_size(txt[byte_pos])); #endif + cur_area.x1 += cur_style.hpad; + cur_area.y1 += cur_style.vpad; lv_draw_label(&cur_area, mask, &cur_style, letter_buf, TXT_FLAG_NONE, 0); } else if(ta_ext->cursor_type == LV_TA_CURSOR_OUTLINE) { - cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1; - cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1; - cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + letter_w; - cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + letter_h; + cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1 - cur_style.hpad; + cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1 - cur_style.vpad; + cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + cur_style.hpad + letter_w; + cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 - cur_style.vpad+ letter_h; cur_style.empty = 1; if(cur_style.bwidth == 0) cur_style.bwidth = 1 * LV_DOWNSCALE; /*Be sure the border will be drawn*/ lv_draw_rect(&cur_area, mask, &cur_style); } else if(ta_ext->cursor_type == LV_TA_CURSOR_UNDERLINE) { - cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1; - cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1 + letter_h - (cur_style.line_width >> 1); - cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + letter_w; - cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + letter_h + (cur_style.line_width >> 1) + (cur_style.line_width & 0x1); + cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1 + cur_style.hpad; + cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1 + cur_style.vpad + letter_h - (cur_style.line_width >> 1); + cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + cur_style.hpad + letter_w; + cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + cur_style.vpad + letter_h + (cur_style.line_width >> 1) + (cur_style.line_width & 0x1); lv_draw_rect(&cur_area, mask, &cur_style); } From 57619fca0647e4ac997963fc6fc8d69e6acd0d3c Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 10 Oct 2017 16:15:59 +0200 Subject: [PATCH 3/3] fix a style refresh issue --- lv_obj/lv_obj.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index 93af18301..cdfa0f2d8 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -808,6 +808,9 @@ void lv_obj_set_style(lv_obj_t * obj, lv_style_t * style) /*Send a signal about style change to every children with NULL style*/ lv_child_refr_style(obj); + /*Notify the object about the style change too*/ + lv_obj_refr_style(obj); + } /** @@ -1526,7 +1529,7 @@ static void lv_child_refr_style(lv_obj_t * obj) while(child != NULL) { if(child->style_p == NULL) { lv_child_refr_style(child); /*Check children too*/ - lv_obj_refr_style(obj); /*Send a style change signal to the object*/ + lv_obj_refr_style(child); /*Notify the child about the style change*/ } else if(child->style_p->glass) { /*Children with 'glass' parent might be effected if their style == NULL*/ lv_child_refr_style(child);