BigW Consortium Gitlab

Commit 445b5ad2 by Gabor Kiss-Vamosi

Merge branch 'new_objs' into beta

parents d6ccc489 315bf64c
...@@ -134,7 +134,6 @@ ...@@ -134,7 +134,6 @@
/*Text area (dependencies: lv_label, lv_page)*/ /*Text area (dependencies: lv_label, lv_page)*/
#define USE_LV_TA 1 #define USE_LV_TA 1
#if USE_LV_TA != 0 #if USE_LV_TA != 0
#define LV_TA_MAX_LENGTH 256
#define LV_TA_CUR_BLINK_TIME 400 /*ms*/ #define LV_TA_CUR_BLINK_TIME 400 /*ms*/
#define LV_TA_PWD_SHOW_TIME 1500 /*ms*/ #define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
#endif #endif
......
...@@ -64,14 +64,14 @@ static void point_swap(point_t * p1, point_t * p2); ...@@ -64,14 +64,14 @@ static void point_swap(point_t * p1, point_t * p2);
#if LV_VDB_SIZE != 0 #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 (*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 (*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 #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; 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 #endif
#else #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 (*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 (*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 #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; 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 #endif
...@@ -280,13 +280,15 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_ ...@@ -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*/ /*Write all letter of a line*/
cmd_state = CMD_STATE_WAIT; cmd_state = CMD_STATE_WAIT;
i = line_start;
for(i = line_start; i < line_end; i++) { uint32_t letter;
while(i < line_end) {
letter = txt_utf8_next(txt, &i);
/*Handle the re-color command*/ /*Handle the re-color command*/
if((flag & TXT_FLAG_RECOLOR) != 0) { 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*/ 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; cmd_state = CMD_STATE_PAR;
continue; continue;
} else if(cmd_state == CMD_STATE_PAR) { /*Other start char in parameter escaped cmd. char */ } 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_ ...@@ -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*/ /*Skip the color parameter and wait the space after it*/
if(cmd_state == CMD_STATE_PAR) { if(cmd_state == CMD_STATE_PAR) {
if(txt[i] == ' ') { if(letter == ' ') {
/*Get the parameter*/ /*Get the parameter*/
if(i - par_start == LABEL_RECOLOR_PAR_LENGTH) { if(i - par_start == LABEL_RECOLOR_PAR_LENGTH) {
char buf[LABEL_RECOLOR_PAR_LENGTH + 1]; 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_ ...@@ -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; color_t color = style->ccolor;
if(cmd_state == CMD_STATE_IN) color = recolor; 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*/ /*Go to next line*/
......
...@@ -95,6 +95,7 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, ...@@ -95,6 +95,7 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p,
color_t color, opa_t opa) color_t color, opa_t opa)
{ {
uint8_t w = font_get_width(font_p, letter); uint8_t w = font_get_width(font_p, letter);
const uint8_t * bitmap_p = font_get_bitmap(font_p, letter); const uint8_t * bitmap_p = font_get_bitmap(font_p, letter);
uint8_t col, col_sub, row; uint8_t col, col_sub, row;
...@@ -110,15 +111,14 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, ...@@ -110,15 +111,14 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p,
col_sub = 8; col_sub = 8;
} }
} }
/*Correction if the letter is short*/
bitmap_p += font_p->width_byte - ((w >> 3) + 1);
/*Go to the next row*/ /*Go to the next row*/
bitmap_p ++; bitmap_p ++;
} }
#else #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 * 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 px_cnt;
uint8_t col_byte_cnt; uint8_t col_byte_cnt;
for(row = 0; row < (font_p->height_row >> 1); row ++) { 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, ...@@ -152,10 +152,10 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p,
} }
} }
map1_p += font_p->width_byte; map1_p += width_byte;
map2_p += font_p->width_byte; map2_p += width_byte;
map1_p += font_p->width_byte - col_byte_cnt; map1_p += width_byte - col_byte_cnt;
map2_p += font_p->width_byte - col_byte_cnt; map2_p += width_byte - col_byte_cnt;
} }
#endif #endif
} }
......
...@@ -148,7 +148,7 @@ void lv_vfill(const area_t * cords_p, const area_t * mask_p, ...@@ -148,7 +148,7 @@ void lv_vfill(const area_t * cords_p, const area_t * mask_p,
* @param opa opacity of letter (0..255) * @param opa opacity of letter (0..255)
*/ */
void lv_vletter(const point_t * pos_p, const area_t * mask_p, 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) color_t color, opa_t opa)
{ {
if(font_p == NULL) return; if(font_p == NULL) return;
...@@ -170,6 +170,8 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, ...@@ -170,6 +170,8 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p,
cord_t col, row; cord_t col, row;
uint8_t col_bit; uint8_t col_bit;
uint8_t col_byte_cnt; 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 /* Calculate the col/row start/end on the map
* If font anti alaiassing is enabled use the reduced letter sizes*/ * 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, ...@@ -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; vdb_buf_tmp += (row_start * vdb_width) + col_start;
/*Move on the map too*/ /*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 #if FONT_ANTIALIAS != 0
opa_t opa_tmp = opa; opa_t opa_tmp = opa;
if(opa_tmp != OPA_COVER) opa_tmp = opa_tmp >> 2; /*Opacity per pixel (used when sum the pixels)*/ 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 * 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; uint8_t px_cnt;
for(row = row_start; row < row_end; row ++) { for(row = row_start; row < row_end; row ++) {
col_byte_cnt = 0; col_byte_cnt = 0;
...@@ -228,10 +230,10 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, ...@@ -228,10 +230,10 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p,
vdb_buf_tmp++; vdb_buf_tmp++;
} }
map1_p += font_p->width_byte; map1_p += width_byte;
map2_p += font_p->width_byte; map2_p += width_byte;
map1_p += font_p->width_byte - col_byte_cnt; map1_p += width_byte - col_byte_cnt;
map2_p += font_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*/ vdb_buf_tmp += vdb_width - ((col_end) - (col_start)); /*Next row in VDB*/
} }
#else #else
...@@ -255,7 +257,7 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, ...@@ -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*/ vdb_buf_tmp += vdb_width - (col_end - col_start); /*Next row in VDB*/
} }
#endif #endif
......
...@@ -54,7 +54,7 @@ void lv_vfill(const area_t * cords_p, const area_t * mask_p, ...@@ -54,7 +54,7 @@ void lv_vfill(const area_t * cords_p, const area_t * mask_p,
* @param opa opacity of letter (0..255) * @param opa opacity of letter (0..255)
*/ */
void lv_vletter(const point_t * pos_p, const area_t * mask_p, 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); color_t color, opa_t opa);
/** /**
......
...@@ -1525,13 +1525,14 @@ static void lv_child_refr_style(lv_obj_t * obj) ...@@ -1525,13 +1525,14 @@ static void lv_child_refr_style(lv_obj_t * obj)
lv_obj_t * child = lv_obj_get_child(obj, NULL); lv_obj_t * child = lv_obj_get_child(obj, NULL);
while(child != NULL) { while(child != NULL) {
if(child->style_p == 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); 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);
} }
/** /**
......
...@@ -353,14 +353,21 @@ void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id) ...@@ -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 * Set the styles of the buttons of the button matrix
* @param btnm pointer to a button matrix object * @param btnm pointer to a button matrix object
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL) * @param rel pointer to a style for releases state
* @param style pointer to style * @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); lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
ext->style_btn_rel = rel; ext->style_btn_rel = rel;
ext->style_btn_pr = pr; ext->style_btn_pr = pr;
ext->style_btn_trel = trel;
ext->style_btn_tpr = tpr;
ext->style_btn_ina = ina;
lv_obj_inv(btnm); lv_obj_inv(btnm);
......
...@@ -47,8 +47,9 @@ typedef struct ...@@ -47,8 +47,9 @@ typedef struct
lv_btnm_callback_t cb; /*A function to call when a button is releases*/ 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_rel; /*Style of the released buttons*/
lv_style_t * style_btn_pr; /*Style of the pressed 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_trel; /*Style of the toggled released buttons*/
lv_style_t * style_btn_tpr; /*Style of the pressed 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*/ uint8_t tgl :1; /*Enable toggling*/
}lv_btnm_ext_t; }lv_btnm_ext_t;
...@@ -100,13 +101,18 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb); ...@@ -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); 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 btnm pointer to a button matrix object
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL) * @param rel pointer to a style for releases state
* @param style pointer to style * @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 * Get the current map of a button matrix
......
...@@ -70,7 +70,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -70,7 +70,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
ext->opt_label = NULL; ext->opt_label = NULL;
ext->cb = NULL; ext->cb = NULL;
ext->opened = 0; ext->opened = 0;
ext->auto_size = 0; ext->fix_height = 0;
ext->sel_opt = 0; ext->sel_opt = 0;
ext->num_opt = 0; ext->num_opt = 0;
ext->anim_time = LV_DDLIST_DEF_ANIM_TIME; ext->anim_time = LV_DDLIST_DEF_ANIM_TIME;
...@@ -86,7 +86,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -86,7 +86,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
if(copy == NULL) { if(copy == NULL) {
lv_obj_t * scrl = lv_page_get_scrl(new_ddlist); lv_obj_t * scrl = lv_page_get_scrl(new_ddlist);
lv_obj_set_drag(scrl, false); 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); lv_cont_set_fit(scrl, true, true);
ext->opt_label = lv_label_create(new_ddlist, NULL); ext->opt_label = lv_label_create(new_ddlist, NULL);
...@@ -102,7 +102,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -102,7 +102,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); 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)); lv_label_set_text(ext->opt_label, lv_label_get_text(copy_ext->opt_label));
ext->sel_opt = copy_ext->sel_opt; 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->cb = copy_ext->cb;
ext->num_opt = copy_ext->num_opt; ext->num_opt = copy_ext->num_opt;
...@@ -131,8 +131,6 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param) ...@@ -131,8 +131,6 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param)
* make the object specific signal handling */ * make the object specific signal handling */
if(valid != false) { if(valid != false) {
if(sign == LV_SIGNAL_STYLE_CHG) { 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); lv_ddlist_refr_size(ddlist, 0);
} else if(sign == LV_SIGNAL_FOCUS) { } else if(sign == LV_SIGNAL_FOCUS) {
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
...@@ -195,8 +193,8 @@ void lv_ddlist_set_options(lv_obj_t * ddlist, const char ** options) ...@@ -195,8 +193,8 @@ void lv_ddlist_set_options(lv_obj_t * ddlist, const char ** options)
lv_label_set_text(ext->opt_label, ""); lv_label_set_text(ext->opt_label, "");
uint16_t i = 0; uint16_t i = 0;
while(options[i][0] != '\0') { while(options[i][0] != '\0') {
lv_label_append_text(ext->opt_label, options[i]); lv_label_ins_text(ext->opt_label, LV_LABEL_POS_LAST, options[i]);
if(options[i + 1][0] != '\0') lv_label_append_text(ext->opt_label, "\n"); if(options[i + 1][0] != '\0') lv_label_ins_text(ext->opt_label, LV_LABEL_POS_LAST, "\n");
i++; i++;
} }
...@@ -235,11 +233,13 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt) ...@@ -235,11 +233,13 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt)
{ {
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); 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*/ /*Move the list to show the current option*/
if(ext->opened == 0) { if(ext->opened == 0) {
lv_ddlist_pos_act_option(ddlist); lv_ddlist_pos_act_option(ddlist);
} else {
lv_obj_inv(ddlist);
} }
} }
...@@ -255,15 +255,16 @@ void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t cb) ...@@ -255,15 +255,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. * Set the fix height value.
* In this case the drop down list can be scrolled. * 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 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); 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);
} }
/** /**
...@@ -288,6 +289,20 @@ void lv_ddlist_set_style_select(lv_obj_t * ddlist, lv_style_t * style) ...@@ -288,6 +289,20 @@ void lv_ddlist_set_style_select(lv_obj_t * ddlist, lv_style_t * style)
ext->style_sel = style; 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 * Getter functions
*====================*/ *====================*/
...@@ -341,14 +356,14 @@ void lv_ddlist_get_selected_str(lv_obj_t * ddlist, char * buf) ...@@ -341,14 +356,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 * @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); lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
return ext->auto_size == 0 ? false : true; return ext->fix_height;
} }
/** /**
...@@ -469,7 +484,7 @@ static lv_action_res_t lv_ddlist_rel_action(lv_obj_t * ddlist, lv_dispi_t * disp ...@@ -469,7 +484,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 ddlist pointer to a drop down list object
* @param anim_time animations time for open/close [ms] * @param anim_time animations time for open/close [ms]
*/ */
...@@ -478,13 +493,9 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, uint16_t anim_time) ...@@ -478,13 +493,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_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
lv_style_t * style = lv_obj_get_style(ddlist); lv_style_t * style = lv_obj_get_style(ddlist);
cord_t new_height; cord_t new_height;
if(ext->opened != 0) { /*Open the list*/ if(ext->opened) { /*Open the list*/
new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad; if(ext->fix_height == 0) new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad;
lv_obj_t * parent = lv_obj_get_parent(ddlist); else new_height = ext->fix_height;
/*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;
}
} else { /*Close the list*/ } else { /*Close the list*/
const font_t * font = style->font; const font_t * font = style->font;
lv_style_t * label_style = lv_obj_get_style(ext->opt_label); lv_style_t * label_style = lv_obj_get_style(ext->opt_label);
...@@ -525,9 +536,11 @@ static void lv_ddlist_pos_act_option(lv_obj_t * ddlist) ...@@ -525,9 +536,11 @@ static void lv_ddlist_pos_act_option(lv_obj_t * ddlist)
cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS;
lv_style_t * label_style = lv_obj_get_style(ext->opt_label); lv_style_t * label_style = lv_obj_get_style(ext->opt_label);
lv_obj_t * scrl = lv_page_get_scrl(ddlist); 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);
} }
......
...@@ -48,7 +48,7 @@ typedef struct ...@@ -48,7 +48,7 @@ typedef struct
uint16_t sel_opt; /*Index of the current option*/ uint16_t sel_opt; /*Index of the current option*/
uint16_t anim_time; /*Open/Close animation time [ms]*/ uint16_t anim_time; /*Open/Close animation time [ms]*/
uint8_t opened :1; /*1: The list is opened*/ 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; }lv_ddlist_ext_t;
...@@ -99,12 +99,12 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt); ...@@ -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); 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. * Set the fix height value.
* In this case the drop down list can be scrolled. * 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 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 * Set the style of the rectangle on the selected option
...@@ -114,6 +114,14 @@ void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size); ...@@ -114,6 +114,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); 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 * Get the options of a drop down list
* @param ddlist pointer to drop down list object * @param ddlist pointer to drop down list object
* @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3")
...@@ -134,12 +142,13 @@ uint16_t lv_ddlist_get_selected(lv_obj_t * ddlist); ...@@ -134,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); 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 * @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 * Get the style of the rectangle on the selected option
......
/** /**
* @file lv_kb.c * @file lv_kb.c
* *
...@@ -15,7 +16,6 @@ ...@@ -15,7 +16,6 @@
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
...@@ -80,7 +80,6 @@ static const char * kb_map_num[] = { ...@@ -80,7 +80,6 @@ static const char * kb_map_num[] = {
lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy) lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy)
{ {
/*Create the ancestor of keyboard*/ /*Create the ancestor of keyboard*/
/*TODO modify it to the ancestor create function */
lv_obj_t * new_kb = lv_btnm_create(par, copy); lv_obj_t * new_kb = lv_btnm_create(par, copy);
dm_assert(new_kb); dm_assert(new_kb);
...@@ -214,6 +213,7 @@ void lv_kb_set_close_action(lv_obj_t * kb, lv_action_t action) ...@@ -214,6 +213,7 @@ void lv_kb_set_close_action(lv_obj_t * kb, lv_action_t action)
ext->close_action = action; ext->close_action = action;
} }
/*===================== /*=====================
* Getter functions * Getter functions
*====================*/ *====================*/
...@@ -362,10 +362,10 @@ static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, uint16_t i) ...@@ -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); lv_ta_set_cursor_pos(ext->ta, cur + 1);
} }
} else if(strcmp(txt, "Hide") == 0) { } 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; return LV_ACTION_RES_INV;
} else if(strcmp(txt, "Ok") == 0) { } 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; return LV_ACTION_RES_INV;
} else { } else {
lv_ta_add_text(ext->ta, txt); lv_ta_add_text(ext->ta, txt);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#if USE_LV_LABEL != 0 #if USE_LV_LABEL != 0
#include "misc/gfx/color.h" #include "misc/gfx/color.h"
#include "misc/gfx/text.h"
#include "misc/math/math_base.h" #include "misc/math/math_base.h"
#include "lv_label.h" #include "lv_label.h"
#include "../lv_obj/lv_obj.h" #include "../lv_obj/lv_obj.h"
...@@ -165,22 +166,28 @@ void lv_label_set_text(lv_obj_t * label, const char * text) ...@@ -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); 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 is NULL then refresh */
if(text == ext->txt || text == NULL) { if(text == NULL) {
lv_label_refr_text(label); lv_label_refr_text(label);
return; return;
} }
/*Allocate space for the new text*/ if(ext->txt == text) {
uint32_t len = strlen(text) + 1; /*If set its own text then reallocate it (maybe its size changed)*/
if(ext->txt != NULL && ext->static_txt == 0) { ext->txt = dm_realloc(ext->txt, strlen(ext->txt) + 1);
dm_free(ext->txt); } else {
ext->txt = NULL; /*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); lv_label_refr_text(label);
} }
/** /**
...@@ -238,11 +245,14 @@ void lv_label_set_text_static(lv_obj_t * label, const char * text) ...@@ -238,11 +245,14 @@ 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 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.
* @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, uint32_t pos, const char * txt)
{ {
lv_label_ext_t * ext = lv_obj_get_ext(label); lv_label_ext_t * ext = lv_obj_get_ext(label);
...@@ -253,11 +263,19 @@ void lv_label_append_text(lv_obj_t * label, const char * text) ...@@ -253,11 +263,19 @@ void lv_label_append_text(lv_obj_t * label, const char * text)
/*Allocate space for the new text*/ /*Allocate space for the new text*/
uint32_t old_len = strlen(ext->txt); uint32_t old_len = strlen(ext->txt);
uint32_t app_len = strlen(text); uint32_t ins_len = strlen(txt);
uint32_t new_len = app_len + old_len; uint32_t new_len = ins_len + old_len;
ext->txt = dm_realloc(ext->txt, new_len + 1); 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) {
#if TXT_UTF8 == 0
pos = old_len;
#else
pos = txt_len(ext->txt);
#endif
}
txt_ins(ext->txt, pos, txt);
lv_label_refr_text(label); lv_label_refr_text(label);
} }
...@@ -271,15 +289,6 @@ void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode) ...@@ -271,15 +289,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); 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)*/ /*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_x);
anim_del(label, (anim_fp_t) lv_obj_set_y); anim_del(label, (anim_fp_t) lv_obj_set_y);
...@@ -363,7 +372,7 @@ bool lv_label_get_recolor(lv_obj_t * label) ...@@ -363,7 +372,7 @@ bool lv_label_get_recolor(lv_obj_t * label)
/** /**
* Get the relative x and y coordinates of a letter * Get the relative x and y coordinates of a letter
* @param label pointer to a label object * @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) * @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) void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
...@@ -388,6 +397,8 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) ...@@ -388,6 +397,8 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
max_w = CORD_MAX; max_w = CORD_MAX;
} }
index = txt_utf8_get_id(txt, index);
/*Search the line of the index letter */; /*Search the line of the index letter */;
while (txt[new_line_start] != '\0') { while (txt[new_line_start] != '\0') {
new_line_start += txt_get_next_line(&txt[line_start], font, style->letter_space, max_w, flag); new_line_start += txt_get_next_line(&txt[line_start], font, style->letter_space, max_w, flag);
...@@ -397,6 +408,7 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) ...@@ -397,6 +408,7 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
line_start = new_line_start; line_start = new_line_start;
} }
/*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') { if((txt[index - 1] == '\n' || txt[index - 1] == '\r') && txt[index] == '\0') {
y += letter_height + style->line_space; y += letter_height + style->line_space;
line_start = index; line_start = index;
...@@ -404,16 +416,20 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos) ...@@ -404,16 +416,20 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
/*Calculate the x coordinate*/ /*Calculate the x coordinate*/
cord_t x = 0; 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; txt_cmd_state_t cmd_state = TXT_CMD_STATE_WAIT;
for(i = line_start; i < index; i++) { uint32_t letter;
while(cnt < index) {
cnt += txt_utf8_size(txt[i]);
letter = txt_utf8_next(txt, &i);
/*Handle the recolor command*/ /*Handle the recolor command*/
if((flag & TXT_FLAG_RECOLOR) != 0) { if((flag & TXT_FLAG_RECOLOR) != 0) {
if(txt_is_cmd(&cmd_state, txt[i]) != false) { if(txt_is_cmd(&cmd_state, txt[i]) != false) {
continue; /*Skip the letter is it is part of a command*/ 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) { if(style->txt_align == LV_TXT_ALIGN_MID) {
...@@ -474,8 +490,10 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos) ...@@ -474,8 +490,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; txt_cmd_state_t cmd_state = TXT_CMD_STATE_WAIT;
uint16_t i; uint32_t i = line_start;
for(i = line_start; i < new_line_start - 1; i++) { uint32_t letter;
while(i < new_line_start - 1) {
letter = txt_utf8_next(txt, &i);
/*Handle the recolor command*/ /*Handle the recolor command*/
if((flag & TXT_FLAG_RECOLOR) != 0) { if((flag & TXT_FLAG_RECOLOR) != 0) {
if(txt_is_cmd(&cmd_state, txt[i]) != false) { if(txt_is_cmd(&cmd_state, txt[i]) != false) {
...@@ -483,8 +501,8 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos) ...@@ -483,8 +501,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; x += (font_get_width(font, letter) >> FONT_ANTIALIAS) + style->letter_space;
if(pos->x < x) break; if(pos->x < x) break; /*Get the position*/
} }
return i; return i;
...@@ -660,40 +678,7 @@ static void lv_label_refr_text(lv_obj_t * label) ...@@ -660,40 +678,7 @@ static void lv_label_refr_text(lv_obj_t * label)
else if (ext->long_mode == LV_LABEL_LONG_BREAK) { else if (ext->long_mode == LV_LABEL_LONG_BREAK) {
lv_obj_set_height(label, size.y); 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); lv_obj_inv(label);
} }
......
...@@ -19,12 +19,13 @@ extern "C" { ...@@ -19,12 +19,13 @@ extern "C" {
#include "../lv_obj/lv_obj.h" #include "../lv_obj/lv_obj.h"
#include "misc/gfx/font.h" #include "misc/gfx/font.h"
#include "misc/gfx/text.h" #include "misc/gfx/text.h"
#include "misc/gfx/fonts/symbol_def.h"
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#define LV_LABEL_DOT_NUM 3 #define LV_LABEL_DOT_NUM 3
#define LV_LABEL_POS_LAST 0xFFFF
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
...@@ -34,7 +35,6 @@ typedef enum ...@@ -34,7 +35,6 @@ typedef enum
{ {
LV_LABEL_LONG_EXPAND, /*Expand the object size to the text size*/ 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_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_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_ROLL, /*Keep the size and roll the text infinitely*/
}lv_label_long_mode_t; }lv_label_long_mode_t;
...@@ -46,7 +46,11 @@ typedef struct ...@@ -46,7 +46,11 @@ typedef struct
/*New data for this type */ /*New data for this type */
char * txt; /*Text of the label*/ char * txt; /*Text of the label*/
lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/ 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)*/ 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)*/ uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/
point_t offset; /*Text draw position offset*/ point_t offset; /*Text draw position offset*/
uint8_t static_txt :1; /*Flag to indicate the text is static*/ uint8_t static_txt :1; /*Flag to indicate the text is static*/
...@@ -100,11 +104,16 @@ void lv_label_set_text_array(lv_obj_t * label, const char * array, uint16_t size ...@@ -100,11 +104,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); 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 label pointer to label object
* @param text pointe rto the new text * @param pos character index to insert
*/ * 0: before first char.
void lv_label_append_text(lv_obj_t * label, const char * text); * 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, uint32_t pos, const char * txt);
/** /**
* Set the behavior of the label with longer text then the object size * Set the behavior of the label with longer text then the object size
......
...@@ -349,25 +349,6 @@ void lv_list_set_sb_out(lv_obj_t * list, bool out) ...@@ -349,25 +349,6 @@ void lv_list_set_sb_out(lv_obj_t * list, bool out)
ext->sb_out = out == false ? 0 : 1; 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 * Set styles of the list elements of a list in each state
......
...@@ -104,13 +104,6 @@ void lv_list_down(lv_obj_t * list); ...@@ -104,13 +104,6 @@ void lv_list_down(lv_obj_t * list);
void lv_list_set_sb_out(lv_obj_t * list, bool out); 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 * Set styles of the list elements of a list in each state
* @param list pointer to list object * @param list pointer to list object
* @param rel pointer to a style for releases state * @param rel pointer to a style for releases state
......
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
* *
*/ */
/*Search an replace: template -> object normal name with lower case (e.g. button, label etc.) /* TODO Remove these instructions
* templ -> object short name with lower case(e.g. btn, label etc) * Search an replace: template -> object normal name with lower case (e.g. button, label etc.)
* TEMPL -> object short name with upper case (e.g. BTN, 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.)
* *
*/ */
......
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
*/ */
/*Search an replace: template -> object normal name with lower case (e.g. button, label etc.) /* TODO Remove these instructions
* templ -> object short name with lower case(e.g. btn, label etc) * Search an replace: template -> object normal name with lower case (e.g. button, label etc.)
* TEMPL -> object short name with upper case (e.g. BTN, 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.)
* *
*/ */
......
/**
* @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);
static 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*/
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); /*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, 0);
lv_style_t * style_label = lv_obj_get_style(ext->ddlist.opt_label);
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 {
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 */
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) {
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;
}
/*======================
* 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 = 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));
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;
}
/**
* 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;
/* 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) {
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;
/*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;
}
/*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;
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;
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);
}
}
}
return valid;
}
#endif
/**
* @file lv_roller.h
*
*/
#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*/
...@@ -97,7 +97,7 @@ bool lv_ta_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); ...@@ -97,7 +97,7 @@ bool lv_ta_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
* @param ta pointer to a text area object * @param ta pointer to a text area object
* @param c a character * @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 * Insert a text to the current cursor position
......
...@@ -151,10 +151,11 @@ bool lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param) ...@@ -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 /* The object can be deleted so check its validity and then
* make the object specific signal handling */ * make the object specific signal handling */
if(valid != false) { if(valid != false) {
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
if(sign == LV_SIGNAL_CLEANUP) { 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) { } else if(sign == LV_SIGNAL_CORD_CHG) {
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
if(ext->content != NULL && if(ext->content != NULL &&
(lv_obj_get_width(tabview) != area_get_width(param) || (lv_obj_get_width(tabview) != area_get_width(param) ||
lv_obj_get_height(tabview) != area_get_height(param))) lv_obj_get_height(tabview) != area_get_height(param)))
......
...@@ -33,6 +33,7 @@ extern "C" { ...@@ -33,6 +33,7 @@ extern "C" {
#include "lv_objx/lv_btnm.h" #include "lv_objx/lv_btnm.h"
#include "lv_objx/lv_kb.h" #include "lv_objx/lv_kb.h"
#include "lv_objx/lv_ddlist.h" #include "lv_objx/lv_ddlist.h"
#include "lv_objx/lv_roller.h"
#include "lv_objx/lv_ta.h" #include "lv_objx/lv_ta.h"
#include "lv_objx/lv_win.h" #include "lv_objx/lv_win.h"
#include "lv_objx/lv_tabview.h" #include "lv_objx/lv_tabview.h"
......
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