From 6aa27cc11b321810fb8a050fc0e943d213d2c2a8 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 13 May 2021 15:39:06 +0200 Subject: [PATCH] refactor(label, text area) rename functions of text_sel to text_selection --- lv_conf_template.h | 2 +- src/lv_conf_internal.h | 8 ++++---- src/widgets/lv_label.c | 22 +++++++++++----------- src/widgets/lv_label.h | 16 ++++++++-------- src/widgets/lv_textarea.c | 26 +++++++++++++------------- src/widgets/lv_textarea.h | 6 +++--- tests/build.py | 2 +- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lv_conf_template.h b/lv_conf_template.h index 0bdc209f4..3afe18403 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -390,7 +390,7 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/ #define LV_USE_LABEL 1 #if LV_USE_LABEL -# define LV_LABEL_TEXT_SEL 1 /*Enable selecting text of the label*/ +# define LV_LABEL_TEXT_SELECTION 1 /*Enable selecting text of the label*/ # define LV_LABEL_LONG_TXT_HINT 1 /*Store some extra info in labels to speed up drawing of very long texts*/ #endif diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index fff2c8f49..5fb67c72a 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -1152,11 +1152,11 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/ # endif #endif #if LV_USE_LABEL -#ifndef LV_LABEL_TEXT_SEL -# ifdef CONFIG_LV_LABEL_TEXT_SEL -# define LV_LABEL_TEXT_SEL CONFIG_LV_LABEL_TEXT_SEL +#ifndef LV_LABEL_TEXT_SELECTION +# ifdef CONFIG_LV_LABEL_TEXT_SELECTION +# define LV_LABEL_TEXT_SELECTION CONFIG_LV_LABEL_TEXT_SELECTION # else -# define LV_LABEL_TEXT_SEL 1 /*Enable selecting text of the label*/ +# define LV_LABEL_TEXT_SELECTION 1 /*Enable selecting text of the label*/ # endif #endif #ifndef LV_LABEL_LONG_TXT_HINT diff --git a/src/widgets/lv_label.c b/src/widgets/lv_label.c index 91268e552..f47a79b39 100644 --- a/src/widgets/lv_label.c +++ b/src/widgets/lv_label.c @@ -233,7 +233,7 @@ void lv_label_set_text_sel_start(lv_obj_t * obj, uint32_t index) { LV_ASSERT_OBJ(obj, MY_CLASS); -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION lv_label_t * label = (lv_label_t *)obj; label->sel_start = index; lv_obj_invalidate(obj); @@ -247,7 +247,7 @@ void lv_label_set_text_sel_end(lv_obj_t * obj, uint32_t index) { LV_ASSERT_OBJ(obj, MY_CLASS); -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION lv_label_t * label = (lv_label_t *)obj; label->sel_end = index; lv_obj_invalidate(obj); @@ -603,30 +603,30 @@ bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos) return (pos->x >= (last_x - letter_space) && pos->x <= (last_x + max_diff)); } -uint32_t lv_label_get_text_sel_start(const lv_obj_t * obj) +uint32_t lv_label_get_text_selection_start(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION lv_label_t * label = (lv_label_t *)obj; return label->sel_start; #else (void)obj; /*Unused*/ - return LV_LABEL_TEXT_SEL_OFF; + return LV_LABEL_TEXT_SELECTION_OFF; #endif } -uint32_t lv_label_get_text_sel_end(const lv_obj_t * obj) +uint32_t lv_label_get_text_selection_end(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION lv_label_t * label = (lv_label_t *)obj; return label->sel_end; #else (void)obj; /*Unused*/ - return LV_LABEL_TEXT_SEL_OFF; + return LV_LABEL_TEXT_SELECTION_OFF; #endif } @@ -717,7 +717,7 @@ static void lv_label_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) label->hint.y = 0; #endif -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION label->sel_start = LV_DRAW_LABEL_NO_TXT_SEL; label->sel_end = LV_DRAW_LABEL_NO_TXT_SEL; #endif @@ -820,8 +820,8 @@ static void draw_main(lv_event_t * e) label_draw_dsc.flag = flag; lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_draw_dsc); - label_draw_dsc.sel_start = lv_label_get_text_sel_start(obj); - label_draw_dsc.sel_end = lv_label_get_text_sel_end(obj); + label_draw_dsc.sel_start = lv_label_get_text_selection_start(obj); + label_draw_dsc.sel_end = lv_label_get_text_selection_end(obj); if(label_draw_dsc.sel_start != LV_DRAW_LABEL_NO_TXT_SEL && label_draw_dsc.sel_end != LV_DRAW_LABEL_NO_TXT_SEL) { label_draw_dsc.sel_color = lv_obj_get_style_text_color_filtered(obj, LV_PART_SELECTED); label_draw_dsc.sel_bg_color = lv_obj_get_style_bg_color(obj, LV_PART_SELECTED); diff --git a/src/widgets/lv_label.h b/src/widgets/lv_label.h index 57c881e63..2bbfc86f3 100644 --- a/src/widgets/lv_label.h +++ b/src/widgets/lv_label.h @@ -30,11 +30,11 @@ extern "C" { #define LV_LABEL_WAIT_CHAR_COUNT 3 #define LV_LABEL_DOT_NUM 3 #define LV_LABEL_POS_LAST 0xFFFF -#define LV_LABEL_TEXT_SEL_OFF LV_DRAW_LABEL_NO_TXT_SEL +#define LV_LABEL_TEXT_SELECTION_OFF LV_DRAW_LABEL_NO_TXT_SEL LV_EXPORT_CONST_INT(LV_LABEL_DOT_NUM); LV_EXPORT_CONST_INT(LV_LABEL_POS_LAST); -LV_EXPORT_CONST_INT(LV_LABEL_TEXT_SEL_OFF); +LV_EXPORT_CONST_INT(LV_LABEL_TEXT_SELECTION_OFF); /********************** * TYPEDEFS @@ -63,7 +63,7 @@ typedef struct { lv_draw_label_hint_t hint; #endif -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION uint32_t sel_start; uint32_t sel_end; #endif @@ -134,14 +134,14 @@ void lv_label_set_recolor(lv_obj_t * obj, bool en); /** * Set where text selection should start * @param obj pointer to a label object - * @param index character index from where selection should start. `LV_LABEL_TEXT_SEL_OFF` for no selection + * @param index character index from where selection should start. `LV_LABEL_TEXT_SELECTION_OFF` for no selection */ void lv_label_set_text_sel_start(lv_obj_t * obj, uint32_t index); /** * Set where text selection should end * @param obj pointer to a label object - * @param index character index where selection should end. `LV_LABEL_TEXT_SEL_OFF` for no selection + * @param index character index where selection should end. `LV_LABEL_TEXT_SELECTION_OFF` for no selection */ void lv_label_set_text_sel_end(lv_obj_t * obj, uint32_t index); @@ -199,16 +199,16 @@ bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos); /** * @brief Get the selection start index. * @param obj pointer to a label object. - * @return selection start index. `LV_LABEL_TEXT_SEL_OFF` if nothing is selected. + * @return selection start index. `LV_LABEL_TEXT_SELECTION_OFF` if nothing is selected. */ -uint32_t lv_label_get_text_sel_start(const lv_obj_t * obj); +uint32_t lv_label_get_text_selection_start(const lv_obj_t * obj); /** * @brief Get the selection end index. * @param obj pointer to a label object. * @return selection end index. `LV_LABEL_TXT_SEL_OFF` if nothing is selected. */ -uint32_t lv_label_get_text_sel_end(const lv_obj_t * obj); +uint32_t lv_label_get_text_selection_end(const lv_obj_t * obj); /*===================== * Other functions diff --git a/src/widgets/lv_textarea.c b/src/widgets/lv_textarea.c index 2eca5ceda..5147811dc 100644 --- a/src/widgets/lv_textarea.c +++ b/src/widgets/lv_textarea.c @@ -520,11 +520,11 @@ void lv_textarea_set_insert_replace(lv_obj_t * obj, const char * txt) ta_insert_replace = txt; } -void lv_textarea_set_text_sel(lv_obj_t * obj, bool en) +void lv_textarea_set_text_selection(lv_obj_t * obj, bool en) { LV_ASSERT_OBJ(obj, MY_CLASS); -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION lv_textarea_t * ta = (lv_textarea_t *)obj; ta->text_sel_en = en; @@ -653,11 +653,11 @@ bool lv_textarea_text_is_selected(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION lv_textarea_t * ta = (lv_textarea_t *)obj; - if((lv_label_get_text_sel_start(ta->label) == LV_DRAW_LABEL_NO_TXT_SEL || - lv_label_get_text_sel_end(ta->label) == LV_DRAW_LABEL_NO_TXT_SEL)) { + if((lv_label_get_text_selection_start(ta->label) == LV_DRAW_LABEL_NO_TXT_SEL || + lv_label_get_text_selection_end(ta->label) == LV_DRAW_LABEL_NO_TXT_SEL)) { return true; } else { @@ -669,11 +669,11 @@ bool lv_textarea_text_is_selected(const lv_obj_t * obj) #endif } -bool lv_textarea_get_text_sel_en(lv_obj_t * obj) +bool lv_textarea_get_text_selection(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION lv_textarea_t * ta = (lv_textarea_t *)obj; return ta->text_sel_en; #else @@ -699,11 +699,11 @@ void lv_textarea_clear_selection(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION lv_textarea_t * ta = (lv_textarea_t *)obj; - if(lv_label_get_text_sel_start(ta->label) != LV_DRAW_LABEL_NO_TXT_SEL || - lv_label_get_text_sel_end(ta->label) != LV_DRAW_LABEL_NO_TXT_SEL) { + if(lv_label_get_text_selection_start(ta->label) != LV_DRAW_LABEL_NO_TXT_SEL || + lv_label_get_text_selection_end(ta->label) != LV_DRAW_LABEL_NO_TXT_SEL) { lv_label_set_text_sel_start(ta->label, LV_DRAW_LABEL_NO_TXT_SEL); lv_label_set_text_sel_end(ta->label, LV_DRAW_LABEL_NO_TXT_SEL); } @@ -806,7 +806,7 @@ static void lv_textarea_constructor(const lv_obj_class_t * class_p, lv_obj_t * o ta->cursor.click_pos = 1; ta->cursor.valid_x = 0; ta->one_line = 0; -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION ta->text_sel_en = 0; #endif ta->label = NULL; @@ -1154,7 +1154,7 @@ static void update_cursor_position_on_click(lv_event_t * e) uint16_t char_id_at_click; -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION lv_label_t * label_data = (lv_label_t *)ta->label; bool click_outside_label; /*Check if the click happened on the left side of the area outside the label*/ @@ -1176,7 +1176,7 @@ static void update_cursor_position_on_click(lv_event_t * e) if(!ta->text_sel_in_prog && !click_outside_label && code == LV_EVENT_PRESSED) { /*Input device just went down. Store the selection start position*/ ta->sel_start = char_id_at_click; - ta->sel_end = LV_LABEL_TEXT_SEL_OFF; + ta->sel_end = LV_LABEL_TEXT_SELECTION_OFF; ta->text_sel_in_prog = 1; lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_CHAIN); } diff --git a/src/widgets/lv_textarea.h b/src/widgets/lv_textarea.h index 065c1dae7..0964416d4 100644 --- a/src/widgets/lv_textarea.h +++ b/src/widgets/lv_textarea.h @@ -55,7 +55,7 @@ typedef struct { uint8_t show : 1; /*Cursor is visible now or not (Handled by the library)*/ uint8_t click_pos : 1; /*1: Enable positioning the cursor by clicking the text area*/ } cursor; -#if LV_LABEL_TEXT_SEL +#if LV_LABEL_TEXT_SELECTION uint32_t sel_start; /*Temporary values for text selection*/ uint32_t sel_end; uint8_t text_sel_in_prog : 1; /*User is in process of selecting*/ @@ -189,7 +189,7 @@ void lv_textarea_set_insert_replace(lv_obj_t * obj, const char * txt); * @param obj pointer to a text area object * @param en true or false to enable/disable selection mode */ -void lv_textarea_set_text_sel(lv_obj_t * obj, bool en); +void lv_textarea_set_text_selection(lv_obj_t * obj, bool en); /** * Set how long show the password before changing it to '*' @@ -286,7 +286,7 @@ bool lv_textarea_text_is_selected(const lv_obj_t * obj); * @param obj pointer to a text area object * @return true: selection mode is enabled, false: disabled */ -bool lv_textarea_get_text_sel_en(lv_obj_t * obj); +bool lv_textarea_get_text_selection(lv_obj_t * obj); /** * Set how long show the password before changing it to '*' diff --git a/tests/build.py b/tests/build.py index 101611a43..e35af2091 100755 --- a/tests/build.py +++ b/tests/build.py @@ -197,7 +197,7 @@ full_32bit = { "LV_USE_PERF_MONITOR":1, "LV_USE_MEM_MONITOR":1, - "LV_LABEL_TEXT_SEL":1, + "LV_LABEL_TEXT_SELECTION":1, "LV_BUILD_EXAMPLES":1,