From 32770da251901ec5262444bf7dbd75c009fc57ce Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 3 Jan 2020 11:06:11 +0100 Subject: [PATCH] integrate ta, kb --- src/lv_objx/lv_btnm.c | 24 +- src/lv_objx/lv_btnm.h | 2 +- src/lv_objx/lv_kb.c | 95 +++----- src/lv_objx/lv_kb.h | 24 +- src/lv_objx/lv_ta.c | 389 ++++++++++++++++----------------- src/lv_objx/lv_ta.h | 29 +-- src/lv_objx/lv_tabview.c | 2 +- src/lv_themes/lv_theme.h | 4 + src/lv_themes/lv_theme_alien.c | 23 +- 9 files changed, 255 insertions(+), 337 deletions(-) diff --git a/src/lv_objx/lv_btnm.c b/src/lv_objx/lv_btnm.c index e7a54933e..dd43f36d2 100644 --- a/src/lv_objx/lv_btnm.c +++ b/src/lv_objx/lv_btnm.c @@ -109,8 +109,8 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_size(new_btnm, LV_DPI * 3, LV_DPI * 2); /*Set the default styles*/ - lv_obj_reset_style(new_btnm, LV_BTNM_PART_MAIN); - _ot(new_btnm, LV_BTNM_PART_MAIN, BTNM); + lv_obj_reset_style(new_btnm, LV_BTNM_PART_BG); + _ot(new_btnm, LV_BTNM_PART_BG, BTNM); /* Do not cache the button style because it's independent from the object's style. * (Therefore it can't be cached)*/ @@ -165,11 +165,11 @@ void lv_btnm_set_map(const lv_obj_t * btnm, const char * map[]) ext->map_p = map; /*Set size and positions of the buttons*/ - lv_style_value_t left = lv_obj_get_style_value(btnm, LV_BTNM_PART_MAIN, LV_STYLE_PAD_LEFT); - lv_style_value_t right = lv_obj_get_style_value(btnm, LV_BTNM_PART_MAIN, LV_STYLE_PAD_RIGHT); - lv_style_value_t top = lv_obj_get_style_value(btnm, LV_BTNM_PART_MAIN, LV_STYLE_PAD_TOP); - lv_style_value_t bottom = lv_obj_get_style_value(btnm, LV_BTNM_PART_MAIN, LV_STYLE_PAD_BOTTOM); - lv_style_value_t inner = lv_obj_get_style_value(btnm, LV_BTNM_PART_MAIN, LV_STYLE_PAD_INNER); + lv_style_value_t left = lv_obj_get_style_value(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_LEFT); + lv_style_value_t right = lv_obj_get_style_value(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_RIGHT); + lv_style_value_t top = lv_obj_get_style_value(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_TOP); + lv_style_value_t bottom = lv_obj_get_style_value(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_BOTTOM); + lv_style_value_t inner = lv_obj_get_style_value(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_INNER); lv_coord_t max_w = lv_obj_get_width(btnm) - left - right; @@ -642,8 +642,8 @@ static lv_design_res_t lv_btnm_design(lv_obj_t * btnm, const lv_area_t * clip_ar btnm->state = state_ori; - lv_style_value_t padding_top = lv_obj_get_style_value(btnm, LV_BTNM_PART_MAIN, LV_STYLE_PAD_TOP); - lv_style_value_t padding_bottom = lv_obj_get_style_value(btnm, LV_BTNM_PART_MAIN, LV_STYLE_PAD_BOTTOM); + lv_style_value_t padding_top = lv_obj_get_style_value(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_TOP); + lv_style_value_t padding_bottom = lv_obj_get_style_value(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_BOTTOM); if(ext->recolor) txt_flag = LV_TXT_FLAG_RECOLOR; for(btn_i = 0; btn_i < ext->btn_cnt; btn_i++, txt_i++) { @@ -903,7 +903,7 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) ext->btn_id_act = ext->btn_id_pr; lv_obj_invalidate(btnm); } else if(c == LV_KEY_DOWN) { - lv_style_value_t pad_inner = lv_obj_get_style_value(btnm, LV_BTNM_PART_MAIN, LV_STYLE_PAD_INNER); + lv_style_value_t pad_inner = lv_obj_get_style_value(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_INNER); /*Find the area below the the current*/ if(ext->btn_id_pr == LV_BTNM_BTN_NONE) { ext->btn_id_pr = 0; @@ -925,7 +925,7 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) ext->btn_id_act = ext->btn_id_pr; lv_obj_invalidate(btnm); } else if(c == LV_KEY_UP) { - lv_style_value_t pad_inner = lv_obj_get_style_value(btnm, LV_BTNM_PART_MAIN, LV_STYLE_PAD_INNER); + lv_style_value_t pad_inner = lv_obj_get_style_value(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_INNER); /*Find the area below the the current*/ if(ext->btn_id_pr == LV_BTNM_BTN_NONE) { ext->btn_id_pr = 0; @@ -962,7 +962,7 @@ static lv_style_dsc_t * lv_btnm_get_style(lv_obj_t * btnm, uint8_t part) lv_style_dsc_t * style_dsc_p; switch(part) { - case LV_BTNM_PART_MAIN: + case LV_BTNM_PART_BG: style_dsc_p = &btnm->style_dsc; break; case LV_BTNM_PART_BTN: diff --git a/src/lv_objx/lv_btnm.h b/src/lv_objx/lv_btnm.h index d2b5a01e5..b38d0491a 100644 --- a/src/lv_objx/lv_btnm.h +++ b/src/lv_objx/lv_btnm.h @@ -63,7 +63,7 @@ typedef struct } lv_btnm_ext_t; enum { - LV_BTNM_PART_MAIN, + LV_BTNM_PART_BG, LV_BTNM_PART_BTN, }; typedef uint8_t lv_btnm_part_t; diff --git a/src/lv_objx/lv_kb.c b/src/lv_objx/lv_kb.c index 4f23ad0b7..44c715f36 100644 --- a/src/lv_objx/lv_kb.c +++ b/src/lv_objx/lv_kb.c @@ -29,7 +29,8 @@ * STATIC PROTOTYPES **********************/ static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param); -static void lv_kb_updatemap(lv_obj_t * kb); +static lv_style_dsc_t * lv_kb_get_style(lv_obj_t * kb, uint8_t part); +static void lv_kb_update_map(lv_obj_t * kb); /********************** * STATIC VARIABLES @@ -150,18 +151,6 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy) lv_btnm_set_map(new_kb, kb_map[ext->mode]); lv_btnm_set_ctrl_map(new_kb, kb_ctrl[ext->mode]); - /*Set the default styles*/ - lv_theme_t * th = lv_theme_get_current(); - if(th) { - lv_kb_set_style(new_kb, LV_KB_STYLE_BG, th->style.kb.bg); - lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_REL, th->style.kb.btn.rel); - lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_PR, th->style.kb.btn.pr); - lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_REL, th->style.kb.btn.tgl_rel); - lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_PR, th->style.kb.btn.tgl_pr); - lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_INA, th->style.kb.btn.ina); - } else { - /*Let the button matrix's styles*/ - } } /*Copy an existing keyboard*/ else { @@ -175,7 +164,7 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy) lv_btnm_set_ctrl_map(new_kb, kb_ctrl[ext->mode]); /*Refresh the style with new signal function*/ - lv_obj_refresh_style(new_kb); +// lv_obj_refresh_style(new_kb); } LV_LOG_INFO("keyboard created"); @@ -258,26 +247,6 @@ void lv_kb_set_cursor_manage(lv_obj_t * kb, bool en) } } -/** - * Set a style of a keyboard - * @param kb pointer to a keyboard object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_kb_set_style(lv_obj_t * kb, lv_kb_style_t type, const lv_style_t * style) -{ - LV_ASSERT_OBJ(kb, LV_OBJX_NAME); - - switch(type) { - case LV_KB_STYLE_BG: lv_btnm_set_style(kb, LV_BTNM_STYLE_BG, style); break; - case LV_KB_STYLE_BTN_REL: lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_REL, style); break; - case LV_KB_STYLE_BTN_PR: lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_PR, style); break; - case LV_KB_STYLE_BTN_TGL_REL: lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_TGL_REL, style); break; - case LV_KB_STYLE_BTN_TGL_PR: lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_TGL_PR, style); break; - case LV_KB_STYLE_BTN_INA: lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_INA, style); break; - } -} - /** * Set a new map for the keyboard * @param kb pointer to a Keyboard object @@ -288,7 +257,7 @@ void lv_kb_set_style(lv_obj_t * kb, lv_kb_style_t type, const lv_style_t * style void lv_kb_set_map(lv_obj_t * kb, lv_kb_mode_t mode, const char * map[]) { kb_map[mode] = map; - lv_kb_updatemap(kb); + lv_kb_update_map(kb); } /** @@ -303,7 +272,7 @@ void lv_kb_set_map(lv_obj_t * kb, lv_kb_mode_t mode, const char * map[]) void lv_kb_set_ctrl_map(lv_obj_t * kb, lv_kb_mode_t mode, const lv_btnm_ctrl_t ctrl_map[]) { kb_ctrl[mode] = ctrl_map; - lv_kb_updatemap(kb); + lv_kb_update_map(kb); } /*===================== @@ -349,31 +318,6 @@ bool lv_kb_get_cursor_manage(const lv_obj_t * kb) return ext->cursor_mng == 0 ? false : true; } -/** - * Get a style of a keyboard - * @param kb pointer to a keyboard object - * @param type which style should be get - * @return style pointer to a style - */ -const lv_style_t * lv_kb_get_style(const lv_obj_t * kb, lv_kb_style_t type) -{ - LV_ASSERT_OBJ(kb, LV_OBJX_NAME); - - const lv_style_t * style = NULL; - - switch(type) { - case LV_KB_STYLE_BG: style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BG); break; - case LV_KB_STYLE_BTN_REL: style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_REL); break; - case LV_KB_STYLE_BTN_PR: style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_PR); break; - case LV_KB_STYLE_BTN_TGL_REL: style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_TGL_REL); break; - case LV_KB_STYLE_BTN_TGL_PR: style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_TGL_PR); break; - case LV_KB_STYLE_BTN_INA: style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_INA); break; - default: style = NULL; break; - } - - return style; -} - /*===================== * Other functions *====================*/ @@ -511,11 +455,38 @@ static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param) return res; } +/** + * Get the style descriptor of a part of the object + * @param kb pointer the object + * @param part the part from `lv_kb_part_t`. (LV_KB_PART_...) + * @return pointer to the style descriptor of the specified part + */ +static lv_style_dsc_t * lv_kb_get_style(lv_obj_t * kb, uint8_t part) +{ + LV_ASSERT_OBJ(kb, LV_OBJX_NAME); + + lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); + lv_style_dsc_t * style_dsc_p; + + switch(part) { + case LV_KB_PART_BG: + style_dsc_p = &kb->style_dsc; + break; + case LV_KB_PART_BTN: + style_dsc_p = &ext->btnm.style_btn; + break; + default: + style_dsc_p = NULL; + } + + return style_dsc_p; +} + /** * Update the key map for the current mode * @param kb pointer to a keyboard object */ -static void lv_kb_updatemap(lv_obj_t * kb) +static void lv_kb_update_map(lv_obj_t * kb) { lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); lv_btnm_set_map(kb, kb_map[ext->mode]); diff --git a/src/lv_objx/lv_kb.h b/src/lv_objx/lv_kb.h index 97de1ae5c..fe442537c 100644 --- a/src/lv_objx/lv_kb.h +++ b/src/lv_objx/lv_kb.h @@ -57,12 +57,8 @@ typedef struct } lv_kb_ext_t; enum { - LV_KB_STYLE_BG, - LV_KB_STYLE_BTN_REL, - LV_KB_STYLE_BTN_PR, - LV_KB_STYLE_BTN_TGL_REL, - LV_KB_STYLE_BTN_TGL_PR, - LV_KB_STYLE_BTN_INA, + LV_KB_PART_BG, + LV_KB_PART_BTN, }; typedef uint8_t lv_kb_style_t; @@ -123,14 +119,6 @@ void lv_kb_set_map(lv_obj_t * kb, lv_kb_mode_t mode, const char * map[]); */ void lv_kb_set_ctrl_map(lv_obj_t * kb, lv_kb_mode_t mode, const lv_btnm_ctrl_t ctrl_map[]); -/** - * Set a style of a keyboard - * @param kb pointer to a keyboard object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_kb_set_style(lv_obj_t * kb, lv_kb_style_t type, const lv_style_t * style); - /*===================== * Getter functions *====================*/ @@ -166,14 +154,6 @@ static inline const char ** lv_kb_get_map_array(const lv_obj_t * kb) return lv_btnm_get_map_array(kb); } -/** - * Get a style of a keyboard - * @param kb pointer to a keyboard object - * @param type which style should be get - * @return style pointer to a style - */ -const lv_style_t * lv_kb_get_style(const lv_obj_t * kb, lv_kb_style_t type); - /*===================== * Other functions *====================*/ diff --git a/src/lv_objx/lv_ta.c b/src/lv_objx/lv_ta.c index 66e174502..81e5a1df7 100644 --- a/src/lv_objx/lv_ta.c +++ b/src/lv_objx/lv_ta.c @@ -46,6 +46,7 @@ static lv_design_res_t lv_ta_design(lv_obj_t * ta, const lv_area_t * clip_area, static lv_design_res_t lv_ta_scrollable_design(lv_obj_t * scrl, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param); static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); +static lv_style_dsc_t * lv_ta_get_style(lv_obj_t * ta, uint8_t part); #if LV_USE_ANIMATION static void cursor_blink_anim(lv_obj_t * ta, lv_anim_value_t show); static void pwd_char_hider_anim(lv_obj_t * ta, lv_anim_value_t x); @@ -53,7 +54,6 @@ static void pwd_char_hider_anim_ready(lv_anim_t * a); #endif static void pwd_char_hider(lv_obj_t * ta); static bool char_is_accepted(lv_obj_t * ta, uint32_t c); -static void get_cursor_style(lv_obj_t * ta, lv_style_t * style_res); static void refr_cursor_area(lv_obj_t * ta); static void placeholder_update(lv_obj_t * ta); static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_indev_t * click_source); @@ -144,16 +144,13 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_click(ext->label, false); lv_obj_set_size(new_ta, LV_TA_DEF_WIDTH, LV_TA_DEF_HEIGHT); lv_ta_set_sb_mode(new_ta, LV_SB_MODE_DRAG); - lv_page_set_style(new_ta, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight); - /*Set the default styles*/ - lv_theme_t * th = lv_theme_get_current(); - if(th) { - lv_ta_set_style(new_ta, LV_TA_STYLE_BG, th->style.ta.area); - lv_ta_set_style(new_ta, LV_TA_STYLE_SB, th->style.ta.sb); - } else { - lv_ta_set_style(new_ta, LV_TA_STYLE_BG, &lv_style_pretty); - } + lv_style_dsc_reset(&ext->page.scrl->style_dsc); + lv_obj_add_style_class(ext->page.scrl, LV_OBJ_PART_MAIN, &lv_style_transp_tight); + + _ot(new_ta, LV_TA_PART_CURSOR, TA_CURSOR); + + } /*Copy an existing object*/ else { @@ -186,10 +183,10 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy) if(copy_ext->one_line) lv_ta_set_one_line(new_ta, true); - lv_ta_set_style(new_ta, LV_TA_STYLE_CURSOR, lv_ta_get_style(copy, LV_TA_STYLE_CURSOR)); +// lv_ta_set_style(new_ta, LV_TA_STYLE_CURSOR, lv_ta_get_style(copy, LV_TA_STYLE_CURSOR)); /*Refresh the style with new signal function*/ - lv_obj_refresh_style(new_ta); +// lv_obj_refresh_style(new_ta); } #if LV_USE_ANIMATION @@ -430,8 +427,8 @@ void lv_ta_del_char(lv_obj_t * ta) /*Don't let 'width == 0' because cursor will not be visible*/ if(lv_obj_get_width(ext->label) == 0) { - const lv_style_t * style = lv_obj_get_style(ext->label); - lv_obj_set_width(ext->label, style->line.width); + lv_style_value_t line_width = lv_obj_get_style_value(ta, LV_TA_PART_CURSOR, LV_STYLE_LINE_WIDTH); + lv_obj_set_width(ext->label, line_width); } if(ext->pwd_mode != 0) { @@ -500,8 +497,8 @@ void lv_ta_set_text(lv_obj_t * ta, const char * txt) /*Don't let 'width == 0' because the cursor will not be visible*/ if(lv_obj_get_width(ext->label) == 0) { - const lv_style_t * style = lv_obj_get_style(ext->label); - lv_obj_set_width(ext->label, lv_font_get_glyph_width(style->text.font, ' ', '\0')); + lv_style_value_t line_width = lv_obj_get_style_value(ta, LV_TA_PART_CURSOR, LV_STYLE_LINE_WIDTH); + lv_obj_set_width(ext->label, line_width); } if(ext->pwd_mode != 0) { @@ -592,8 +589,9 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos) /*Position the label to make the cursor visible*/ lv_obj_t * label_par = lv_obj_get_parent(ext->label); lv_point_t cur_pos; - const lv_style_t * style = lv_obj_get_style(ta); - const lv_font_t * font_p = style->text.font; + const lv_font_t * font = lv_obj_get_style_ptr(ta, LV_TA_PART_BG, LV_STYLE_FONT); + lv_style_value_t top = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_TOP); + lv_style_value_t bottom = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_BOTTOM); lv_area_t label_cords; lv_area_t ta_cords; lv_label_get_letter_pos(ext->label, pos, &cur_pos); @@ -601,25 +599,25 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos) lv_obj_get_coords(ext->label, &label_cords); /*Check the top*/ - lv_coord_t font_h = lv_font_get_line_height(font_p); + lv_coord_t font_h = lv_font_get_line_height(font); if(lv_obj_get_y(label_par) + cur_pos.y < 0) { - lv_obj_set_y(label_par, -cur_pos.y + style->body.padding.top); + lv_obj_set_y(label_par, -cur_pos.y + top); } /*Check the bottom*/ - if(label_cords.y1 + cur_pos.y + font_h + style->body.padding.bottom > ta_cords.y2) { - lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) + font_h + style->body.padding.top + - style->body.padding.bottom)); + if(label_cords.y1 + cur_pos.y + font_h + bottom > ta_cords.y2) { + lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) + font_h + top + bottom)); } /*Check the left (use the font_h as general unit)*/ if(lv_obj_get_x(label_par) + cur_pos.x < font_h) { lv_obj_set_x(label_par, -cur_pos.x + font_h); } + lv_style_value_t right = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_RIGHT); + lv_style_value_t left = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_LEFT); /*Check the right (use the font_h as general unit)*/ - if(label_cords.x1 + cur_pos.x + font_h + style->body.padding.right > ta_cords.x2) { - lv_obj_set_x(label_par, -(cur_pos.x - lv_obj_get_width(ta) + font_h + style->body.padding.left + - style->body.padding.right)); + if(label_cords.x1 + cur_pos.x + font_h + right > ta_cords.x2) { + lv_obj_set_x(label_par, -(cur_pos.x - lv_obj_get_width(ta) + font_h + left + right)); } ext->cursor.valid_x = cur_pos.x; @@ -736,28 +734,28 @@ void lv_ta_set_one_line(lv_obj_t * ta, bool en) if(ext->one_line == en) return; if(en) { - const lv_style_t * style_ta = lv_obj_get_style(ta); - const lv_style_t * style_scrl = lv_obj_get_style(lv_page_get_scrl(ta)); - const lv_style_t * style_label = lv_obj_get_style(ext->label); - lv_coord_t font_h = lv_font_get_line_height(style_label->text.font); + lv_style_value_t top = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_TOP); + lv_style_value_t bottom = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_BOTTOM); + lv_style_value_t left = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_LEFT); + const lv_font_t * font = lv_obj_get_style_ptr(ta, LV_TA_PART_BG, LV_STYLE_FONT); + lv_coord_t font_h = lv_font_get_line_height(font); ext->one_line = 1; lv_page_set_scrl_fit2(ta, LV_FIT_TIGHT, LV_FIT_FLOOD); - lv_obj_set_height(ta, font_h + style_ta->body.padding.top + style_ta->body.padding.bottom + - style_scrl->body.padding.top + style_scrl->body.padding.bottom); + lv_obj_set_height(ta, font_h + top + bottom); lv_label_set_long_mode(ext->label, LV_LABEL_LONG_EXPAND); if(ext->placeholder) lv_label_set_long_mode(ext->placeholder, LV_LABEL_LONG_EXPAND); - lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->body.padding.left, style_ta->body.padding.top); + lv_obj_set_pos(lv_page_get_scrl(ta), left, top); } else { - const lv_style_t * style_ta = lv_obj_get_style(ta); - + lv_style_value_t top = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_TOP); + lv_style_value_t left = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_LEFT); ext->one_line = 0; lv_page_set_scrl_fit2(ta, LV_FIT_FLOOD, LV_FIT_TIGHT); lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK); if(ext->placeholder) lv_label_set_long_mode(ext->placeholder, LV_LABEL_LONG_BREAK); lv_obj_set_height(ta, LV_TA_DEF_HEIGHT); - lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->body.padding.left, style_ta->body.padding.top); + lv_obj_set_pos(lv_page_get_scrl(ta), left, top); } placeholder_update(ta); @@ -847,33 +845,6 @@ void lv_ta_set_insert_replace(lv_obj_t * ta, const char * txt) ta_insert_replace = txt; } -/** - * Set a style of a text area - * @param ta pointer to a text area object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_ta_set_style(lv_obj_t * ta, lv_ta_style_t type, const lv_style_t * style) -{ - LV_ASSERT_OBJ(ta, LV_OBJX_NAME); - - lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); - - switch(type) { - case LV_TA_STYLE_BG: lv_page_set_style(ta, LV_PAGE_STYLE_BG, style); break; - case LV_TA_STYLE_SB: lv_page_set_style(ta, LV_PAGE_STYLE_SB, style); break; - case LV_TA_STYLE_EDGE_FLASH: lv_page_set_style(ta, LV_PAGE_STYLE_EDGE_FLASH, style); break; - case LV_TA_STYLE_CURSOR: - ext->cursor.style = style; - lv_obj_refresh_ext_draw_pad(lv_page_get_scrl(ta)); /*Refresh ext. size because of cursor drawing*/ - refr_cursor_area(ta); - break; - case LV_TA_STYLE_PLACEHOLDER: - if(ext->placeholder) lv_label_set_style(ext->placeholder, LV_LABEL_STYLE_MAIN, style); - break; - } -} - /** * Enable/disable selection mode. * @param ta pointer to a text area object @@ -1101,33 +1072,6 @@ uint16_t lv_ta_get_max_length(lv_obj_t * ta) return ext->max_length; } -/** - * Get a style of a text area - * @param ta pointer to a text area object - * @param type which style should be get - * @return style pointer to a style - */ -const lv_style_t * lv_ta_get_style(const lv_obj_t * ta, lv_ta_style_t type) -{ - LV_ASSERT_OBJ(ta, LV_OBJX_NAME); - - const lv_style_t * style = NULL; - lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); - - switch(type) { - case LV_TA_STYLE_BG: style = lv_page_get_style(ta, LV_PAGE_STYLE_BG); break; - case LV_TA_STYLE_SB: style = lv_page_get_style(ta, LV_PAGE_STYLE_SB); break; - case LV_TA_STYLE_EDGE_FLASH: style = lv_page_get_style(ta, LV_PAGE_STYLE_EDGE_FLASH); break; - case LV_TA_STYLE_CURSOR: style = ext->cursor.style; break; - case LV_TA_STYLE_PLACEHOLDER: - if(ext->placeholder) style = lv_label_get_style(ext->placeholder, LV_LABEL_STYLE_MAIN); - break; - default: style = NULL; break; - } - - return style; -} - /** * Find whether text is selected or not. * @param ta Text area object @@ -1265,10 +1209,11 @@ void lv_ta_cursor_down(lv_obj_t * ta) lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos); /*Increment the y with one line and keep the valid x*/ - const lv_style_t * label_style = lv_obj_get_style(ext->label); - const lv_font_t * font_p = label_style->text.font; - lv_coord_t font_h = lv_font_get_line_height(font_p); - pos.y += font_h + label_style->text.line_space + 1; + + lv_style_value_t line_space = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_LINE_SPACE); + const lv_font_t * font = lv_obj_get_style_ptr(ta, LV_TA_PART_BG, LV_STYLE_FONT); + lv_coord_t font_h = lv_font_get_line_height(font); + pos.y += font_h + line_space + 1; pos.x = ext->cursor.valid_x; /*Do not go below the last line*/ @@ -1297,15 +1242,15 @@ void lv_ta_cursor_up(lv_obj_t * ta) lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos); /*Decrement the y with one line and keep the valid x*/ - const lv_style_t * label_style = lv_obj_get_style(ext->label); - const lv_font_t * font = label_style->text.font; + lv_style_value_t line_space = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_LINE_SPACE); + const lv_font_t * font = lv_obj_get_style_ptr(ta, LV_TA_PART_BG, LV_STYLE_FONT); lv_coord_t font_h = lv_font_get_line_height(font); - pos.y -= font_h + label_style->text.line_space - 1; + pos.y -= font_h + line_space - 1; pos.x = ext->cursor.valid_x; /*Get the letter index on the new cursor position and set it*/ uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos); - lv_coord_t cur_valid_x_tmp = ext->cursor.valid_x; /*Cursor position set overwrites the valid positon */ + lv_coord_t cur_valid_x_tmp = ext->cursor.valid_x; /*Cursor position set overwrites the valid position */ lv_ta_set_cursor_pos(ta, new_cur_pos); ext->cursor.valid_x = cur_valid_x_tmp; } @@ -1368,8 +1313,9 @@ static lv_design_res_t lv_ta_scrollable_design(lv_obj_t * scrl, const lv_area_t return true; /*The cursor is not visible now*/ } - lv_style_t cur_style; - get_cursor_style(ta, &cur_style); + lv_draw_rect_dsc_t cur_dsc; + lv_draw_rect_dsc_init(&cur_dsc); + lv_obj_init_draw_rect_dsc(ta, LV_TA_PART_CURSOR, &cur_dsc); const char * txt = lv_label_get_text(ext->label); @@ -1382,26 +1328,38 @@ static lv_design_res_t lv_ta_scrollable_design(lv_obj_t * scrl, const lv_area_t cur_area.x2 += ext->label->coords.x1; cur_area.y2 += ext->label->coords.y1; - lv_opa_t opa_scale = lv_obj_get_opa_scale(ta); if(ext->cursor.type == LV_CURSOR_LINE) { - lv_draw_rect(&cur_area, clip_area, &cur_style, opa_scale); + + lv_draw_line_dsc_t cur_line_dsc; + lv_draw_line_dsc_init(&cur_line_dsc); + lv_obj_init_draw_line_dsc(ta, LV_TA_PART_CURSOR, &cur_line_dsc); + cur_dsc.bg_color = cur_line_dsc.color; + cur_dsc.bg_opa = cur_line_dsc.opa; + cur_dsc.bg_blend_mode = cur_line_dsc.blend_mode; + lv_draw_rect(&cur_area, clip_area, &cur_dsc); } else if(ext->cursor.type == LV_CURSOR_BLOCK) { - lv_draw_rect(&cur_area, clip_area, &cur_style, opa_scale); + lv_draw_rect(&cur_area, clip_area, &cur_dsc); char letter_buf[8] = {0}; memcpy(letter_buf, &txt[ext->cursor.txt_byte_pos], lv_txt_encoded_size(&txt[ext->cursor.txt_byte_pos])); - cur_area.x1 += cur_style.body.padding.left; - cur_area.y1 += cur_style.body.padding.top; - lv_draw_label(&cur_area, clip_area, &cur_style, opa_scale, letter_buf, LV_TXT_FLAG_NONE, NULL, NULL, NULL, lv_obj_get_base_dir(ta)); + lv_style_value_t left = lv_obj_get_style_value(ta, LV_TA_PART_CURSOR, LV_STYLE_PAD_LEFT); + lv_style_value_t top = lv_obj_get_style_value(ta, LV_TA_PART_CURSOR, LV_STYLE_PAD_TOP); + cur_area.x1 += left; + cur_area.y1 += top; + + lv_draw_label_dsc_t cur_label_dsc; + lv_draw_label_dsc_init(&cur_label_dsc); + lv_obj_init_draw_label_dsc(ta, LV_TA_PART_CURSOR, &cur_label_dsc); + lv_draw_label(&cur_area, clip_area, &cur_label_dsc, letter_buf, NULL); } else if(ext->cursor.type == LV_CURSOR_OUTLINE) { - cur_style.body.opa = LV_OPA_TRANSP; - if(cur_style.body.border.width == 0) cur_style.body.border.width = 1; /*Be sure the border will be drawn*/ - lv_draw_rect(&cur_area, clip_area, &cur_style, opa_scale); + cur_dsc.bg_opa = LV_OPA_TRANSP; + if(cur_dsc.border_width == 0) cur_dsc.border_width = 1; /*Be sure the border will be drawn*/ + lv_draw_rect(&cur_area, clip_area, &cur_dsc); } else if(ext->cursor.type == LV_CURSOR_UNDERLINE) { - lv_draw_rect(&cur_area, clip_area, &cur_style, opa_scale); + lv_draw_rect(&cur_area, clip_area, &cur_dsc); } } @@ -1418,6 +1376,12 @@ static lv_design_res_t lv_ta_scrollable_design(lv_obj_t * scrl, const lv_area_t static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) { lv_res_t res; + if(sign == LV_SIGNAL_GET_STYLE) { + uint8_t ** type_p = param; + lv_style_dsc_t ** style_dsc_p = param; + *style_dsc_p = lv_ta_get_style(ta, **type_p); + return LV_RES_OK; + } /* Include the ancient signal function */ res = ancestor_signal(ta, sign, param); @@ -1431,38 +1395,34 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) /* (The created label will be deleted automatically) */ } else if(sign == LV_SIGNAL_STYLE_CHG) { if(ext->label) { - lv_obj_t * scrl = lv_page_get_scrl(ta); - const lv_style_t * style_ta = lv_obj_get_style(ta); - const lv_style_t * style_scrl = lv_obj_get_style(scrl); if(ext->one_line) { + lv_style_value_t top = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_TOP); + lv_style_value_t bottom = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_PAD_BOTTOM); + const lv_font_t * font = lv_obj_get_style_ptr(ta, LV_TA_PART_BG, LV_STYLE_FONT); + /*In one line mode refresh the Text Area height because 'vpad' can modify it*/ - const lv_style_t * style_label = lv_obj_get_style(ext->label); - lv_coord_t font_h = lv_font_get_line_height(style_label->text.font); + lv_coord_t font_h = lv_font_get_line_height(font); lv_obj_set_height(ext->label, font_h); - lv_obj_set_height(ta, font_h + style_ta->body.padding.top + style_ta->body.padding.bottom + - style_scrl->body.padding.top + style_scrl->body.padding.bottom); + lv_obj_set_height(ta, font_h + top + bottom); } else { /*In not one line mode refresh the Label width because 'hpad' can modify it*/ lv_obj_set_width(ext->label, lv_page_get_fit_width(ta)); - lv_obj_set_pos(ext->label, style_scrl->body.padding.left, - style_scrl->body.padding.right); /*Be sure the Label is in the correct position*/ + lv_obj_set_pos(ext->label, 0, 0); /*Be sure the Label is in the correct position*/ if(ext->placeholder) { lv_obj_set_width(ext->placeholder, lv_page_get_fit_width(ta)); - lv_obj_set_pos(ext->placeholder, style_scrl->body.padding.left, - style_scrl->body.padding.top); /*Be sure the placeholder is in the correct position*/ + lv_obj_set_pos(ext->placeholder, 0, 0); /*Be sure the placeholder is in the correct position*/ } } lv_label_set_text(ext->label, NULL); + refr_cursor_area(ta); } } else if(sign == LV_SIGNAL_CORD_CHG) { /*Set the label width according to the text area width*/ if(ext->label) { if(lv_obj_get_width(ta) != lv_area_get_width(param) || lv_obj_get_height(ta) != lv_area_get_height(param)) { - lv_obj_t * scrl = lv_page_get_scrl(ta); - const lv_style_t * style_scrl = lv_obj_get_style(scrl); lv_obj_set_width(ext->label, lv_page_get_fit_width(ta)); - lv_obj_set_pos(ext->label, style_scrl->body.padding.left, style_scrl->body.padding.top); + lv_obj_set_pos(ext->label, 0, 0); lv_label_set_text(ext->label, NULL); /*Refresh the label*/ refr_cursor_area(ta); @@ -1471,10 +1431,8 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) /*Set the placeholder width according to the text area width*/ if(ext->placeholder) { if(lv_obj_get_width(ta) != lv_area_get_width(param) || lv_obj_get_height(ta) != lv_area_get_height(param)) { - lv_obj_t * scrl = lv_page_get_scrl(ta); - const lv_style_t * style_scrl = lv_obj_get_style(scrl); lv_obj_set_width(ext->placeholder, lv_page_get_fit_width(ta)); - lv_obj_set_pos(ext->placeholder, style_scrl->body.padding.left, style_scrl->body.padding.top); + lv_obj_set_pos(ext->placeholder, 0, 0); lv_label_set_text(ext->placeholder, NULL); /*Refresh the label*/ refr_cursor_area(ta); @@ -1554,18 +1512,18 @@ static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { /*Set ext. size because the cursor might be out of this object*/ - const lv_style_t * style_label = lv_obj_get_style(ext->label); - lv_coord_t font_h = lv_font_get_line_height(style_label->text.font); - scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, style_label->text.line_space + font_h); + lv_style_value_t line_space = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_LINE_SPACE); + const lv_font_t * font = lv_obj_get_style_ptr(ta, LV_TA_PART_BG, LV_STYLE_FONT); + lv_coord_t font_h = lv_font_get_line_height(font); + scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, line_space + font_h); } else if(sign == LV_SIGNAL_CORD_CHG) { /*Set the label width according to the text area width*/ if(ext->label) { if(lv_obj_get_width(scrl) != lv_area_get_width(param) || lv_obj_get_height(scrl) != lv_area_get_height(param)) { - const lv_style_t * style_scrl = lv_obj_get_style(scrl); lv_obj_set_width(ext->label, lv_page_get_fit_width(ta)); - lv_obj_set_pos(ext->label, style_scrl->body.padding.left, style_scrl->body.padding.top); + lv_obj_set_pos(ext->label, 0, 0); lv_label_set_text(ext->label, NULL); /*Refresh the label*/ refr_cursor_area(ta); @@ -1579,6 +1537,41 @@ static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void return res; } +/** + * Get the style descriptor of a part of the object + * @param page pointer the object + * @param part the part from `lv_ta_part_t`. (LV_TA_PART_...) + * @return pointer to the style descriptor of the specified part + */ +static lv_style_dsc_t * lv_ta_get_style(lv_obj_t * ta, uint8_t part) +{ + LV_ASSERT_OBJ(ta, LV_OBJX_NAME); + + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + lv_style_dsc_t * style_dsc_p; + + switch(part) { + case LV_PAGE_PART_BG: + style_dsc_p = &ta->style_dsc; + break; + case LV_PAGE_PART_SCRL: + style_dsc_p = lv_obj_get_style(ext->page.scrl, LV_CONT_PART_MAIN); + break; + case LV_PAGE_PART_SCRLBAR: + style_dsc_p = &ext->page.sb.style; + break; +#if LV_USE_ANIMATION + case LV_PAGE_PART_EDGE_FLASH: + style_dsc_p = &ext->page.edge_flash.style; + break; +#endif + default: + style_dsc_p = NULL; + } + + return style_dsc_p; +} + #if LV_USE_ANIMATION /** @@ -1684,43 +1677,13 @@ static bool char_is_accepted(lv_obj_t * ta, uint32_t c) } } -static void get_cursor_style(lv_obj_t * ta, lv_style_t * style_res) -{ - lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); - const lv_style_t * label_style = lv_obj_get_style(ext->label); - - if(ext->cursor.style) { - lv_style_copy(style_res, ext->cursor.style); - } else { - /*If cursor style is not specified then use the modified label style */ - lv_style_copy(style_res, label_style); - lv_color_t clv_color_tmp = style_res->text.color; /*Make letter color to cursor color*/ - style_res->text.color = - style_res->body.main_color; /*In block mode the letter color will be current background color*/ - style_res->body.main_color = clv_color_tmp; - style_res->body.grad_color = clv_color_tmp; - style_res->body.border.color = clv_color_tmp; - style_res->body.border.opa = LV_OPA_COVER; - style_res->body.border.width = 1; - style_res->body.shadow.width = 0; - style_res->body.radius = 0; - style_res->body.opa = LV_OPA_COVER; - style_res->body.padding.left = 0; - style_res->body.padding.right = 0; - style_res->body.padding.top = 0; - style_res->body.padding.bottom = 0; - style_res->line.width = 1; - } -} static void refr_cursor_area(lv_obj_t * ta) { lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); - const lv_style_t * label_style = lv_obj_get_style(ext->label); - - lv_style_t cur_style; - get_cursor_style(ta, &cur_style); + const lv_font_t * font = lv_obj_get_style_ptr(ta, LV_TA_PART_BG, LV_STYLE_FONT); + lv_style_value_t line_space = lv_obj_get_style_value(ta, LV_TA_PART_BG, LV_STYLE_LINE_SPACE); uint16_t cur_pos = lv_ta_get_cursor_pos(ta); const char * txt = lv_label_get_text(ext->label); @@ -1730,15 +1693,15 @@ static void refr_cursor_area(lv_obj_t * ta) uint32_t letter = lv_txt_encoded_next(&txt[byte_pos], NULL); - lv_coord_t letter_h = lv_font_get_line_height(label_style->text.font); + lv_coord_t letter_h = lv_font_get_line_height(font); /*Set letter_w (set not 0 on non printable but valid chars)*/ lv_coord_t letter_w; if(letter == '\0' || letter == '\n' || letter == '\r') { - letter_w = lv_font_get_glyph_width(label_style->text.font, ' ', '\0'); + letter_w = lv_font_get_glyph_width(font, ' ', '\0'); } else { /*`letter_next` parameter is '\0' to ignore kerning*/ - letter_w = lv_font_get_glyph_width(label_style->text.font, letter, '\0'); + letter_w = lv_font_get_glyph_width(font, letter, '\0'); } lv_point_t letter_pos; @@ -1748,7 +1711,7 @@ static void refr_cursor_area(lv_obj_t * ta) if(letter_pos.x + ext->label->coords.x1 + letter_w > ext->label->coords.x2 && ext->one_line == 0 && lv_label_get_align(ext->label) != LV_LABEL_ALIGN_RIGHT) { letter_pos.x = 0; - letter_pos.y += letter_h + label_style->text.line_space; + letter_pos.y += letter_h + line_space; if(letter != '\0') { byte_pos += lv_txt_encoded_size(&txt[byte_pos]); @@ -1756,41 +1719,57 @@ static void refr_cursor_area(lv_obj_t * ta) } if(letter == '\0' || letter == '\n' || letter == '\r') { - letter_w = lv_font_get_glyph_width(label_style->text.font, ' ', '\0'); + letter_w = lv_font_get_glyph_width(font, ' ', '\0'); } else { - letter_w = lv_font_get_glyph_width(label_style->text.font, letter, '\0'); + letter_w = lv_font_get_glyph_width(font, letter, '\0'); } } /*Save the byte position. It is required to draw `LV_CURSOR_BLOCK`*/ ext->cursor.txt_byte_pos = byte_pos; - /*Draw he cursor according to the type*/ + /*Calculate the cursor according to its type*/ + + lv_style_value_t top = lv_obj_get_style_value(ta, LV_TA_PART_CURSOR, LV_STYLE_PAD_TOP); + lv_style_value_t bottom = lv_obj_get_style_value(ta, LV_TA_PART_CURSOR, LV_STYLE_PAD_BOTTOM); + lv_style_value_t left = lv_obj_get_style_value(ta, LV_TA_PART_CURSOR, LV_STYLE_PAD_LEFT); + lv_style_value_t right = lv_obj_get_style_value(ta, LV_TA_PART_CURSOR, LV_STYLE_PAD_RIGHT); + lv_area_t cur_area; if(ext->cursor.type == LV_CURSOR_LINE) { + + lv_draw_line_dsc_t cur_dsc; + lv_draw_line_dsc_init(&cur_dsc); + lv_obj_init_draw_line_dsc(ta, LV_TA_PART_CURSOR, &cur_dsc); + cur_area.x1 = - letter_pos.x + cur_style.body.padding.left - (cur_style.line.width >> 1) - (cur_style.line.width & 0x1); - cur_area.y1 = letter_pos.y + cur_style.body.padding.top; - cur_area.x2 = letter_pos.x + cur_style.body.padding.right + (cur_style.line.width >> 1); - cur_area.y2 = letter_pos.y + cur_style.body.padding.bottom + letter_h; + letter_pos.x + left - (cur_dsc.width >> 1) - (cur_dsc.width & 0x1); + cur_area.y1 = letter_pos.y + top; + cur_area.x2 = letter_pos.x + right + (cur_dsc.width >> 1); + cur_area.y2 = letter_pos.y + bottom + letter_h; } else if(ext->cursor.type == LV_CURSOR_BLOCK) { - cur_area.x1 = letter_pos.x - cur_style.body.padding.left; - cur_area.y1 = letter_pos.y - cur_style.body.padding.top; - cur_area.x2 = letter_pos.x + cur_style.body.padding.right + letter_w; - cur_area.y2 = letter_pos.y + cur_style.body.padding.bottom + letter_h; + cur_area.x1 = letter_pos.x - left; + cur_area.y1 = letter_pos.y - top; + cur_area.x2 = letter_pos.x + right + letter_w; + cur_area.y2 = letter_pos.y + bottom + letter_h; } else if(ext->cursor.type == LV_CURSOR_OUTLINE) { - cur_area.x1 = letter_pos.x - cur_style.body.padding.left; - cur_area.y1 = letter_pos.y - cur_style.body.padding.top; - cur_area.x2 = letter_pos.x + cur_style.body.padding.right + letter_w; - cur_area.y2 = letter_pos.y + cur_style.body.padding.bottom + letter_h; + cur_area.x1 = letter_pos.x - left; + cur_area.y1 = letter_pos.y - top; + cur_area.x2 = letter_pos.x + right + letter_w; + cur_area.y2 = letter_pos.y + bottom + letter_h; } else if(ext->cursor.type == LV_CURSOR_UNDERLINE) { - cur_area.x1 = letter_pos.x + cur_style.body.padding.left; - cur_area.y1 = letter_pos.y + cur_style.body.padding.top + letter_h - (cur_style.line.width >> 1); - cur_area.x2 = letter_pos.x + cur_style.body.padding.right + letter_w; - cur_area.y2 = letter_pos.y + cur_style.body.padding.bottom + letter_h + (cur_style.line.width >> 1) + - (cur_style.line.width & 0x1); + lv_draw_line_dsc_t cur_dsc; + lv_draw_line_dsc_init(&cur_dsc); + lv_obj_init_draw_line_dsc(ta, LV_TA_PART_CURSOR, &cur_dsc); + + + cur_area.x1 = letter_pos.x + left; + cur_area.y1 = letter_pos.y + top + letter_h - (cur_dsc.width >> 1); + cur_area.x2 = letter_pos.x + right + letter_w; + cur_area.y2 = letter_pos.y + bottom + letter_h + (cur_dsc.width >> 1) + + (cur_dsc.width & 0x1); } else if(ext->cursor.type == LV_CURSOR_NONE) { cur_area.x1 = letter_pos.x; cur_area.y1 = letter_pos.y; @@ -1829,10 +1808,8 @@ static void placeholder_update(lv_obj_t * ta) if(ta_text[0] == '\0') { /*Be sure the main label and the placeholder has the same coordinates*/ - lv_obj_t * scrl = lv_page_get_scrl(ta); - const lv_style_t * style_scrl = lv_obj_get_style(scrl); - lv_obj_set_pos(ext->placeholder, style_scrl->body.padding.left, style_scrl->body.padding.top); - lv_obj_set_pos(ext->label, style_scrl->body.padding.left, style_scrl->body.padding.top); + lv_obj_set_pos(ext->placeholder, 0, 0); + lv_obj_set_pos(ext->label, 0, 0); lv_obj_set_width(ext->placeholder, lv_page_get_fit_width(ta)); lv_obj_set_hidden(ext->placeholder, false); @@ -1891,13 +1868,13 @@ static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_ if(ext->text_sel_en) { if(!ext->text_sel_in_prog && !click_outside_label && sign == LV_SIGNAL_PRESSED) { /*Input device just went down. Store the selection start position*/ - ext->sel.start = char_id_at_click; - ext->sel.end = LV_LABEL_TEXT_SEL_OFF; + ext->sel_start = char_id_at_click; + ext->sel_end = LV_LABEL_TEXT_SEL_OFF; ext->text_sel_in_prog = 1; lv_obj_set_drag(lv_page_get_scrl(ta), false); } else if(ext->text_sel_in_prog && sign == LV_SIGNAL_PRESSING) { /*Input device may be moving. Store the end position */ - ext->sel.end = char_id_at_click; + ext->sel_end = char_id_at_click; } else if(ext->text_sel_in_prog && (sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_RELEASED)) { /*Input device is released. Check if anything was selected.*/ lv_obj_set_drag(lv_page_get_scrl(ta), true); @@ -1910,22 +1887,22 @@ static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_ /*If the selected area has changed then update the real values and*/ /*Invalidate the text area.*/ - if(ext->sel.start > ext->sel.end) { - if(ext_label->txt_sel.start != ext->sel.end || ext_label->txt_sel.end != ext->sel.start) { - ext_label->txt_sel.start = ext->sel.end; - ext_label->txt_sel.end = ext->sel.start; + if(ext->sel_start > ext->sel_end) { + if(ext_label->sel_start != ext->sel_end || ext_label->sel_end != ext->sel_start) { + ext_label->sel_start = ext->sel_end; + ext_label->sel_end = ext->sel_start; lv_obj_invalidate(ta); } - } else if(ext->sel.start < ext->sel.end) { - if(ext_label->txt_sel.start != ext->sel.start || ext_label->txt_sel.end != ext->sel.end) { - ext_label->txt_sel.start = ext->sel.start; - ext_label->txt_sel.end = ext->sel.end; + } else if(ext->sel_start < ext->sel_end) { + if(ext_label->sel_start != ext->sel_start || ext_label->sel_end != ext->sel_end) { + ext_label->sel_start = ext->sel_start; + ext_label->sel_end = ext->sel_end; lv_obj_invalidate(ta); } } else { - if(ext_label->txt_sel.start != LV_DRAW_LABEL_NO_TXT_SEL || ext_label->txt_sel.end != LV_DRAW_LABEL_NO_TXT_SEL) { - ext_label->txt_sel.start = LV_DRAW_LABEL_NO_TXT_SEL; - ext_label->txt_sel.end = LV_DRAW_LABEL_NO_TXT_SEL; + if(ext_label->sel_start != LV_DRAW_LABEL_NO_TXT_SEL || ext_label->sel_end != LV_DRAW_LABEL_NO_TXT_SEL) { + ext_label->sel_start = LV_DRAW_LABEL_NO_TXT_SEL; + ext_label->sel_end = LV_DRAW_LABEL_NO_TXT_SEL; lv_obj_invalidate(ta); } } diff --git a/src/lv_objx/lv_ta.h b/src/lv_objx/lv_ta.h index 8ad840c80..8213d8831 100644 --- a/src/lv_objx/lv_ta.h +++ b/src/lv_objx/lv_ta.h @@ -78,7 +78,8 @@ typedef struct uint8_t click_pos : 1; /*1: Enable positioning the cursor by clicking the text area*/ } cursor; #if LV_LABEL_TEXT_SEL - lv_draw_label_txt_sel_t sel; /*Temporary values for text selection*/ + uint16_t sel_start; /*Temporary values for text selection*/ + uint16_t sel_end; uint8_t text_sel_in_prog : 1; /*User is in process of selecting */ uint8_t text_sel_en : 1; /*Text can be selected on this text area*/ #endif @@ -88,11 +89,11 @@ typedef struct /** Possible text areas tyles. */ enum { - LV_TA_STYLE_BG, /**< Text area background style */ - LV_TA_STYLE_SB, /**< Scrollbar style */ - LV_TA_STYLE_CURSOR, /**< Cursor style */ - LV_TA_STYLE_EDGE_FLASH, /**< Edge flash style */ - LV_TA_STYLE_PLACEHOLDER, /**< Placeholder style */ + LV_TA_PART_BG, /**< Text area background style */ + LV_TA_PART_SB, /**< Scrollbar style */ + LV_TA_PART_CURSOR, /**< Cursor style */ + LV_TA_PART_EDGE_FLASH, /**< Edge flash style */ + LV_TA_PART_PLACEHOLDER, /**< Placeholder style */ }; typedef uint8_t lv_ta_style_t; @@ -258,14 +259,6 @@ static inline void lv_ta_set_edge_flash(lv_obj_t * ta, bool en) lv_page_set_edge_flash(ta, en); } -/** - * Set a style of a text area - * @param ta pointer to a text area object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_ta_set_style(lv_obj_t * ta, lv_ta_style_t type, const lv_style_t * style); - /** * Enable/disable selection mode. * @param ta pointer to a text area object @@ -391,14 +384,6 @@ static inline bool lv_ta_get_edge_flash(lv_obj_t * ta) return lv_page_get_edge_flash(ta); } -/** - * Get a style of a text area - * @param ta pointer to a text area object - * @param type which style should be get - * @return style pointer to a style - */ -const lv_style_t * lv_ta_get_style(const lv_obj_t * ta, lv_ta_style_t type); - /** * Find whether text is selected or not. * @param ta Text area object diff --git a/src/lv_objx/lv_tabview.c b/src/lv_objx/lv_tabview.c index 37025881b..4b5b3e53f 100644 --- a/src/lv_objx/lv_tabview.c +++ b/src/lv_objx/lv_tabview.c @@ -743,7 +743,7 @@ static lv_style_dsc_t * lv_tabview_get_style(lv_obj_t * tabview, uint8_t part) style_dsc_p = lv_obj_get_style(ext->content, LV_PAGE_PART_SCRL); break; case LV_TABVIEW_PART_BTNS_BG: - style_dsc_p = lv_obj_get_style(ext->btns, LV_BTNM_PART_MAIN); + style_dsc_p = lv_obj_get_style(ext->btns, LV_BTNM_PART_BG); break; case LV_TABVIEW_PART_BTNS: style_dsc_p = lv_obj_get_style(ext->btns, LV_BTNM_PART_BTN); diff --git a/src/lv_themes/lv_theme.h b/src/lv_themes/lv_theme.h index a3fa7bba7..7f990b29e 100644 --- a/src/lv_themes/lv_theme.h +++ b/src/lv_themes/lv_theme.h @@ -92,6 +92,10 @@ typedef enum { LV_THEME_GAUGE, LV_THEME_GAUGE_STRONG, + + LV_THEME_TA, + LV_THEME_TA_CURSOR, + LV_THEME_TA_SCRLBAR, }lv_theme_style_t; typedef struct { diff --git a/src/lv_themes/lv_theme_alien.c b/src/lv_themes/lv_theme_alien.c index 6db3bb90a..dcac6bac6 100644 --- a/src/lv_themes/lv_theme_alien.c +++ b/src/lv_themes/lv_theme_alien.c @@ -57,6 +57,10 @@ static lv_style_t gauge_strong; static lv_style_t ddlist_bg, ddlist_sel; #endif +#if LV_USE_TA +static lv_style_t ta_cursor; +#endif + /********************** * MACROS **********************/ @@ -101,6 +105,7 @@ static void basic_init(void) lv_style_set_color(&btn, LV_STYLE_BG_COLOR, LV_COLOR_RED); lv_style_set_color(&btn, LV_STYLE_BG_GRAD_COLOR, LV_COLOR_MAROON); lv_style_set_color(&btn, LV_STYLE_BORDER_COLOR, LV_COLOR_NAVY); + lv_style_set_color(&btn, LV_STYLE_BORDER_COLOR | LV_STYLE_STATE_FOCUS, LV_COLOR_AQUA); lv_style_set_color(&btn, LV_STYLE_BG_GRAD_COLOR | LV_STYLE_STATE_PRESSED, LV_COLOR_LIME); lv_style_set_color(&btn, LV_STYLE_BG_COLOR | LV_STYLE_STATE_CHECKED, LV_COLOR_BLUE); lv_style_set_color(&btn, LV_STYLE_TEXT_COLOR, LV_COLOR_WHITE); @@ -109,7 +114,6 @@ static void basic_init(void) // lv_style_set_opa(&btn, LV_STYLE_TEXT_OPA, LV_OPA_50); // lv_style_set_value(&btn, LV_STYLE_SHADOW_WIDTH, 5); // lv_style_set_value(&btn, LV_STYLE_SHADOW_OFFSET_Y, 10); - lv_style_set_color(&btn, LV_STYLE_BORDER_COLOR | LV_STYLE_STATE_FOCUS, LV_COLOR_AQUA); lv_style_set_value(&btn, LV_STYLE_BORDER_WIDTH | LV_STYLE_STATE_FOCUS, 6); lv_style_set_ptr(&btn, LV_STYLE_PATTERN_IMAGE | LV_STYLE_STATE_CHECKED, LV_SYMBOL_OK); lv_style_set_value(&btn, LV_STYLE_PATTERN_REPEATE | LV_STYLE_STATE_CHECKED, 1); @@ -442,12 +446,6 @@ static void btnm_init(void) static void kb_init(void) { #if LV_USE_KB - theme.style.kb.bg = &btnm_bg; - theme.style.kb.btn.rel = &btnm_rel; - theme.style.kb.btn.pr = &btnm_pr; - theme.style.kb.btn.tgl_rel = &btnm_trel; - theme.style.kb.btn.tgl_pr = &btnm_pr; - theme.style.kb.btn.ina = &btnm_ina; #endif } @@ -477,10 +475,11 @@ static void page_init(void) static void ta_init(void) { #if LV_USE_TA - theme.style.ta.area = &panel; - theme.style.ta.oneline = &panel; - theme.style.ta.cursor = NULL; - theme.style.ta.sb = &sb; + lv_style_init(&ta_cursor); + lv_style_set_color(&ta_cursor, LV_STYLE_LINE_COLOR, LV_COLOR_LIME); + lv_style_set_color(&ta_cursor, LV_STYLE_BG_COLOR, LV_COLOR_RED); + lv_style_set_value(&ta_cursor, LV_STYLE_LINE_WIDTH, 3); +// lv_style_set_color(&ta_cursor, LV_STYLE_LINE_COLOR, LV_COLOR_RED); #endif } @@ -716,6 +715,8 @@ lv_style_t * lv_theme_alien_get_style(lv_theme_style_t name) return &gauge; case LV_THEME_GAUGE_STRONG: return &gauge_strong; + case LV_THEME_TA_CURSOR: + return &ta_cursor; } return NULL;