From 922d0ab1500138d21d89fd24309fb2e3baa2edb2 Mon Sep 17 00:00:00 2001 From: Gabor Date: Thu, 24 Aug 2017 14:28:02 +0200 Subject: [PATCH 01/19] lv_btnm_set_styles support trel, tpr and ina styles (API change) --- lv_objx/lv_btnm.c | 13 ++++++++++--- lv_objx/lv_btnm.h | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index aa19d5097..4ec1ef5ee 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -353,14 +353,21 @@ void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id) /** * Set the styles of the buttons of the button matrix * @param btnm pointer to a button matrix object - * @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL) - * @param style pointer to style + * @param rel pointer to a style for releases state + * @param pr pointer to a style for pressed state + * @param trel pointer to a style for toggled releases state + * @param tpr pointer to a style for toggled pressed state + * @param ina pointer to a style for inactive state */ -void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr) +void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr, + lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina) { lv_btnm_ext_t * ext = lv_obj_get_ext(btnm); ext->style_btn_rel = rel; ext->style_btn_pr = pr; + ext->style_btn_trel = trel; + ext->style_btn_tpr = tpr; + ext->style_btn_ina = ina; lv_obj_inv(btnm); diff --git a/lv_objx/lv_btnm.h b/lv_objx/lv_btnm.h index d43a63d93..1a356f2ef 100644 --- a/lv_objx/lv_btnm.h +++ b/lv_objx/lv_btnm.h @@ -47,8 +47,9 @@ typedef struct lv_btnm_callback_t cb; /*A function to call when a button is releases*/ lv_style_t * style_btn_rel; /*Style of the released buttons*/ lv_style_t * style_btn_pr; /*Style of the pressed buttons*/ - lv_style_t * style_btn_trel; /*Style of the released buttons*/ - lv_style_t * style_btn_tpr; /*Style of the pressed buttons*/ + lv_style_t * style_btn_trel; /*Style of the toggled released buttons*/ + lv_style_t * style_btn_tpr; /*Style of the toggled pressed buttons*/ + lv_style_t * style_btn_ina; /*Style of the inactive buttons*/ uint8_t tgl :1; /*Enable toggling*/ }lv_btnm_ext_t; @@ -100,13 +101,18 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb); */ void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id); + /** - * Set the styles of the buttons of the button matrox + * Set the styles of the buttons of the button matrix * @param btnm pointer to a button matrix object - * @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL) - * @param style pointer to style + * @param rel pointer to a style for releases state + * @param pr pointer to a style for pressed state + * @param trel pointer to a style for toggled releases state + * @param tpr pointer to a style for toggled pressed state + * @param ina pointer to a style for inactive state */ -void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr); +void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr, + lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina) /** * Get the current map of a button matrix From 892745a5927675ee3725e5e8cd0f37a546ea787d Mon Sep 17 00:00:00 2001 From: Gabor Date: Thu, 24 Aug 2017 14:29:28 +0200 Subject: [PATCH 02/19] lv_kb: action call bugfix --- lv_objx/lv_kb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lv_objx/lv_kb.c b/lv_objx/lv_kb.c index 94ef44b0b..bfff724c4 100644 --- a/lv_objx/lv_kb.c +++ b/lv_objx/lv_kb.c @@ -1,3 +1,4 @@ + /** * @file lv_kb.c * @@ -15,7 +16,6 @@ /********************* * DEFINES *********************/ - /********************** * TYPEDEFS **********************/ @@ -80,7 +80,6 @@ static const char * kb_map_num[] = { lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor of keyboard*/ - /*TODO modify it to the ancestor create function */ lv_obj_t * new_kb = lv_btnm_create(par, copy); dm_assert(new_kb); @@ -214,6 +213,7 @@ void lv_kb_set_close_action(lv_obj_t * kb, lv_action_t action) ext->close_action = action; } + /*===================== * Getter functions *====================*/ @@ -362,10 +362,10 @@ static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, uint16_t i) lv_ta_set_cursor_pos(ext->ta, cur + 1); } } else if(strcmp(txt, "Hide") == 0) { - //lv_app_kb_close(false); + if(ext->close_action) ext->close_action(kb, NULL); return LV_ACTION_RES_INV; } else if(strcmp(txt, "Ok") == 0) { - //lv_app_kb_close(true); + if(ext->ok_action) ext->ok_action(kb, NULL); return LV_ACTION_RES_INV; } else { lv_ta_add_text(ext->ta, txt); From 99dbf35953034a05f539319b69ea52096ba939a8 Mon Sep 17 00:00:00 2001 From: Gabor Date: Thu, 24 Aug 2017 14:30:14 +0200 Subject: [PATCH 03/19] lv_tabview: free allocated memory on in clean up signal --- lv_objx/lv_tabview.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lv_objx/lv_tabview.c b/lv_objx/lv_tabview.c index d66ef2d57..74ddc6924 100644 --- a/lv_objx/lv_tabview.c +++ b/lv_objx/lv_tabview.c @@ -151,10 +151,11 @@ bool lv_tabview_signal(lv_obj_t * tabview, 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) { + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); if(sign == LV_SIGNAL_CLEANUP) { - /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + dm_free(ext->tab_name_ptr); + ext->tab_name_ptr = NULL; } else if(sign == LV_SIGNAL_CORD_CHG) { - lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); if(ext->content != NULL && (lv_obj_get_width(tabview) != area_get_width(param) || lv_obj_get_height(tabview) != area_get_height(param))) From 9cefda4f7b3a442790fd222c36d51a09b55e385b Mon Sep 17 00:00:00 2001 From: Gabor Date: Sun, 3 Sep 2017 16:01:03 +0200 Subject: [PATCH 04/19] lv_label: lv_label_append_text() renamed and upgraded to lv_label_ins_text() --- lv_objx/lv_label.c | 29 ++++++++++++++++++++++------- lv_objx/lv_label.h | 14 ++++++++++---- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 305f0513d..4dcf9d4f9 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -238,11 +238,16 @@ void lv_label_set_text_static(lv_obj_t * label, const char * text) } /** - * Append a text to the label. The label current label text can not be static. + * Insert a text to the label. The label current label text can not be static. * @param label pointer to label object - * @param text pointe rto the new text + * @param pos character index to insert + * 0: before first char. + * LV_LABEL_POS_LAST: after last char. + * < 0: count from the end + * -1: before the last char. + * @param txt pointer to the text to insert */ -void lv_label_append_text(lv_obj_t * label, const char * text) +void lv_label_ins_text(lv_obj_t * label, int32_t pos, const char * txt) { lv_label_ext_t * ext = lv_obj_get_ext(label); @@ -253,11 +258,21 @@ void lv_label_append_text(lv_obj_t * label, const char * text) /*Allocate space for the new text*/ uint32_t old_len = strlen(ext->txt); - uint32_t app_len = strlen(text); - uint32_t new_len = app_len + old_len; + uint32_t ins_len = strlen(txt); + uint32_t new_len = ins_len + old_len; ext->txt = dm_realloc(ext->txt, new_len + 1); - memcpy(ext->txt + old_len, text, app_len); - ext->txt[new_len] = '\0'; + + if(pos == LV_LABEL_POS_LAST) pos = old_len; + else if(pos < 0) pos = old_len + pos; + + /*Copy the second part into the end to make place to text to insert*/ + int32_t i; + for(i = new_len; i >= pos + ins_len; i--){ + ext->txt[i] = ext->txt[i - ins_len]; + } + + /* Copy the text into the new space*/ + memcpy(ext->txt + pos, txt, ins_len); lv_label_refr_text(label); } diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index f5e84758d..8ea37da9a 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -19,12 +19,13 @@ extern "C" { #include "../lv_obj/lv_obj.h" #include "misc/gfx/font.h" #include "misc/gfx/text.h" +#include "misc/gfx/fonts/symbol_def.h" /********************* * DEFINES *********************/ #define LV_LABEL_DOT_NUM 3 - +#define LV_LABEL_POS_LAST 0xFFFF /********************** * TYPEDEFS **********************/ @@ -100,11 +101,16 @@ void lv_label_set_text_array(lv_obj_t * label, const char * array, uint16_t size void lv_label_set_text_static(lv_obj_t * label, const char * text); /** - * Append a text to the label. The label current label text can not be static. + * Insert a text to the label. The label current label text can not be static. * @param label pointer to label object - * @param text pointe rto the new text + * @param pos character index to insert + * 0: before first char. + * LV_LABEL_POS_LAST: after last char. + * < 0: count from the end + * -1: before the last char. + * @param txt pointer to the text to insert */ -void lv_label_append_text(lv_obj_t * label, const char * text); +void lv_label_ins_text(lv_obj_t * label, int32_t pos, const char * txt); /** * Set the behavior of the label with longer text then the object size From 7148f377c4bc9b7da728b4f685403b4f8e33e3d4 Mon Sep 17 00:00:00 2001 From: Gabor Date: Sun, 3 Sep 2017 16:01:51 +0200 Subject: [PATCH 05/19] lv_roller: lv_roler added but not ready yet --- lv_objx/lv_ddlist.c | 20 +++- lv_objx/lv_ddlist.h | 8 ++ lv_objx/lv_roller.c | 239 ++++++++++++++++++++++++++++++++++++++++++++ lv_objx/lv_roller.h | 74 ++++++++++++++ 4 files changed, 339 insertions(+), 2 deletions(-) create mode 100644 lv_objx/lv_roller.c create mode 100644 lv_objx/lv_roller.h diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index 600b627e0..a19ecfcbf 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -194,8 +194,8 @@ void lv_ddlist_set_options(lv_obj_t * ddlist, const char ** options) lv_label_set_text(ext->opt_label, ""); uint16_t i = 0; while(options[i][0] != '\0') { - lv_label_append_text(ext->opt_label, options[i]); - if(options[i + 1][0] != '\0') lv_label_append_text(ext->opt_label, "\n"); + lv_label_ins_text(ext->opt_label, LV_LABEL_POS_LAST, options[i]); + if(options[i + 1][0] != '\0') lv_label_ins_text(ext->opt_label, LV_LABEL_POS_LAST, "\n"); i++; } @@ -239,6 +239,8 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt) /*Move the list to show the current option*/ if(ext->opened == 0) { lv_ddlist_pos_act_option(ddlist); + } else { + lv_obj_inv(ddlist); } } @@ -286,6 +288,20 @@ void lv_ddlist_set_style_select(lv_obj_t * ddlist, lv_style_t * style) lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); ext->style_sel = style; +} + +/** + * Open or Collapse the drop down list + * @param ddlist pointer to drop down list object + * @param state true: open; false: collapse + * @param anim true: use animations; false: not use animations + */ +void lv_ddlist_open(lv_obj_t * ddlist, bool state, bool anim) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); + ext->opened = state ? 1 : 0; + lv_ddlist_refr_size(ddlist, anim ? ext->anim_time : 0); + } /*===================== * Getter functions diff --git a/lv_objx/lv_ddlist.h b/lv_objx/lv_ddlist.h index 3c9db2923..18ec4930d 100644 --- a/lv_objx/lv_ddlist.h +++ b/lv_objx/lv_ddlist.h @@ -113,6 +113,14 @@ void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size); */ void lv_ddlist_set_style_select(lv_obj_t * ddlist, lv_style_t * style); +/** + * Open or Collapse the drop down list + * @param ddlist pointer to drop down list object + * @param state true: open; false: collapse + * @param anim true: use animations; false: not use animations + */ +void lv_ddlist_open(lv_obj_t * ddlist, bool state, bool anim); + /** * Get the options of a drop down list * @param ddlist pointer to drop down list object diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c new file mode 100644 index 000000000..57fb9585d --- /dev/null +++ b/lv_objx/lv_roller.c @@ -0,0 +1,239 @@ +/** + * @file lv_roller.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_ROLLER != 0 + +#include "lv_roller.h" +#include "../lv_draw/lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_mode_t mode); +bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_f_t ancestor_scr_signal_f; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/*----------------- + * Create function + *-----------------*/ + +/** + * Create a roller object + * @param par pointer to an object, it will be the parent of the new roller + * @param copy pointer to a roller object, if not NULL then the new object will be copied from it + * @return pointer to the created roller + */ +lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy) +{ + /*Create the ancestor of roller*/ + /*TODO modify it to the ancestor create function */ + lv_obj_t * new_roller = lv_ddlist_create(par, copy); + dm_assert(new_roller); + + /*Allocate the roller type specific extended data*/ + lv_roller_ext_t * ext = lv_obj_alloc_ext(new_roller, sizeof(lv_roller_ext_t)); + dm_assert(ext); + + /*Initialize the allocated 'ext' */ + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_f(new_roller, lv_roller_signal); + lv_obj_set_design_f(new_roller, lv_roller_design); + + if(ancestor_scr_signal_f == NULL) ancestor_scr_signal_f = lv_obj_get_signal_f(lv_page_get_scrl(new_roller)); + + /*Init the new roller roller*/ + if(copy == NULL) { + lv_obj_t * scrl = lv_page_get_scrl(new_roller); + lv_obj_set_drag(scrl, true); + lv_page_set_rel_action(new_roller, NULL); + lv_obj_set_signal_f(scrl, roller_scrl_signal); + // lv_ddlist_open(new_roller, true, false); + lv_obj_set_style(new_roller, lv_style_get(LV_STYLE_PRETTY, NULL)); + lv_cont_set_fit(lv_page_get_scrl(new_roller), true, false); + lv_ddlist_set_options_str(new_roller, "alma\nkorte\ncitrom\nbanan\neper\ndinnye"); + + lv_style_t * style_label = lv_obj_get_style(ext->ddlist.opt_label); + lv_obj_set_height(new_roller, (font_get_height(style_label->font) >> FONT_ANTIALIAS) * 3 + style_label->line_space * 4); + + lv_obj_set_height(lv_page_get_scrl(new_roller), lv_obj_get_height(ext->ddlist.opt_label) + lv_obj_get_height(new_roller)); + lv_obj_align(ext->ddlist.opt_label, NULL, LV_ALIGN_CENTER, 0, 0); + + } + /*Copy an existing roller*/ + else { + lv_roller_ext_t * copy_ext = lv_obj_get_ext(copy); + + /*Refresh the style with new signal function*/ + lv_obj_refr_style(new_roller); + } + + return new_roller; +} + +/** + * Signal function of the roller + * @param roller pointer to a roller object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +bool lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + /* TODO update it to the ancestor's signal function*/ + valid = lv_ddlist_signal(roller, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } + } + + return valid; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/* + * New object specific "add" or "remove" functions come here + */ + + +/*===================== + * Setter functions + *====================*/ + +/* + * New object specific "set" functions come here + */ + + +/*===================== + * Getter functions + *====================*/ + +/* + * New object specific "get" functions come here + */ + +/*===================== + * Other functions + *====================*/ + +/* + * New object specific "other" functions come here + */ + +/********************** + * STATIC FUNCTIONS + **********************/ + + +/** + * Handle the drawing related tasks of the rollers + * @param roller 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_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + + + lv_style_t * style = lv_obj_get_style(roller); + lv_draw_rect(&roller->cords, mask, style); + + const font_t * font = style->font; + lv_roller_ext_t * ext = lv_obj_get_ext(roller); + cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; + area_t rect_area; + rect_area.y1 = lv_obj_get_height(roller) / 2 - font_h / 2 - style->line_space - 2; + + rect_area.y2 = rect_area.y1 + font_h + style->line_space; + rect_area.x1 = ext->ddlist.opt_label->cords.x1 - style->hpad; + rect_area.x2 = rect_area.x1 + lv_obj_get_width(lv_page_get_scrl(roller)); + + lv_draw_rect(&rect_area, mask, ext->ddlist.style_sel); + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + + +bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + valid = ancestor_scr_signal_f(roller_scrl, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + if(sign == LV_SIGNAL_RELEASED) { + lv_obj_t * roller = lv_obj_get_parent(roller_scrl); + lv_roller_ext_t * ext = lv_obj_get_ext(roller); + lv_style_t * style_label = lv_obj_get_style(ext->ddlist.opt_label); + + cord_t label_y1 = ext->ddlist.opt_label->cords.y1; + cord_t label_unit = (font_get_height(style_label->font) >> FONT_ANTIALIAS) + style_label->line_space / 2; + cord_t mid = (roller->cords.y2 - roller->cords.y1) / 2; + + int32_t id = (mid - label_y1) / label_unit; + + printf("roller diff: %d , unit: %d, id: %d\n", mid-label_y1, label_unit, id); + } + } + + return valid; +} + + + +#endif diff --git a/lv_objx/lv_roller.h b/lv_objx/lv_roller.h new file mode 100644 index 000000000..4a95cdf3e --- /dev/null +++ b/lv_objx/lv_roller.h @@ -0,0 +1,74 @@ +/** + * @file lv_roller.h + * + */ + + +/*Search an replace: roller -> object normal name with lower case (e.g. button, label etc.) + * roller -> object short name with lower case(e.g. btn, label etc) + * ROLLER -> object short name with upper case (e.g. BTN, LABEL etc.) + * + */ + +#ifndef LV_ROLLER_H +#define LV_ROLLER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_ROLLER != 0 + +#include "../lv_obj/lv_obj.h" +#include "lv_ddlist.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of roller*/ +typedef struct { + lv_ddlist_ext_t ddlist; /*Ext. of ancestor*/ + /*New data for this type */ +}lv_roller_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a roller objects + * @param par pointer to an object, it will be the parent of the new roller + * @param copy pointer to a roller object, if not NULL then the new object will be copied from it + * @return pointer to the created roller + */ +lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy); + +/** + * Signal function of the roller + * @param roller pointer to a roller object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +bool lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param); + + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_ROLLER*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_ROLLER_H*/ From 024d776d2c66ecddce08aff1bc0c955f35c986d9 Mon Sep 17 00:00:00 2001 From: Gabor Date: Sun, 3 Sep 2017 16:02:37 +0200 Subject: [PATCH 06/19] lv_btnm.h add missing semi colon --- lv_objx/lv_btnm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lv_objx/lv_btnm.h b/lv_objx/lv_btnm.h index 1a356f2ef..652a437c3 100644 --- a/lv_objx/lv_btnm.h +++ b/lv_objx/lv_btnm.h @@ -112,7 +112,7 @@ void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id); * @param ina pointer to a style for inactive state */ void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr, - lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina) + lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina); /** * Get the current map of a button matrix From 45b8364b0e7b3dfd99857a51d5410872f860cb3f Mon Sep 17 00:00:00 2001 From: Gabor Date: Mon, 11 Sep 2017 12:43:14 +0200 Subject: [PATCH 07/19] lv_roller: lv_ddlist_set_selected() updated to work with roller too --- lv_objx/lv_ddlist.c | 8 +++++--- lv_objx/lv_roller.c | 6 ++---- lv_objx/lv_roller.h | 7 ------- lvgl.h | 1 + 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index a19ecfcbf..b05d17038 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -234,7 +234,7 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt) { lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); - ext->sel_opt = sel_opt; + ext->sel_opt = sel_opt < ext->num_opt ? sel_opt : ext->num_opt - 1; /*Move the list to show the current option*/ if(ext->opened == 0) { @@ -540,9 +540,11 @@ static void lv_ddlist_pos_act_option(lv_obj_t * ddlist) cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; lv_style_t * label_style = lv_obj_get_style(ext->opt_label); lv_obj_t * scrl = lv_page_get_scrl(ddlist); - lv_style_t * style_scrl = lv_obj_get_style(scrl); - lv_obj_set_y(scrl, -(ext->sel_opt * (font_h + label_style->line_space) - label_style->line_space) - style_scrl->hpad); + cord_t h = lv_obj_get_height(ddlist); + cord_t line_y1 = ext->sel_opt * (font_h + label_style->line_space) + ext->opt_label->cords.y1 - scrl->cords.y1; + + lv_obj_set_y(scrl, - line_y1 + (h - font_h) / 2); } diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index 57fb9585d..e25a8c3ef 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -180,8 +180,6 @@ static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_m } /*Draw the object*/ else if(mode == LV_DESIGN_DRAW_MAIN) { - - lv_style_t * style = lv_obj_get_style(roller); lv_draw_rect(&roller->cords, mask, style); @@ -189,7 +187,7 @@ static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_m lv_roller_ext_t * ext = lv_obj_get_ext(roller); cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; area_t rect_area; - rect_area.y1 = lv_obj_get_height(roller) / 2 - font_h / 2 - style->line_space - 2; + rect_area.y1 = roller->cords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->line_space - 2; rect_area.y2 = rect_area.y1 + font_h + style->line_space; rect_area.x1 = ext->ddlist.opt_label->cords.x1 - style->hpad; @@ -221,7 +219,7 @@ bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) lv_roller_ext_t * ext = lv_obj_get_ext(roller); lv_style_t * style_label = lv_obj_get_style(ext->ddlist.opt_label); - cord_t label_y1 = ext->ddlist.opt_label->cords.y1; + cord_t label_y1 = ext->ddlist.page.scrl->cords.y1 - roller->cords.y1; cord_t label_unit = (font_get_height(style_label->font) >> FONT_ANTIALIAS) + style_label->line_space / 2; cord_t mid = (roller->cords.y2 - roller->cords.y1) / 2; diff --git a/lv_objx/lv_roller.h b/lv_objx/lv_roller.h index 4a95cdf3e..873254763 100644 --- a/lv_objx/lv_roller.h +++ b/lv_objx/lv_roller.h @@ -3,13 +3,6 @@ * */ - -/*Search an replace: roller -> object normal name with lower case (e.g. button, label etc.) - * roller -> object short name with lower case(e.g. btn, label etc) - * ROLLER -> object short name with upper case (e.g. BTN, LABEL etc.) - * - */ - #ifndef LV_ROLLER_H #define LV_ROLLER_H diff --git a/lvgl.h b/lvgl.h index 3cdee0c7e..ef7144498 100644 --- a/lvgl.h +++ b/lvgl.h @@ -33,6 +33,7 @@ extern "C" { #include "lv_objx/lv_btnm.h" #include "lv_objx/lv_kb.h" #include "lv_objx/lv_ddlist.h" +#include "lv_objx/lv_roller.h" #include "lv_objx/lv_ta.h" #include "lv_objx/lv_win.h" #include "lv_objx/lv_tabview.h" From 569edb76857c458636b7d23e1b80c3b13ba53bf3 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 22 Sep 2017 09:52:53 +0200 Subject: [PATCH 08/19] utf-8: lv_label full support, lv_ta in pwd_mode still not working --- lv_draw/lv_draw.c | 20 +++++----- lv_draw/lv_draw_vbasic.c | 2 +- lv_draw/lv_draw_vbasic.h | 2 +- lv_objx/lv_label.c | 63 +++++++---------------------- lv_objx/lv_label.h | 5 ++- lv_objx/lv_list.c | 19 --------- lv_objx/lv_list.h | 7 ---- lv_objx/lv_ta.c | 85 ++++++++++++++++++++++++++++------------ 8 files changed, 91 insertions(+), 112 deletions(-) diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index b8f02483d..6e027d2c0 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -64,14 +64,14 @@ static void point_swap(point_t * p1, point_t * p2); #if LV_VDB_SIZE != 0 static void (*px_fp)(cord_t x, cord_t y, const area_t * mask_p, color_t color, opa_t opa) = lv_vpx; static void (*fill_fp)(const area_t * cords_p, const area_t * mask_p, color_t color, opa_t opa) = lv_vfill; -static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint8_t letter, color_t color, opa_t opa) = lv_vletter; +static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint32_t letter, color_t color, opa_t opa) = lv_vletter; #if USE_FSINT != 0 static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, bool upscale, color_t recolor, opa_t recolor_opa) = lv_vmap; #endif #else static void (*px_fp)(cord_t x, cord_t y, const area_t * mask_p, color_t color, opa_t opa) = lv_rpx; static void (*fill_fp)(const area_t * cords_p, const area_t * mask_p, color_t color, opa_t opa) = lv_rfill; -static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint8_t letter, color_t color, opa_t opa) = lv_rletter; +static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint32_t letter, color_t color, opa_t opa) = lv_rletter; #if USE_LV_IMG != 0 && USE_FSINT != 0 static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, bool upscale, color_t recolor, opa_t recolor_opa) = lv_rmap; #endif @@ -280,13 +280,15 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_ } /*Write all letter of a line*/ cmd_state = CMD_STATE_WAIT; - - for(i = line_start; i < line_end; i++) { + i = line_start; + uint32_t letter; + while(i < line_end) { + letter = txt_utf8_next(txt, &i); /*Handle the re-color command*/ if((flag & TXT_FLAG_RECOLOR) != 0) { - if(txt[i] == TXT_RECOLOR_CMD) { + if(letter == TXT_RECOLOR_CMD) { if(cmd_state == CMD_STATE_WAIT) { /*Start char*/ - par_start = i + 1; + par_start = i + txt_utf8_size(&txt[i]); cmd_state = CMD_STATE_PAR; continue; } else if(cmd_state == CMD_STATE_PAR) { /*Other start char in parameter escaped cmd. char */ @@ -299,7 +301,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_ /*Skip the color parameter and wait the space after it*/ if(cmd_state == CMD_STATE_PAR) { - if(txt[i] == ' ') { + if(letter == ' ') { /*Get the parameter*/ if(i - par_start == LABEL_RECOLOR_PAR_LENGTH) { char buf[LABEL_RECOLOR_PAR_LENGTH + 1]; @@ -320,9 +322,9 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_ color_t color = style->ccolor; if(cmd_state == CMD_STATE_IN) color = recolor; - letter_fp(&pos, mask_p, font, txt[i], color, style->opa); + letter_fp(&pos, mask_p, font, letter, color, style->opa); - pos.x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space; + pos.x += (font_get_width(font, letter) >> FONT_ANTIALIAS) + style->letter_space; } /*Go to next line*/ diff --git a/lv_draw/lv_draw_vbasic.c b/lv_draw/lv_draw_vbasic.c index d3f543c6e..90fd052f6 100644 --- a/lv_draw/lv_draw_vbasic.c +++ b/lv_draw/lv_draw_vbasic.c @@ -148,7 +148,7 @@ void lv_vfill(const area_t * cords_p, const area_t * mask_p, * @param opa opacity of letter (0..255) */ void lv_vletter(const point_t * pos_p, const area_t * mask_p, - const font_t * font_p, uint8_t letter, + const font_t * font_p, uint32_t letter, color_t color, opa_t opa) { if(font_p == NULL) return; diff --git a/lv_draw/lv_draw_vbasic.h b/lv_draw/lv_draw_vbasic.h index c347d18be..4e39117f5 100644 --- a/lv_draw/lv_draw_vbasic.h +++ b/lv_draw/lv_draw_vbasic.h @@ -54,7 +54,7 @@ void lv_vfill(const area_t * cords_p, const area_t * mask_p, * @param opa opacity of letter (0..255) */ void lv_vletter(const point_t * pos_p, const area_t * mask_p, - const font_t * font_p, uint8_t letter, + const font_t * font_p, uint32_t letter, color_t color, opa_t opa); /** diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 03b898f80..c68c5eb73 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -271,15 +271,6 @@ void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode) { lv_label_ext_t * ext = lv_obj_get_ext(label); - /*When changing from dot mode reload the characters replaced by dots*/ - if(ext->long_mode == LV_LABEL_LONG_DOTS && - ext->dot_end != LV_LABEL_DOT_END_INV) { - uint8_t i; - for(i = 0; i < LV_LABEL_DOT_NUM + 1; i++) { - ext->txt[ext->dot_end - LV_LABEL_DOT_NUM + i] = ext->dot_tmp[i]; - } - } - /*Delete the old animation (if exists)*/ anim_del(label, (anim_fp_t) lv_obj_set_x); anim_del(label, (anim_fp_t) lv_obj_set_y); @@ -397,6 +388,7 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) line_start = new_line_start; } + /*If the last character is lie break then go to the next line*/ if((txt[index - 1] == '\n' || txt[index - 1] == '\r') && txt[index] == '\0') { y += letter_height + style->line_space; line_start = index; @@ -404,16 +396,20 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) /*Calculate the x coordinate*/ cord_t x = 0; - uint32_t i; + uint32_t i = line_start; + uint32_t cnt = line_start; /*Count the letter (in UTF-8 1 letter not 1 byte)*/ txt_cmd_state_t cmd_state = TXT_CMD_STATE_WAIT; - for(i = line_start; i < index; i++) { + uint32_t letter; + while(cnt < index) { + letter = txt_utf8_next(txt, &i); + cnt++; /*Handle the recolor command*/ if((flag & TXT_FLAG_RECOLOR) != 0) { if(txt_is_cmd(&cmd_state, txt[i]) != false) { continue; /*Skip the letter is it is part of a command*/ } } - x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space; + x += (font_get_width(font, letter) >> FONT_ANTIALIAS) + style->letter_space; } if(style->txt_align == LV_TXT_ALIGN_MID) { @@ -474,8 +470,10 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos) } txt_cmd_state_t cmd_state = TXT_CMD_STATE_WAIT; - uint16_t i; - for(i = line_start; i < new_line_start - 1; i++) { + uint32_t i = line_start; + uint32_t letter; + while(i < new_line_start - 1) { + letter = txt_utf8_next(txt, &i); /*Handle the recolor command*/ if((flag & TXT_FLAG_RECOLOR) != 0) { if(txt_is_cmd(&cmd_state, txt[i]) != false) { @@ -483,8 +481,8 @@ 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; + x += (font_get_width(font, letter) >> FONT_ANTIALIAS) + style->letter_space; + if(pos->x < x) break; /*Get the position*/ } return i; @@ -660,40 +658,7 @@ static void lv_label_refr_text(lv_obj_t * label) else if (ext->long_mode == LV_LABEL_LONG_BREAK) { lv_obj_set_height(label, size.y); } - /*Replace the last 'LV_LABEL_DOT_NUM' characters with dots - * and save these characters*/ - else if(ext->long_mode == LV_LABEL_LONG_DOTS) { - point_t point; - point.x = lv_obj_get_width(label) - 1; - point.y = lv_obj_get_height(label) - 1; - uint16_t index = lv_label_get_letter_on(label, &point); - if(index < strlen(ext->txt) - 1) { - - /* Change the last 'LV_LABEL_DOT_NUM' to dots - * (if there are at least 'LV_LABEL_DOT_NUM' characters*/ - if(index > LV_LABEL_DOT_NUM) { - uint8_t i; - for(i = 0; i < LV_LABEL_DOT_NUM; i++) { - ext->dot_tmp[i] = ext->txt[index - LV_LABEL_DOT_NUM + i]; - ext->txt[index - LV_LABEL_DOT_NUM + i] = '.'; - } - /*The last character is '\0'. Save this character from the text too.*/ - ext->dot_tmp[i] = ext->txt[index]; - ext->txt[index] = '\0'; - } - /*Else with short text change all characters to dots*/ - else { - uint8_t i; - for(i = 0; i < LV_LABEL_DOT_NUM; i++) { - ext->txt[i] = '.'; - } - ext->txt[i] = '\0'; - } - /*Save the dot end index*/ - ext->dot_end = index; - } - } lv_obj_inv(label); } diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index f5e84758d..516eb2687 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -34,7 +34,6 @@ typedef enum { LV_LABEL_LONG_EXPAND, /*Expand the object size to the text size*/ LV_LABEL_LONG_BREAK, /*Keep the object width, break the too long lines and expand the object height*/ - LV_LABEL_LONG_DOTS, /*Keep the object size, break the text and write dots in the last line*/ LV_LABEL_LONG_SCROLL, /*Expand the object size and scroll the text on the parent (move the label object)*/ LV_LABEL_LONG_ROLL, /*Keep the size and roll the text infinitely*/ }lv_label_long_mode_t; @@ -46,7 +45,11 @@ typedef struct /*New data for this type */ char * txt; /*Text of the label*/ lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/ +#if TXT_UTF8 == 0 char dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/ +#else + uint32_t dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/ +#endif 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*/ diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index efcbe4fd6..644f8219c 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -349,25 +349,6 @@ void lv_list_set_sb_out(lv_obj_t * list, bool out) ext->sb_out = out == false ? 0 : 1; } -/** - * Enable or disable the text rolling on a list element - * @param liste pinter to list element - * @param en true: enable text scrolling, false: disable text scrolling - */ -void lv_list_set_element_text_roll(lv_obj_t * liste, bool en) -{ - lv_obj_t * label = lv_list_get_element_label(liste); - if(label == NULL) return; - - if(en == false) { - lv_label_set_long_mode(label, LV_LABEL_LONG_DOTS); - } else { - lv_obj_set_width(label, liste->cords.x2 - label->cords.x1); - lv_label_set_long_mode(label, LV_LABEL_LONG_ROLL); - } - -} - /** * Set styles of the list elements of a list in each state diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index 9ef8f8809..08255843f 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -103,13 +103,6 @@ void lv_list_down(lv_obj_t * list); */ void lv_list_set_sb_out(lv_obj_t * list, bool out); -/** - * Enable or disable the text rolling on a list element - * @param liste pinter to list element - * @param en true: enable text scrolling, false: disable text scrolling - */ -void lv_list_set_element_text_roll(lv_obj_t * liste, bool en); - /** * Set styles of the list elements of a list in each state * @param list pointer to list object diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index ac865234b..15131dc90 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -14,6 +14,7 @@ #include "../lv_obj/lv_group.h" #include "../lv_draw/lv_draw.h" #include "misc/gfx/anim.h" +#include "misc/gfx/text.h" /********************* * DEFINES @@ -103,7 +104,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy) lv_obj_set_design_f(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, NULL)); @@ -221,22 +222,32 @@ void lv_ta_add_char(lv_obj_t * ta, char c) if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/ - char buf[LV_TA_MAX_LENGTH]; + uint32_t cur_pos; +#if TXT_UTF8 == 0 + cur_pos = ext->cursor_pos; +#else + cur_pos = txt_utf8_get_id(label_txt, ext->cursor_pos); +#endif + + char buf[LV_TA_MAX_LENGTH]; /*Insert the character*/ - memcpy(buf, label_txt, ext->cursor_pos); - buf[ext->cursor_pos] = c; - memcpy(buf+ext->cursor_pos+1, label_txt+ext->cursor_pos, strlen(label_txt) - ext->cursor_pos + 1); + memcpy(buf, label_txt, cur_pos); + buf[cur_pos] = c; + memcpy(buf + cur_pos + 1, label_txt + cur_pos, strlen(label_txt) - cur_pos + 1); /*Refresh the label*/ lv_label_set_text(ext->label, buf); if(ext->pwd_mode != 0) { +#if TXT_UTF8 != 0 + cur_pos = txt_utf8_get_id(ext->pwd_tmp, ext->cursor_pos); /*Noral text contains '*', pwd_tmp normal UTF-8 letter, so the cursor points to a different byte*/ +#endif ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 2); /*+2: the new char + \0 */ dm_assert(ext->pwd_tmp); - memcpy(buf, ext->pwd_tmp, ext->cursor_pos); - buf[ext->cursor_pos] = c; - memcpy(buf + ext->cursor_pos + 1, ext->pwd_tmp + ext->cursor_pos, strlen(ext->pwd_tmp) - ext->cursor_pos + 1); + memcpy(buf, ext->pwd_tmp, cur_pos); + buf[cur_pos] = c; + memcpy(buf + cur_pos + 1, ext->pwd_tmp + cur_pos, strlen(ext->pwd_tmp) - cur_pos + 1); strcpy(ext->pwd_tmp, buf); anim_t a; @@ -283,12 +294,18 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt) /*Insert the text*/ char buf[LV_TA_MAX_LENGTH]; - memcpy(buf, label_txt, ext->cursor_pos); - memcpy(buf + ext->cursor_pos, txt, txt_len); - memcpy(buf + ext->cursor_pos + txt_len, label_txt+ext->cursor_pos, label_len - ext->cursor_pos + 1); + uint32_t cur_pos; +#if TXT_UTF8 == 0 + cur_pos = ext->cursor_pos; +#else + cur_pos = txt_utf8_get_id(label_txt, ext->cursor_pos); +#endif + + memcpy(buf, label_txt, cur_pos); + memcpy(buf + cur_pos, txt, txt_len); + memcpy(buf + cur_pos + txt_len, label_txt+cur_pos, label_len - cur_pos + 1); /*Refresh the label*/ - lv_label_set_text(ext->label, buf); @@ -296,8 +313,8 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt) ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + txt_len + 1); dm_assert(ext->pwd_tmp); memcpy(buf, ext->pwd_tmp, ext->cursor_pos); - memcpy(buf + ext->cursor_pos, txt, txt_len); - memcpy(buf + ext->cursor_pos + txt_len, ext->pwd_tmp+ext->cursor_pos, label_len - ext->cursor_pos + 1); + memcpy(buf + cur_pos, txt, txt_len); + memcpy(buf + cur_pos + txt_len, ext->pwd_tmp+ext->cursor_pos, label_len - ext->cursor_pos + 1); strcpy(ext->pwd_tmp, buf); anim_t a; @@ -416,11 +433,11 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos) lv_ta_ext_t * ext = lv_obj_get_ext(ta); lv_obj_t * scrl = lv_page_get_scrl(ta); lv_style_t * style_scrl = lv_obj_get_style(scrl); - uint16_t txt_len = strlen(lv_label_get_text(ext->label)); + uint16_t len = txt_len(lv_label_get_text(ext->label)); - if(pos < 0) pos = txt_len + pos; + if(pos < 0) pos = len + pos; - if(pos > txt_len || pos == LV_TA_CUR_LAST) pos = txt_len; + if(pos > len || pos == LV_TA_CUR_LAST) pos = len; ext->cursor_pos = pos; @@ -457,6 +474,7 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos) font_h + 2 * style_scrl->hpad)); } + /*Reset cursor blink animation*/ anim_t a; a.var = ta; a.fp = (anim_fp_t)cursor_blink_anim; @@ -607,14 +625,15 @@ void lv_ta_set_pwd_mode(lv_obj_t * ta, bool en) /*Pwd mode is now enabled*/ if(ext->pwd_mode == 0 && en != false) { char * txt = lv_label_get_text(ext->label); - uint16_t txt_len = strlen(txt); - ext->pwd_tmp = dm_alloc(txt_len + 1); + uint16_t len = strlen(txt); + ext->pwd_tmp = dm_alloc(len + 1); strcpy(ext->pwd_tmp, txt); uint16_t i; - for(i = 0; i < txt_len; i++) { + for(i = 0; i < len; i++) { txt[i] = '*'; /*All char to '*'*/ } + txt[i] = '\0'; lv_label_set_text(ext->label, NULL); } @@ -828,7 +847,17 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des uint16_t cur_pos = lv_ta_get_cursor_pos(ta); const char * txt = lv_label_get_text(ta_ext->label); - cord_t letter_w = font_get_width(label_style->font, txt[cur_pos] != '\0' ? txt[cur_pos] : ' '); + + uint32_t byte_pos; +#if TXT_UTF8 != 0 + byte_pos = txt_utf8_get_id(txt, cur_pos); +#else + byte_pos = cur_pos; +#endif + + uint32_t letter = txt_utf8_next(&txt[byte_pos], NULL); + printf("letter %d\n", letter); + cord_t letter_w = font_get_width(label_style->font, letter != '\0' ? letter : ' '); cord_t letter_h = font_get_height(label_style->font) >> FONT_ANTIALIAS; point_t letter_pos; lv_label_get_letter_pos(ta_ext->label, cur_pos, &letter_pos); @@ -847,9 +876,15 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + letter_h; lv_draw_rect(&cur_area, mask, &cur_style); + /*Get the current letter*/ +#if TXT_UTF8 == 0 char letter_buf[2]; - letter_buf[0] = txt[cur_pos]; - letter_buf[1] = '\0'; + letter_buf[0] = txt[byte_pos]; + letter_buf[1] = '\0'; +#else + char letter_buf[8] = {0}; + memcpy(letter_buf, &txt[byte_pos], txt_utf8_size(txt[byte_pos])); +#endif lv_draw_label(&cur_area, mask, &cur_style, letter_buf, TXT_FLAG_NONE, 0); } else if(ta_ext->cursor_type == LV_TA_CURSOR_OUTLINE) { @@ -911,10 +946,10 @@ static void pwd_char_hider(lv_obj_t * ta) lv_ta_ext_t * ext = lv_obj_get_ext(ta); if(ext->pwd_mode != 0) { char * txt = lv_label_get_text(ext->label); - int16_t txt_len = strlen(txt); + int16_t len = txt_len(txt); bool refr = false; uint16_t i; - for(i = 0; i < txt_len; i++) { + for(i = 0; i < len; i++) { if(txt[i] != '*') { txt[i] = '*'; refr = true; From 1bbe6e10684e23274fa30721d618b25e3dac391d Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 22 Sep 2017 13:58:01 +0200 Subject: [PATCH 09/19] lv_ta: full UTF-8 support --- lv_objx/lv_label.c | 49 ++++++++++--------- lv_objx/lv_label.h | 2 +- lv_objx/lv_ta.c | 114 ++++++++++++++++++--------------------------- lv_objx/lv_ta.h | 2 +- 4 files changed, 74 insertions(+), 93 deletions(-) diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 961476bd4..ba26fcef1 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -10,6 +10,7 @@ #if USE_LV_LABEL != 0 #include "misc/gfx/color.h" +#include "misc/gfx/text.h" #include "misc/math/math_base.h" #include "lv_label.h" #include "../lv_obj/lv_obj.h" @@ -165,22 +166,28 @@ void lv_label_set_text(lv_obj_t * label, const char * text) lv_label_ext_t * ext = lv_obj_get_ext(label); - /*If trying to set its own text or the text is NULL then refresh */ - if(text == ext->txt || text == NULL) { + /*If text is NULL then refresh */ + if(text == NULL) { lv_label_refr_text(label); return; } - /*Allocate space for the new text*/ - uint32_t len = strlen(text) + 1; - if(ext->txt != NULL && ext->static_txt == 0) { - dm_free(ext->txt); - ext->txt = NULL; + if(ext->txt == text) { + /*If set its own text then reallocate it (maybe its size changed)*/ + ext->txt = dm_realloc(ext->txt, strlen(ext->txt) + 1); + } else { + /*Allocate space for the new text*/ + uint32_t len = strlen(text) + 1; + if(ext->txt != NULL && ext->static_txt == 0) { + dm_free(ext->txt); + ext->txt = NULL; + } + + ext->txt = dm_alloc(len); + strcpy(ext->txt, text); + ext->static_txt = 0; /*Now the text is dynamically allocated*/ } - ext->txt = dm_alloc(len); - strcpy(ext->txt, text); - ext->static_txt = 0; /*Now the text is dynamically allocated*/ - + lv_label_refr_text(label); } /** @@ -243,11 +250,9 @@ void lv_label_set_text_static(lv_obj_t * label, const char * text) * @param pos character index to insert * 0: before first char. * LV_LABEL_POS_LAST: after last char. - * < 0: count from the end - * -1: before the last char. * @param txt pointer to the text to insert */ -void lv_label_ins_text(lv_obj_t * label, int32_t pos, const char * txt) +void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt) { lv_label_ext_t * ext = lv_obj_get_ext(label); @@ -262,17 +267,15 @@ void lv_label_ins_text(lv_obj_t * label, int32_t pos, const char * txt) uint32_t new_len = ins_len + old_len; ext->txt = dm_realloc(ext->txt, new_len + 1); - if(pos == LV_LABEL_POS_LAST) pos = old_len; - else if(pos < 0) pos = old_len + pos; - - /*Copy the second part into the end to make place to text to insert*/ - int32_t i; - for(i = new_len; i >= pos + ins_len; i--){ - ext->txt[i] = ext->txt[i - ins_len]; + if(pos == LV_LABEL_POS_LAST) { +#if TXT_UTF8 == 0 + pos = old_len; +#else + pos = txt_len(ext->txt); +#endif } - /* Copy the text into the new space*/ - memcpy(ext->txt + pos, txt, ins_len); + txt_ins(ext->txt, pos, txt); lv_label_refr_text(label); } diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index 5bccfd68f..fb4fdabb0 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -113,7 +113,7 @@ void lv_label_set_text_static(lv_obj_t * label, const char * text); * -1: before the last char. * @param txt pointer to the text to insert */ -void lv_label_ins_text(lv_obj_t * label, int32_t pos, const char * txt); +void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt); /** * Set the behavior of the label with longer text then the object size diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 15131dc90..906e6dd07 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -211,44 +211,37 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) * @param ta pointer to a text area object * @param c a character */ -void lv_ta_add_char(lv_obj_t * ta, char c) +void lv_ta_add_char(lv_obj_t * ta, uint32_t c) { lv_ta_ext_t * ext = lv_obj_get_ext(ta); - const char * label_txt = lv_label_get_text(ext->label); - - /*Test the new length: txt length + 1 (closing'\0') + 1 (c character)*/ - if((strlen(label_txt) + 2) > LV_TA_MAX_LENGTH) return; - if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/ - - - uint32_t cur_pos; #if TXT_UTF8 == 0 - cur_pos = ext->cursor_pos; + char letter_buf[2]; + letter_buf[0] = c; + letter_buf[1] = '\0'; #else - cur_pos = txt_utf8_get_id(label_txt, ext->cursor_pos); + /*Swap because of UTF-8 is "big-endian-like" */ + if(((c >> 8) & 0b11100000) == 0b11000000) { + c = (c & 0xFF) << 8 | ((c >> 8) & 0xFF); + } + if(((c >> 16) & 0b11110000) == 0b11100000) { + c = (c & 0xFF) << 16 | ((c >> 16) & 0xFF); + } + if(((c >> 24) & 0b11111000) == 0b11110000) { + c = ((c & 0xFF) << 24) | (((c >> 8) & 0xFF) >> 16) | (((c >> 16) & 0xFF) >> 8) | ((c >> 24) & 0xFF); + } + + char letter_buf[8] = {0}; + memcpy(letter_buf, &c, txt_utf8_size(c)); #endif + lv_label_ins_text(ext->label, ext->cursor_pos, letter_buf); /*Insert the character*/ - char buf[LV_TA_MAX_LENGTH]; - /*Insert the character*/ - memcpy(buf, label_txt, cur_pos); - buf[cur_pos] = c; - memcpy(buf + cur_pos + 1, label_txt + cur_pos, strlen(label_txt) - cur_pos + 1); + if(ext->pwd_mode != 0) { - /*Refresh the label*/ - lv_label_set_text(ext->label, buf); - - if(ext->pwd_mode != 0) { -#if TXT_UTF8 != 0 - cur_pos = txt_utf8_get_id(ext->pwd_tmp, ext->cursor_pos); /*Noral text contains '*', pwd_tmp normal UTF-8 letter, so the cursor points to a different byte*/ -#endif - ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 2); /*+2: the new char + \0 */ - dm_assert(ext->pwd_tmp); - memcpy(buf, ext->pwd_tmp, cur_pos); - buf[cur_pos] = c; - memcpy(buf + cur_pos + 1, ext->pwd_tmp + cur_pos, strlen(ext->pwd_tmp) - cur_pos + 1); - strcpy(ext->pwd_tmp, buf); + ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 2); /*+2: the new char + \0 */ + dm_assert(ext->pwd_tmp); + txt_ins(ext->pwd_tmp, ext->cursor_pos, letter_buf); anim_t a; a.var = ta; @@ -284,38 +277,19 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt) lv_ta_ext_t * ext = lv_obj_get_ext(ta); const char * label_txt = lv_label_get_text(ext->label); - uint16_t label_len = strlen(label_txt); uint16_t txt_len = strlen(txt); - /*Test the new length (+ 1 for the closing '\0')*/ - if((label_len + txt_len + 1) > LV_TA_MAX_LENGTH) return; - if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/ /*Insert the text*/ - char buf[LV_TA_MAX_LENGTH]; - uint32_t cur_pos; -#if TXT_UTF8 == 0 - cur_pos = ext->cursor_pos; -#else - cur_pos = txt_utf8_get_id(label_txt, ext->cursor_pos); -#endif - - memcpy(buf, label_txt, cur_pos); - memcpy(buf + cur_pos, txt, txt_len); - memcpy(buf + cur_pos + txt_len, label_txt+cur_pos, label_len - cur_pos + 1); - - /*Refresh the label*/ - lv_label_set_text(ext->label, buf); + lv_label_ins_text(ext->label, ext->cursor_pos, txt); if(ext->pwd_mode != 0) { ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + txt_len + 1); dm_assert(ext->pwd_tmp); - memcpy(buf, ext->pwd_tmp, ext->cursor_pos); - memcpy(buf + cur_pos, txt, txt_len); - memcpy(buf + cur_pos + txt_len, ext->pwd_tmp+ext->cursor_pos, label_len - ext->cursor_pos + 1); - strcpy(ext->pwd_tmp, buf); + + txt_ins(ext->pwd_tmp, ext->cursor_pos, txt); anim_t a; a.var = ta; @@ -392,15 +366,17 @@ void lv_ta_del(lv_obj_t * ta) if(cur_pos == 0) return; + char * label_txt = lv_label_get_text(ext->label); /*Delete a character*/ - char buf[LV_TA_MAX_LENGTH]; - const char * label_txt = lv_label_get_text(ext->label); - uint16_t label_len = strlen(label_txt); - memcpy(buf, label_txt, cur_pos - 1); - memcpy(buf+cur_pos - 1, label_txt + cur_pos, label_len - cur_pos + 1); - +#if TXT_UTF8 == 0 + txt_cut(label_txt, ext->cursor_pos - 1, 1); +#else + uint32_t byte_pos = txt_utf8_get_id(label_txt, ext->cursor_pos - 1); + txt_cut(label_txt, ext->cursor_pos - 1, txt_utf8_size(label_txt[byte_pos])); +#endif /*Refresh the label*/ - lv_label_set_text(ext->label, buf); + lv_label_set_text(ext->label, label_txt); + /*Don't let 'width == 0' because cursor will not be visible*/ if(lv_obj_get_width(ext->label) == 0) { lv_style_t * style = lv_obj_get_style(ext->label); @@ -408,13 +384,18 @@ void lv_ta_del(lv_obj_t * ta) } if(ext->pwd_mode != 0) { - ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(buf)); +#if TXT_UTF8 == 0 + txt_cut(ext->pwd_tmp, ext->cursor_pos - 1, 1); +#else + uint32_t byte_pos = txt_utf8_get_id(ext->pwd_tmp, ext->cursor_pos - 1); + txt_cut(ext->pwd_tmp, ext->cursor_pos - 1, txt_utf8_size(label_txt[byte_pos])); +#endif + ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 1); dm_assert(ext->pwd_tmp); - strcpy(ext->pwd_tmp, buf); } /*Move the cursor to the place of the deleted character*/ - lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) - 1); + lv_ta_set_cursor_pos(ta, ext->cursor_pos - 1); /*It is a valid x step so save it*/ lv_ta_save_valid_cursor_x(ta); @@ -949,14 +930,11 @@ static void pwd_char_hider(lv_obj_t * ta) int16_t len = txt_len(txt); bool refr = false; uint16_t i; - for(i = 0; i < len; i++) { - if(txt[i] != '*') { - txt[i] = '*'; - refr = true; - } - } + for(i = 0; i < len; i++) txt[i] = '*'; - if(refr != false) lv_label_set_text(ext->label, NULL); + txt[i] = '\0'; + + if(refr != false) lv_label_set_text(ext->label, txt); } } diff --git a/lv_objx/lv_ta.h b/lv_objx/lv_ta.h index 3eb7a3ce6..4105d6d05 100644 --- a/lv_objx/lv_ta.h +++ b/lv_objx/lv_ta.h @@ -87,7 +87,7 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param); * @param ta pointer to a text area object * @param c a character */ -void lv_ta_add_char(lv_obj_t * ta, char c); +void lv_ta_add_char(lv_obj_t * ta, uint32_t c); /** * Insert a text to the current cursor position From d950ae0ee41ab4caf61dcd5a1ffe9dc3d04d34b0 Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Fri, 22 Sep 2017 23:54:31 +0200 Subject: [PATCH 10/19] lv_obj_set_style refresh NULL styles behind glass styles --- lv_obj/lv_obj.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index 0b9bf896b..8f4e682f1 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -1526,13 +1526,14 @@ static void lv_child_refr_style(lv_obj_t * obj) lv_obj_t * child = lv_obj_get_child(obj, NULL); 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*/ + } else if(child->style_p->glass) { + /*Children with 'glass' parent might be effected if their style == NULL*/ lv_child_refr_style(child); } - child = lv_obj_get_child(obj, child); + child = lv_obj_get_child(child, NULL); } - - /*Send a style change signal to the object*/ - lv_obj_refr_style(obj); } /** From 4935b885881de2cfaf0481823bf394abfc6fe37b Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Fri, 22 Sep 2017 23:55:03 +0200 Subject: [PATCH 11/19] lv_objx_templ: minor update in comments --- lv_objx/lv_objx_templ.c | 7 ++++--- lv_objx/lv_objx_templ.h | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lv_objx/lv_objx_templ.c b/lv_objx/lv_objx_templ.c index 71ad75fd1..36c2a5667 100644 --- a/lv_objx/lv_objx_templ.c +++ b/lv_objx/lv_objx_templ.c @@ -3,9 +3,10 @@ * */ -/*Search an replace: template -> object normal name with lower case (e.g. button, label etc.) - * templ -> object short name with lower case(e.g. btn, label etc) - * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) +/* TODO Remove these instructions + * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) + * templ -> object short name with lower case(e.g. btn, label etc) + * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) * */ diff --git a/lv_objx/lv_objx_templ.h b/lv_objx/lv_objx_templ.h index 63cd55447..174dc4fcb 100644 --- a/lv_objx/lv_objx_templ.h +++ b/lv_objx/lv_objx_templ.h @@ -4,9 +4,10 @@ */ -/*Search an replace: template -> object normal name with lower case (e.g. button, label etc.) - * templ -> object short name with lower case(e.g. btn, label etc) - * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) +/* TODO Remove these instructions + * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) + * templ -> object short name with lower case(e.g. btn, label etc) + * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) * */ From 280e039e1960c1fd3e1f9444f66ff00d8c58f0ca Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Fri, 22 Sep 2017 23:55:42 +0200 Subject: [PATCH 12/19] lv_ddlist: change auto_size to fix_height --- lv_objx/lv_ddlist.c | 39 +++++++++++++++++---------------------- lv_objx/lv_ddlist.h | 17 +++++++++-------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index b05d17038..a34eab7e4 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -69,7 +69,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) ext->opt_label = NULL; ext->cb = NULL; ext->opened = 0; - ext->auto_size = 0; + ext->fix_height = 0; ext->sel_opt = 0; ext->num_opt = 0; ext->anim_time = LV_DDLIST_DEF_ANIM_TIME; @@ -85,7 +85,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) if(copy == NULL) { lv_obj_t * scrl = lv_page_get_scrl(new_ddlist); lv_obj_set_drag(scrl, false); - lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL));; + lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL)); lv_cont_set_fit(scrl, true, true); ext->opt_label = lv_label_create(new_ddlist, NULL); @@ -101,7 +101,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) ext->opt_label = lv_label_create(new_ddlist, copy_ext->opt_label); lv_label_set_text(ext->opt_label, lv_label_get_text(copy_ext->opt_label)); ext->sel_opt = copy_ext->sel_opt; - ext->auto_size = copy_ext->auto_size; + ext->fix_height = copy_ext->fix_height; ext->cb = copy_ext->cb; ext->num_opt = copy_ext->num_opt; @@ -130,8 +130,6 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param) * make the object specific signal handling */ if(valid != false) { if(sign == LV_SIGNAL_STYLE_CHG) { - lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); - lv_obj_set_style(ext->opt_label, lv_obj_get_style(ddlist)); lv_ddlist_refr_size(ddlist, 0); } else if(sign == LV_SIGNAL_FOCUS) { lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); @@ -256,15 +254,16 @@ void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t cb) } /** - * Set the auto size attribute. If enabled the height will reduced to be visible on the parent. - * In this case the drop down list can be scrolled. + * Set the fix height value. + * If 0 then the opened ddlist will be auto. sized else the set height will be applied. * @param ddlist pointer to a drop down list - * @param auto_size true: enable auto size, false: disable + * @param h the height when the list is opened (0: auto size) */ -void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size) +void lv_ddlist_set_fix_height(lv_obj_t * ddlist, cord_t h) { lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); - ext->auto_size = auto_size == false ? 0 : 1; + ext->fix_height = h; + lv_ddlist_refr_size(ddlist, 0); } /** @@ -356,14 +355,14 @@ void lv_ddlist_get_selected_str(lv_obj_t * ddlist, char * buf) } /** - * Get the auto size attribute. + * Get the fix height value. * @param ddlist pointer to a drop down list object - * @return true: the auto_size is enabled, false: disabled + * @return the height if the ddlist is opened (0: auto size) */ -bool lv_ddlist_get_auto_size(lv_obj_t * ddlist, bool auto_size) +cord_t lv_ddlist_get_fix_height(lv_obj_t * ddlist) { lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); - return ext->auto_size == 0 ? false : true; + return ext->fix_height; } /** @@ -484,7 +483,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 status (open or closed) + * Refresh the size of drop down list according to its status (open or closed) * @param ddlist pointer to a drop down list object * @param anim_time animations time for open/close [ms] */ @@ -493,13 +492,9 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, uint16_t anim_time) lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); lv_style_t * style = lv_obj_get_style(ddlist); cord_t new_height; - if(ext->opened != 0) { /*Open the list*/ - new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad; - lv_obj_t * parent = lv_obj_get_parent(ddlist); - /*Reduce the height if enabled and required*/ - if(ext->auto_size != 0 && new_height + ddlist->cords.y1 > parent->cords.y2) { - new_height = parent->cords.y2 - ddlist->cords.y1; - } + if(ext->opened) { /*Open the list*/ + if(ext->fix_height == 0) new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad; + else new_height = ext->fix_height; } else { /*Close the list*/ const font_t * font = style->font; lv_style_t * label_style = lv_obj_get_style(ext->opt_label); diff --git a/lv_objx/lv_ddlist.h b/lv_objx/lv_ddlist.h index 18ec4930d..018548b3c 100644 --- a/lv_objx/lv_ddlist.h +++ b/lv_objx/lv_ddlist.h @@ -48,7 +48,7 @@ typedef struct uint16_t sel_opt; /*Index of the current option*/ uint16_t anim_time; /*Open/Close animation time [ms]*/ uint8_t opened :1; /*1: The list is opened*/ - uint8_t auto_size :1; /*1: Set height to show all options. 0: Set height maximum to the parent bottom*/ + cord_t fix_height; /*Height if the ddlist is opened. (0: auto-size)*/ }lv_ddlist_ext_t; @@ -99,12 +99,12 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt); void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t cb); /** - * Set the auto size attribute. If enabled the height will reduced to be visible on the parent. - * In this case the drop down list can be scrolled. + * Set the fix height value. + * If 0 then the opened ddlist will be auto. sized else the set height will be applied. * @param ddlist pointer to a drop down list - * @param auto_size true: enable auto size, false: disable + * @param h the height when the list is opened (0: auto size) */ -void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size); +void lv_ddlist_set_fix_height(lv_obj_t * ddlist, cord_t h); /** * Set the style of the rectangle on the selected option @@ -142,12 +142,13 @@ uint16_t lv_ddlist_get_selected(lv_obj_t * ddlist); */ void lv_ddlist_get_selected_str(lv_obj_t * ddlist, char * buf); + /** - * Get the auto size attribute. + * Get the fix height value. * @param ddlist pointer to a drop down list object - * @return true: the auto_size is enabled, false: disabled + * @return the height if the ddlist is opened (0: auto size) */ -bool lv_ddlist_get_auto_size(lv_obj_t * ddlist, bool auto_size); +cord_t lv_ddlist_get_fix_height(lv_obj_t * ddlist); /** * Get the style of the rectangle on the selected option From b557331d63bb6772c77d8e2e7f9402699a1bda9c Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Fri, 22 Sep 2017 23:55:54 +0200 Subject: [PATCH 13/19] lv_roller updates --- lv_objx/lv_roller.c | 88 +++++++++++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 23 deletions(-) diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index e25a8c3ef..fc1aaf56e 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -52,8 +52,7 @@ static lv_signal_f_t ancestor_scr_signal_f; lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor of roller*/ - /*TODO modify it to the ancestor create function */ - lv_obj_t * new_roller = lv_ddlist_create(par, copy); + lv_obj_t * new_roller = lv_ddlist_create(par, copy); dm_assert(new_roller); /*Allocate the roller type specific extended data*/ @@ -71,20 +70,16 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new roller roller*/ if(copy == NULL) { lv_obj_t * scrl = lv_page_get_scrl(new_roller); - lv_obj_set_drag(scrl, true); - lv_page_set_rel_action(new_roller, NULL); + lv_obj_set_drag(scrl, true); /*In ddlist is might be disabled*/ + lv_page_set_rel_action(new_roller, NULL); /*Handle roller specific actions*/ + lv_cont_set_fit(lv_page_get_scrl(new_roller), true, false); /*Height is specified directly*/ lv_obj_set_signal_f(scrl, roller_scrl_signal); - // lv_ddlist_open(new_roller, true, false); - lv_obj_set_style(new_roller, lv_style_get(LV_STYLE_PRETTY, NULL)); - lv_cont_set_fit(lv_page_get_scrl(new_roller), true, false); - lv_ddlist_set_options_str(new_roller, "alma\nkorte\ncitrom\nbanan\neper\ndinnye"); + lv_ddlist_open(new_roller, true, 0); lv_style_t * style_label = lv_obj_get_style(ext->ddlist.opt_label); - lv_obj_set_height(new_roller, (font_get_height(style_label->font) >> FONT_ANTIALIAS) * 3 + style_label->line_space * 4); - - lv_obj_set_height(lv_page_get_scrl(new_roller), lv_obj_get_height(ext->ddlist.opt_label) + lv_obj_get_height(new_roller)); - lv_obj_align(ext->ddlist.opt_label, NULL, LV_ALIGN_CENTER, 0, 0); - + lv_ddlist_set_fix_height(new_roller, (font_get_height(style_label->font) >> FONT_ANTIALIAS) * 3 + + style_label->line_space * 4); + lv_obj_refr_style(new_roller); /*To set scrollable size automatically*/ } /*Copy an existing roller*/ else { @@ -109,15 +104,24 @@ bool lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param) bool valid; /* Include the ancient signal function */ - /* TODO update it to the ancestor's signal function*/ valid = lv_ddlist_signal(roller, sign, param); /* The object can be deleted so check its validity and then * make the object specific signal handling */ if(valid != false) { - if(sign == LV_SIGNAL_CLEANUP) { - /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ - } + lv_roller_ext_t * ext = lv_obj_get_ext(roller); + if(sign == LV_SIGNAL_STYLE_CHG) { + lv_obj_set_height(lv_page_get_scrl(roller), + lv_obj_get_height(ext->ddlist.opt_label) + lv_obj_get_height(roller)); + lv_obj_align(ext->ddlist.opt_label, NULL, LV_ALIGN_CENTER, 0, 0); + lv_ddlist_set_selected(roller, ext->ddlist.sel_opt); + } else if(sign == LV_SIGNAL_CORD_CHG) { + lv_ddlist_set_fix_height(roller, lv_obj_get_height(roller)); + lv_obj_set_height(lv_page_get_scrl(roller), + lv_obj_get_height(ext->ddlist.opt_label) + lv_obj_get_height(roller)); + lv_obj_align(ext->ddlist.opt_label, NULL, LV_ALIGN_CENTER, 0, 0); + lv_ddlist_set_selected(roller, ext->ddlist.sel_opt); + } } return valid; @@ -188,7 +192,6 @@ static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_m cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; area_t rect_area; rect_area.y1 = roller->cords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->line_space - 2; - rect_area.y2 = rect_area.y1 + font_h + style->line_space; rect_area.x1 = ext->ddlist.opt_label->cords.x1 - style->hpad; rect_area.x2 = rect_area.x1 + lv_obj_get_width(lv_page_get_scrl(roller)); @@ -215,17 +218,56 @@ bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) * make the object specific signal handling */ if(valid != false) { if(sign == LV_SIGNAL_RELEASED) { + int32_t id; lv_obj_t * roller = lv_obj_get_parent(roller_scrl); lv_roller_ext_t * ext = lv_obj_get_ext(roller); lv_style_t * style_label = lv_obj_get_style(ext->ddlist.opt_label); + const font_t * font = style_label->font; + cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; - cord_t label_y1 = ext->ddlist.page.scrl->cords.y1 - roller->cords.y1; - cord_t label_unit = (font_get_height(style_label->font) >> FONT_ANTIALIAS) + style_label->line_space / 2; - cord_t mid = (roller->cords.y2 - roller->cords.y1) / 2; + if(lv_dispi_is_dragging(param)) { - int32_t id = (mid - label_y1) / label_unit; + cord_t label_y1 = ext->ddlist.opt_label->cords.y1 - roller->cords.y1; + cord_t label_unit = (font_get_height(style_label->font) >> FONT_ANTIALIAS) + style_label->line_space / 2; + cord_t mid = (roller->cords.y2 - roller->cords.y1) / 2; - printf("roller diff: %d , unit: %d, id: %d\n", mid-label_y1, label_unit, id); + id = (mid - label_y1) / label_unit; + + printf("roller diff: %d , unit: %d, id: %d\n", mid-label_y1, label_unit, id); + } else { + point_t p; + lv_dispi_get_point(param, &p); + p.y = p.y - ext->ddlist.opt_label->cords.y1; + printf("y: %d\n", p.y); + id = p.y / (font_h + style_label->line_space); + } + if(id < 0) id = 0; + if(id >= ext->ddlist.num_opt) id = ext->ddlist.num_opt - 1; + ext->ddlist.sel_opt = id; + + + cord_t h = lv_obj_get_height(roller); + cord_t line_y1 = id * (font_h + style_label->line_space) + ext->ddlist.opt_label->cords.y1 - roller_scrl->cords.y1; + cord_t new_y = - line_y1 + (h - font_h) / 2; + + if(ext->ddlist.anim_time == 0) { + lv_obj_set_y(roller_scrl, new_y); + } else { + anim_t a; + a.var = roller_scrl; + a.start = lv_obj_get_y(roller_scrl); + a.end = new_y; + a.fp = (anim_fp_t)lv_obj_set_y; + a.path = anim_get_path(ANIM_PATH_LIN); + a.end_cb = NULL; + a.act_time = 0; + a.time = ext->ddlist.anim_time; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + anim_create(&a); + } } } From af11110e0fcd426d8220a21c171cc922c06c7cd8 Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Sat, 23 Sep 2017 22:14:31 +0200 Subject: [PATCH 14/19] lv_roller: comments added --- lv_objx/lv_roller.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index fc1aaf56e..7897724fc 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -206,8 +206,14 @@ static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_m return true; } - -bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) +/** + * Signal function of the scrollable part of the roller. + * @param roller_scrl ointer to the scrollable part of roller (page) + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +static bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) { bool valid; @@ -225,27 +231,25 @@ bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) const font_t * font = style_label->font; cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; + /*If dragged then align the list to there be an element in the middle*/ if(lv_dispi_is_dragging(param)) { - cord_t label_y1 = ext->ddlist.opt_label->cords.y1 - roller->cords.y1; cord_t label_unit = (font_get_height(style_label->font) >> FONT_ANTIALIAS) + style_label->line_space / 2; cord_t mid = (roller->cords.y2 - roller->cords.y1) / 2; - id = (mid - label_y1) / label_unit; - - printf("roller diff: %d , unit: %d, id: %d\n", mid-label_y1, label_unit, id); - } else { + } + /*If pick an option by clicking then set it*/ + else { point_t p; lv_dispi_get_point(param, &p); p.y = p.y - ext->ddlist.opt_label->cords.y1; - printf("y: %d\n", p.y); id = p.y / (font_h + style_label->line_space); } if(id < 0) id = 0; if(id >= ext->ddlist.num_opt) id = ext->ddlist.num_opt - 1; ext->ddlist.sel_opt = id; - + /*Position the scrollable according to the new selected option*/ cord_t h = lv_obj_get_height(roller); cord_t line_y1 = id * (font_h + style_label->line_space) + ext->ddlist.opt_label->cords.y1 - roller_scrl->cords.y1; cord_t new_y = - line_y1 + (h - font_h) / 2; From ebfe8fbfd4d93bd0e09a8b16e96e623c5c6be0f2 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 27 Sep 2017 13:05:35 +0200 Subject: [PATCH 15/19] update to the new font desciption --- lv_draw/lv_draw.c | 2 +- lv_draw/lv_draw_rbasic.c | 16 ++++++++-------- lv_draw/lv_draw_vbasic.c | 16 +++++++++------- lv_objx/lv_ta.c | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index 6e027d2c0..97a02cf58 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -288,7 +288,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_ if((flag & TXT_FLAG_RECOLOR) != 0) { if(letter == TXT_RECOLOR_CMD) { if(cmd_state == CMD_STATE_WAIT) { /*Start char*/ - par_start = i + txt_utf8_size(&txt[i]); + par_start = i + txt_utf8_size(txt[i]); cmd_state = CMD_STATE_PAR; continue; } else if(cmd_state == CMD_STATE_PAR) { /*Other start char in parameter escaped cmd. char */ diff --git a/lv_draw/lv_draw_rbasic.c b/lv_draw/lv_draw_rbasic.c index d1c3ed294..74d07f112 100644 --- a/lv_draw/lv_draw_rbasic.c +++ b/lv_draw/lv_draw_rbasic.c @@ -95,6 +95,7 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, color_t color, opa_t opa) { uint8_t w = font_get_width(font_p, letter); + const uint8_t * bitmap_p = font_get_bitmap(font_p, letter); uint8_t col, col_sub, row; @@ -110,15 +111,14 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, col_sub = 8; } } - - /*Correction if the letter is short*/ - bitmap_p += font_p->width_byte - ((w >> 3) + 1); /*Go to the next row*/ bitmap_p ++; } #else + uint8_t width_byte = w >> 3; /*Width in bytes (e.g. w = 11 -> 2 bytes wide)*/ + if(w & 0x7) width_byte++; const uint8_t * map1_p = bitmap_p; - const uint8_t * map2_p = bitmap_p + font_p->width_byte; + const uint8_t * map2_p = bitmap_p + width_byte; uint8_t px_cnt; uint8_t col_byte_cnt; for(row = 0; row < (font_p->height_row >> 1); row ++) { @@ -152,10 +152,10 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, } } - map1_p += font_p->width_byte; - map2_p += font_p->width_byte; - map1_p += font_p->width_byte - col_byte_cnt; - map2_p += font_p->width_byte - col_byte_cnt; + map1_p += width_byte; + map2_p += width_byte; + map1_p += width_byte - col_byte_cnt; + map2_p += width_byte - col_byte_cnt; } #endif } diff --git a/lv_draw/lv_draw_vbasic.c b/lv_draw/lv_draw_vbasic.c index 90fd052f6..e97360c3f 100644 --- a/lv_draw/lv_draw_vbasic.c +++ b/lv_draw/lv_draw_vbasic.c @@ -170,6 +170,8 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, cord_t col, row; uint8_t col_bit; uint8_t col_byte_cnt; + uint8_t width_byte = letter_w >> 3; /*Width in bytes (e.g. w = 11 -> 2 bytes wide)*/ + if(letter_w & 0x7) width_byte++; /* Calculate the col/row start/end on the map * If font anti alaiassing is enabled use the reduced letter sizes*/ @@ -186,13 +188,13 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, vdb_buf_tmp += (row_start * vdb_width) + col_start; /*Move on the map too*/ - map_p += ((row_start << FONT_ANTIALIAS) * font_p->width_byte) + ((col_start << FONT_ANTIALIAS) >> 3); + map_p += ((row_start << FONT_ANTIALIAS) * width_byte) + ((col_start << FONT_ANTIALIAS) >> 3); #if FONT_ANTIALIAS != 0 opa_t opa_tmp = opa; if(opa_tmp != OPA_COVER) opa_tmp = opa_tmp >> 2; /*Opacity per pixel (used when sum the pixels)*/ const uint8_t * map1_p = map_p; - const uint8_t * map2_p = map_p + font_p->width_byte; + const uint8_t * map2_p = map_p + width_byte; uint8_t px_cnt; for(row = row_start; row < row_end; row ++) { col_byte_cnt = 0; @@ -228,10 +230,10 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, vdb_buf_tmp++; } - map1_p += font_p->width_byte; - map2_p += font_p->width_byte; - map1_p += font_p->width_byte - col_byte_cnt; - map2_p += font_p->width_byte - col_byte_cnt; + map1_p += width_byte; + map2_p += width_byte; + map1_p += width_byte - col_byte_cnt; + map2_p += width_byte - col_byte_cnt; vdb_buf_tmp += vdb_width - ((col_end) - (col_start)); /*Next row in VDB*/ } #else @@ -255,7 +257,7 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, } } - map_p += font_p->width_byte - col_byte_cnt; + map_p += width_byte - col_byte_cnt; vdb_buf_tmp += vdb_width - (col_end - col_start); /*Next row in VDB*/ } #endif diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 906e6dd07..775f8281a 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -209,7 +209,7 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) /** * Insert a character to the current cursor position * @param ta pointer to a text area object - * @param c a character + * @param c a character (could but UTF-8 code as well: 'Á' or txt_unicode_to_utf8(0x047C) */ void lv_ta_add_char(lv_obj_t * ta, uint32_t c) { From 9cd49f155456f38d93cec8f7c9af069fd498fa7f Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 27 Sep 2017 15:15:47 +0200 Subject: [PATCH 16/19] lv_ta: remove a forgotten debug printf --- lv_objx/lv_ta.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 775f8281a..f60091a06 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -837,7 +837,6 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des #endif uint32_t letter = txt_utf8_next(&txt[byte_pos], NULL); - printf("letter %d\n", letter); cord_t letter_w = font_get_width(label_style->font, letter != '\0' ? letter : ' '); cord_t letter_h = font_get_height(label_style->font) >> FONT_ANTIALIAS; point_t letter_pos; From 0c473c6ccb1a3816cfe701515d8c335d04bb5d3a Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 2 Oct 2017 17:19:25 +0200 Subject: [PATCH 17/19] lv_roller: make roller_scrl_signal to static --- lv_objx/lv_roller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index 7897724fc..7ba607fe7 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -24,7 +24,7 @@ * STATIC PROTOTYPES **********************/ static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_mode_t mode); -bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param); +static bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param); /********************** * STATIC VARIABLES From d1dcc41f695a19be212f4d0a1a9bdedfd2157a4e Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 3 Oct 2017 11:35:53 +0200 Subject: [PATCH 18/19] lv_ta: remove forgotten printf --- lv_objx/lv_ta.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index ff889b42a..1207a1742 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -875,8 +875,7 @@ static bool lv_ta_scrling_design(lv_obj_t * scrl, const area_t * mask, lv_design uint32_t letter = txt_utf8_next(&txt[byte_pos], NULL); cord_t letter_h = font_get_height(label_style->font) >> FONT_ANTIALIAS; - printf("letter1:%c, bp:%d\n", letter, byte_pos); - /*Set letter_w (set not 0 on non printable but valid chars)*/ + /*Set letter_w (set not 0 on non printable but valid chars)*/ cord_t letter_w; if(letter == '\0' || letter == '\n' || letter == '\r') { letter_w = font_get_width(label_style->font, ' '); @@ -897,7 +896,6 @@ static bool lv_ta_scrling_design(lv_obj_t * scrl, const area_t * mask, lv_design letter = txt_utf8_next(&txt[byte_pos], NULL); } - printf("letter2:%c, bp:%d\n", letter, byte_pos); if(letter == '\0' || letter == '\n' || letter == '\r') { letter_w = font_get_width(label_style->font, ' '); } else { From 315bf64ccb44f5fdb5437a52033aef017bbfa867 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 5 Oct 2017 11:10:44 +0200 Subject: [PATCH 19/19] merge utf8 --- lv_conf_templ.h | 1 - lv_objx/lv_ta.c | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lv_conf_templ.h b/lv_conf_templ.h index 138c3a6e4..a3e074cb6 100644 --- a/lv_conf_templ.h +++ b/lv_conf_templ.h @@ -134,7 +134,6 @@ /*Text area (dependencies: lv_label, lv_page)*/ #define USE_LV_TA 1 #if USE_LV_TA != 0 -#define LV_TA_MAX_LENGTH 256 #define LV_TA_CUR_BLINK_TIME 400 /*ms*/ #define LV_TA_PWD_SHOW_TIME 1500 /*ms*/ #endif diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 1207a1742..c34758349 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -309,8 +309,6 @@ void lv_ta_add_char(lv_obj_t * ta, uint32_t c) void lv_ta_add_text(lv_obj_t * ta, const char * txt) { lv_ta_ext_t * ext = lv_obj_get_ext(ta); - - const char * label_txt = lv_label_get_text(ext->label); uint16_t txt_len = strlen(txt); if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/ @@ -318,7 +316,6 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt) lv_label_ins_text(ext->label, ext->cursor_pos, txt); - if(ext->pwd_mode != 0) { ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + txt_len + 1); dm_assert(ext->pwd_tmp); @@ -816,7 +813,7 @@ static bool lv_ta_design(lv_obj_t * ta, const area_t * masp, lv_design_mode_t mo /** * An extended scrollable design of the page. Calls the normal design function and draws a cursor. - * @param scrl pointer to the scrollabla part of the Text area + * @param scrl pointer to the scrollable part of the Text area * @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)