BigW Consortium Gitlab

Commit 07775613 by Gabor Kiss-Vamosi

lv_ta: utf8 update

parents 0c473c6c 974540cc
......@@ -372,7 +372,7 @@ bool lv_label_get_recolor(lv_obj_t * label)
/**
* Get the relative x and y coordinates of a letter
* @param label pointer to a label object
* @param index index of the letter (0 ... text length)
* @param index index of the letter [0 ... text length]. Expressed in character index, not byte index (different in UTF-8)
* @param pos store the result here (E.g. index = 0 gives 0;0 coordinates)
*/
void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
......@@ -397,6 +397,8 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
max_w = CORD_MAX;
}
index = txt_utf8_get_id(txt, index);
/*Search the line of the index letter */;
while (txt[new_line_start] != '\0') {
new_line_start += txt_get_next_line(&txt[line_start], font, style->letter_space, max_w, flag);
......@@ -406,7 +408,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 the last character is line 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;
......@@ -419,8 +421,8 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
txt_cmd_state_t cmd_state = TXT_CMD_STATE_WAIT;
uint32_t letter;
while(cnt < index) {
cnt += txt_utf8_size(txt[i]);
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) {
......
......@@ -31,7 +31,6 @@
static void lv_page_sb_refresh(lv_obj_t * main);
static bool lv_page_design(lv_obj_t * scrl, const area_t * mask, lv_design_mode_t mode);
static bool lv_scrl_design(lv_obj_t * scrl, const area_t * mask, lv_design_mode_t mode);
static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param);
/**********************
* STATIC VARIABLES
......@@ -82,7 +81,7 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy)
lv_style_t * style = lv_style_get(LV_STYLE_PRETTY_COLOR, NULL);
ext->scrl = lv_cont_create(new_page, NULL);
if(ancestor_scrl_design_f == NULL) ancestor_scrl_design_f = lv_obj_get_design_f(ext->scrl);
lv_obj_set_signal_f(ext->scrl, lv_scrl_signal);
lv_obj_set_signal_f(ext->scrl, lv_page_scrl_signal);
lv_obj_set_drag(ext->scrl, true);
lv_obj_set_drag_throw(ext->scrl, true);
lv_obj_set_protect(ext->scrl, LV_PROTECT_PARENT);
......@@ -102,7 +101,7 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy)
} else {
lv_page_ext_t * copy_ext = lv_obj_get_ext(copy);
ext->scrl = lv_cont_create(new_page, copy_ext->scrl);
lv_obj_set_signal_f(ext->scrl, lv_scrl_signal);
lv_obj_set_signal_f(ext->scrl, lv_page_scrl_signal);
lv_page_set_pr_action(new_page, copy_ext->pr_action);
lv_page_set_rel_action(new_page, copy_ext->rel_action);
......@@ -209,7 +208,7 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param)
bool lv_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
{
bool obj_valid = true;
......
......@@ -80,6 +80,14 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy);
bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param);
/**
* Signal function of the scrollable part of a page
* @param scrl pointer to the scrollable object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
bool lv_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
/**
* Set a release action for the page
* @param page pointer to a page object
* @param rel_action a function to call when the page is released
......
......@@ -15,6 +15,7 @@
#include "../lv_draw/lv_draw.h"
#include "misc/gfx/anim.h"
#include "misc/gfx/text.h"
#include "misc/math/math_base.h"
/*********************
* DEFINES
......@@ -43,7 +44,7 @@
* STATIC PROTOTYPES
**********************/
static bool lv_ta_design(lv_obj_t * ta, const area_t * mask, lv_design_mode_t mode);
static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_design_mode_t mode);
static bool lv_ta_scrling_design(lv_obj_t * scrl, const area_t * mask, lv_design_mode_t mode);
static void cursor_blink_anim(lv_obj_t * ta, uint8_t show);
static void pwd_char_hider_anim(lv_obj_t * ta, int32_t x);
static void pwd_char_hider(lv_obj_t * ta);
......@@ -96,6 +97,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
if(scrl_design_f == NULL) scrl_design_f = lv_obj_get_design_f(ext->page.scrl);
lv_obj_set_signal_f(new_ta, lv_ta_signal);
lv_obj_set_signal_f(lv_page_get_scrl(new_ta), lv_ta_scrl_signal);
lv_obj_set_design_f(new_ta, lv_ta_design);
/*Init the new text area object*/
......@@ -120,6 +122,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
ext->cursor_show = copy_ext->cursor_show;
ext->pwd_mode = copy_ext->pwd_mode;
lv_page_glue_obj(ext->label, true);
if(copy_ext->one_line) lv_ta_set_one_line(new_ta, true);
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_ta);
......@@ -173,6 +176,8 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->hpad);
lv_obj_set_pos(ext->label, style_scrl->hpad, style_scrl->vpad);
lv_label_set_text(ext->label, NULL);
lv_obj_refr_ext_size(lv_page_get_scrl(ta));
}
} else if(sign == LV_SIGNAL_CORD_CHG) {
/*Set the label width according to the text area width*/
......@@ -186,7 +191,8 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
lv_label_set_text(ext->label, NULL); /*Refresh the label*/
}
}
} else if (sign == LV_SIGNAL_CONTROLL) {
}
else if (sign == LV_SIGNAL_CONTROLL) {
char c = *((char*)param);
if(c == LV_GROUP_KEY_RIGHT) {
lv_ta_cursor_right(ta);
......@@ -202,6 +208,34 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
return valid;
}
/**
* Signal function of the scrollable part of the text area
* @param scrl pointer to scrollable part of a text area 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_ta_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
{
bool valid;
/* Include the ancient signal function */
valid = lv_page_scrl_signal(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_REFR_EXT_SIZE) {
/*Set ext. size because the cursor might be out of this object*/
lv_obj_t * ta = lv_obj_get_parent(scrl);
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
lv_style_t * style_label = lv_obj_get_style(ext->label);
scrl->ext_size = MATH_MAX(scrl->ext_size, style_label->line_space + font_get_height(style_label->font));
}
}
return valid;
}
/*=====================
* Setter functions
*====================*/
......@@ -641,6 +675,7 @@ void lv_ta_set_one_line(lv_obj_t * ta, bool en)
lv_style_t * style_label = lv_obj_get_style(ext->label);
cord_t font_h = font_get_height(style_label->font) >> FONT_ANTIALIAS;
ext->one_line = 1;
lv_cont_set_fit(lv_page_get_scrl(ta), true, true);
lv_obj_set_height(ta, font_h + style_ta->vpad * 2);
lv_label_set_long_mode(ext->label, LV_LABEL_LONG_EXPAND);
......@@ -650,6 +685,7 @@ void lv_ta_set_one_line(lv_obj_t * ta, bool en)
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
lv_style_t * style_ta = lv_obj_get_style(ta);
ext->one_line = 0;
lv_cont_set_fit(lv_page_get_scrl(ta), false, true);
lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK);
lv_label_set_no_break(ext->label, false);
......@@ -779,8 +815,8 @@ static bool lv_ta_design(lv_obj_t * ta, const area_t * masp, lv_design_mode_t mo
}
/**
* An extended scrolling design of the page. Calls the normal design function and it draws a cursor.
* @param label pointer to a text area object
* 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 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)
......@@ -788,19 +824,19 @@ static bool lv_ta_design(lv_obj_t * ta, const area_t * masp, lv_design_mode_t mo
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
* @return return true/false, depends on 'mode'
*/
static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_design_mode_t mode)
static bool lv_ta_scrling_design(lv_obj_t * scrl, const area_t * mask, lv_design_mode_t mode)
{
if(mode == LV_DESIGN_COVER_CHK) {
/*Return false if the object is not covers the mask_p area*/
return scrl_design_f(scrling, mask, mode);
return scrl_design_f(scrl, mask, mode);
} else if(mode == LV_DESIGN_DRAW_MAIN) {
/*Draw the object*/
scrl_design_f(scrling, mask, mode);
scrl_design_f(scrl, mask, mode);
} else if(mode == LV_DESIGN_DRAW_POST) {
scrl_design_f(scrling, mask, mode);
scrl_design_f(scrl, mask, mode);
/*Draw the cursor too*/
lv_obj_t * ta = lv_obj_get_parent(scrling);
lv_obj_t * ta = lv_obj_get_parent(scrl);
lv_ta_ext_t * ta_ext = lv_obj_get_ext(ta);
if(ta_ext->cursor_show == 0 || ta_ext->cursor_state == 0) return true; /*The cursor is not visible now*/
......@@ -811,7 +847,8 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des
lv_style_cpy(&cur_style, ta_ext->cursor_style);
}
else {
lv_style_cpy(&cur_style, label_style); /*Use the label style is no better option and modify it */
/*If cursor style is not specified then use the modified label style */
lv_style_cpy(&cur_style, label_style);
color_t ccolor_tmp = cur_style.ccolor; /*Make letter color to cursor color*/
cur_style.ccolor = cur_style.mcolor; /*In block mode the letter color will be current background color*/
cur_style.mcolor = ccolor_tmp;
......@@ -837,11 +874,38 @@ 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);
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;
printf("letter1:%c, bp:%d\n", letter, byte_pos);
/*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, ' ');
} else {
letter_w = font_get_width(label_style->font, letter);
}
point_t letter_pos;
lv_label_get_letter_pos(ta_ext->label, cur_pos, &letter_pos);
/*If the cursor is out of the text (most right) draw it to the next line*/
if(letter_pos.x + ta_ext->label->cords.x1 + letter_w > ta_ext->label->cords.x2 && ta_ext->one_line == 0) {
letter_pos.x = 0;
letter_pos.y += letter_h + label_style->line_space;
if(letter != '\0'){
byte_pos += txt_utf8_size(txt[byte_pos]);
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 {
letter_w = font_get_width(label_style->font, letter);
}
}
/*Draw he cursor according to the type*/
area_t cur_area;
if(ta_ext->cursor_type == LV_TA_CURSOR_LINE) {
cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1;
......@@ -854,6 +918,7 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des
cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1;
cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + letter_w;
cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + letter_h;
lv_draw_rect(&cur_area, mask, &cur_style);
/*Get the current letter*/
......@@ -872,6 +937,7 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des
cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1;
cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + letter_w;
cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + letter_h;
cur_style.empty = 1;
if(cur_style.bwidth == 0) cur_style.bwidth = 1 * LV_DOWNSCALE; /*Be sure the border will be drawn*/
lv_draw_rect(&cur_area, mask, &cur_style);
......@@ -880,10 +946,10 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des
cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1 + letter_h - cur_style.line_width;
cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + letter_w;
cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + letter_h;
lv_draw_rect(&cur_area, mask, &cur_style);
}
}
return true;
......
......@@ -58,6 +58,7 @@ typedef struct
lv_ta_cursor_type_t cursor_type; /*Shape of the cursor*/
uint8_t cursor_show :1; /*Show or hide cursor */
uint8_t pwd_mode :1; /*Replace characters with '*' */
uint8_t one_line :1; /*One line mode (ignore line breaks)*/
uint8_t cursor_state :1; /*Indicates that the cursor is visible now or not (Handled by the library)*/
}lv_ta_ext_t;
......@@ -83,6 +84,15 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy);
bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param);
/**
* Signal function of the scrollable part of the text area
* @param scrl pointer to scrollable part of a text area 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_ta_scrl_signal(lv_obj_t * scrl, 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment