rever reset
This commit is contained in:
@@ -353,14 +353,21 @@ void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id)
|
||||
/**
|
||||
* Set the styles of the buttons of the button matrix
|
||||
* @param btnm pointer to a button matrix object
|
||||
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
|
||||
* @param style pointer to style
|
||||
* @param rel pointer to a style for releases state
|
||||
* @param pr pointer to a style for pressed state
|
||||
* @param trel pointer to a style for toggled releases state
|
||||
* @param tpr pointer to a style for toggled pressed state
|
||||
* @param ina pointer to a style for inactive state
|
||||
*/
|
||||
void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr)
|
||||
void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr,
|
||||
lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina)
|
||||
{
|
||||
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
|
||||
ext->style_btn_rel = rel;
|
||||
ext->style_btn_pr = pr;
|
||||
ext->style_btn_trel = trel;
|
||||
ext->style_btn_tpr = tpr;
|
||||
ext->style_btn_ina = ina;
|
||||
|
||||
lv_obj_inv(btnm);
|
||||
|
||||
|
||||
@@ -47,8 +47,9 @@ typedef struct
|
||||
lv_btnm_callback_t cb; /*A function to call when a button is releases*/
|
||||
lv_style_t * style_btn_rel; /*Style of the released buttons*/
|
||||
lv_style_t * style_btn_pr; /*Style of the pressed buttons*/
|
||||
lv_style_t * style_btn_trel; /*Style of the released buttons*/
|
||||
lv_style_t * style_btn_tpr; /*Style of the pressed buttons*/
|
||||
lv_style_t * style_btn_trel; /*Style of the toggled released buttons*/
|
||||
lv_style_t * style_btn_tpr; /*Style of the toggled pressed buttons*/
|
||||
lv_style_t * style_btn_ina; /*Style of the inactive buttons*/
|
||||
uint8_t tgl :1; /*Enable toggling*/
|
||||
}lv_btnm_ext_t;
|
||||
|
||||
@@ -100,13 +101,18 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb);
|
||||
*/
|
||||
void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id);
|
||||
|
||||
|
||||
/**
|
||||
* Set the styles of the buttons of the button matrox
|
||||
* Set the styles of the buttons of the button matrix
|
||||
* @param btnm pointer to a button matrix object
|
||||
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
|
||||
* @param style pointer to style
|
||||
* @param rel pointer to a style for releases state
|
||||
* @param pr pointer to a style for pressed state
|
||||
* @param trel pointer to a style for toggled releases state
|
||||
* @param tpr pointer to a style for toggled pressed state
|
||||
* @param ina pointer to a style for inactive state
|
||||
*/
|
||||
void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr);
|
||||
void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr,
|
||||
lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina);
|
||||
|
||||
/**
|
||||
* Get the current map of a button matrix
|
||||
|
||||
@@ -70,7 +70,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
ext->opt_label = NULL;
|
||||
ext->cb = NULL;
|
||||
ext->opened = 0;
|
||||
ext->auto_size = 0;
|
||||
ext->fix_height = 0;
|
||||
ext->sel_opt = 0;
|
||||
ext->num_opt = 0;
|
||||
ext->anim_time = LV_DDLIST_DEF_ANIM_TIME;
|
||||
@@ -86,7 +86,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
if(copy == NULL) {
|
||||
lv_obj_t * scrl = lv_page_get_scrl(new_ddlist);
|
||||
lv_obj_set_drag(scrl, false);
|
||||
lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL));;
|
||||
lv_obj_set_style(scrl, lv_style_get(LV_STYLE_TRANSP, NULL));
|
||||
lv_cont_set_fit(scrl, true, true);
|
||||
|
||||
ext->opt_label = lv_label_create(new_ddlist, NULL);
|
||||
@@ -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);
|
||||
lv_label_set_text(ext->opt_label, lv_label_get_text(copy_ext->opt_label));
|
||||
ext->sel_opt = copy_ext->sel_opt;
|
||||
ext->auto_size = copy_ext->auto_size;
|
||||
ext->fix_height = copy_ext->fix_height;
|
||||
ext->cb = copy_ext->cb;
|
||||
ext->num_opt = copy_ext->num_opt;
|
||||
|
||||
@@ -131,8 +131,6 @@ bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param)
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
if(sign == LV_SIGNAL_STYLE_CHG) {
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
lv_obj_set_style(ext->opt_label, lv_obj_get_style(ddlist));
|
||||
lv_ddlist_refr_size(ddlist, 0);
|
||||
} else if(sign == LV_SIGNAL_FOCUS) {
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
@@ -195,8 +193,8 @@ void lv_ddlist_set_options(lv_obj_t * ddlist, const char ** options)
|
||||
lv_label_set_text(ext->opt_label, "");
|
||||
uint16_t i = 0;
|
||||
while(options[i][0] != '\0') {
|
||||
lv_label_append_text(ext->opt_label, options[i]);
|
||||
if(options[i + 1][0] != '\0') lv_label_append_text(ext->opt_label, "\n");
|
||||
lv_label_ins_text(ext->opt_label, LV_LABEL_POS_LAST, options[i]);
|
||||
if(options[i + 1][0] != '\0') lv_label_ins_text(ext->opt_label, LV_LABEL_POS_LAST, "\n");
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
ext->sel_opt = sel_opt;
|
||||
ext->sel_opt = sel_opt < ext->num_opt ? sel_opt : ext->num_opt - 1;
|
||||
|
||||
/*Move the list to show the current option*/
|
||||
if(ext->opened == 0) {
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the auto size attribute. If enabled the height will reduced to be visible on the parent.
|
||||
* In this case the drop down list can be scrolled.
|
||||
* Set the fix height value.
|
||||
* If 0 then the opened ddlist will be auto. sized else the set height will be applied.
|
||||
* @param ddlist pointer to a drop down list
|
||||
* @param auto_size true: enable auto size, false: disable
|
||||
* @param h the height when the list is opened (0: auto size)
|
||||
*/
|
||||
void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size)
|
||||
void lv_ddlist_set_fix_height(lv_obj_t * ddlist, cord_t h)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
ext->auto_size = auto_size == false ? 0 : 1;
|
||||
ext->fix_height = h;
|
||||
lv_ddlist_refr_size(ddlist, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,6 +288,20 @@ void lv_ddlist_set_style_select(lv_obj_t * ddlist, lv_style_t * style)
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
ext->style_sel = style;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Open or Collapse the drop down list
|
||||
* @param ddlist pointer to drop down list object
|
||||
* @param state true: open; false: collapse
|
||||
* @param anim true: use animations; false: not use animations
|
||||
*/
|
||||
void lv_ddlist_open(lv_obj_t * ddlist, bool state, bool anim)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
ext->opened = state ? 1 : 0;
|
||||
lv_ddlist_refr_size(ddlist, anim ? ext->anim_time : 0);
|
||||
|
||||
}
|
||||
/*=====================
|
||||
* Getter functions
|
||||
@@ -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
|
||||
* @return true: the auto_size is enabled, false: disabled
|
||||
* @return the height if the ddlist is opened (0: auto size)
|
||||
*/
|
||||
bool lv_ddlist_get_auto_size(lv_obj_t * ddlist, bool auto_size)
|
||||
cord_t lv_ddlist_get_fix_height(lv_obj_t * ddlist)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
return ext->auto_size == 0 ? false : true;
|
||||
return ext->fix_height;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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 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)
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist);
|
||||
lv_style_t * style = lv_obj_get_style(ddlist);
|
||||
cord_t new_height;
|
||||
if(ext->opened != 0) { /*Open the list*/
|
||||
new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad;
|
||||
lv_obj_t * parent = lv_obj_get_parent(ddlist);
|
||||
/*Reduce the height if enabled and required*/
|
||||
if(ext->auto_size != 0 && new_height + ddlist->cords.y1 > parent->cords.y2) {
|
||||
new_height = parent->cords.y2 - ddlist->cords.y1;
|
||||
}
|
||||
if(ext->opened) { /*Open the list*/
|
||||
if(ext->fix_height == 0) new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + 2 * style->vpad;
|
||||
else new_height = ext->fix_height;
|
||||
} else { /*Close the list*/
|
||||
const font_t * font = style->font;
|
||||
lv_style_t * label_style = lv_obj_get_style(ext->opt_label);
|
||||
@@ -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;
|
||||
lv_style_t * label_style = lv_obj_get_style(ext->opt_label);
|
||||
lv_obj_t * scrl = lv_page_get_scrl(ddlist);
|
||||
lv_style_t * style_scrl = lv_obj_get_style(scrl);
|
||||
|
||||
lv_obj_set_y(scrl, -(ext->sel_opt * (font_h + label_style->line_space) - label_style->line_space) - style_scrl->hpad);
|
||||
cord_t h = lv_obj_get_height(ddlist);
|
||||
cord_t line_y1 = ext->sel_opt * (font_h + label_style->line_space) + ext->opt_label->cords.y1 - scrl->cords.y1;
|
||||
|
||||
lv_obj_set_y(scrl, - line_y1 + (h - font_h) / 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ typedef struct
|
||||
uint16_t sel_opt; /*Index of the current option*/
|
||||
uint16_t anim_time; /*Open/Close animation time [ms]*/
|
||||
uint8_t opened :1; /*1: The list is opened*/
|
||||
uint8_t auto_size :1; /*1: Set height to show all options. 0: Set height maximum to the parent bottom*/
|
||||
cord_t fix_height; /*Height if the ddlist is opened. (0: auto-size)*/
|
||||
}lv_ddlist_ext_t;
|
||||
|
||||
|
||||
@@ -99,12 +99,12 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt);
|
||||
void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t cb);
|
||||
|
||||
/**
|
||||
* Set the auto size attribute. If enabled the height will reduced to be visible on the parent.
|
||||
* In this case the drop down list can be scrolled.
|
||||
* Set the fix height value.
|
||||
* If 0 then the opened ddlist will be auto. sized else the set height will be applied.
|
||||
* @param ddlist pointer to a drop down list
|
||||
* @param auto_size true: enable auto size, false: disable
|
||||
* @param h the height when the list is opened (0: auto size)
|
||||
*/
|
||||
void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size);
|
||||
void lv_ddlist_set_fix_height(lv_obj_t * ddlist, cord_t h);
|
||||
|
||||
/**
|
||||
* Set the style of the rectangle on the selected option
|
||||
@@ -113,6 +113,14 @@ void lv_ddlist_set_auto_size(lv_obj_t * ddlist, bool auto_size);
|
||||
*/
|
||||
void lv_ddlist_set_style_select(lv_obj_t * ddlist, lv_style_t * style);
|
||||
|
||||
/**
|
||||
* Open or Collapse the drop down list
|
||||
* @param ddlist pointer to drop down list object
|
||||
* @param state true: open; false: collapse
|
||||
* @param anim true: use animations; false: not use animations
|
||||
*/
|
||||
void lv_ddlist_open(lv_obj_t * ddlist, bool state, bool anim);
|
||||
|
||||
/**
|
||||
* Get the options of a drop down list
|
||||
* @param ddlist pointer to drop down list object
|
||||
@@ -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);
|
||||
|
||||
|
||||
/**
|
||||
* Get the auto size attribute.
|
||||
* Get the fix height value.
|
||||
* @param ddlist pointer to a drop down list object
|
||||
* @return true: the auto_size is enabled, false: disabled
|
||||
* @return the height if the ddlist is opened (0: auto size)
|
||||
*/
|
||||
bool lv_ddlist_get_auto_size(lv_obj_t * ddlist, bool auto_size);
|
||||
cord_t lv_ddlist_get_fix_height(lv_obj_t * ddlist);
|
||||
|
||||
/**
|
||||
* Get the style of the rectangle on the selected option
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
/**
|
||||
* @file lv_kb.c
|
||||
*
|
||||
@@ -15,7 +16,6 @@
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
@@ -80,7 +80,6 @@ static const char * kb_map_num[] = {
|
||||
lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor of keyboard*/
|
||||
/*TODO modify it to the ancestor create function */
|
||||
lv_obj_t * new_kb = lv_btnm_create(par, copy);
|
||||
dm_assert(new_kb);
|
||||
|
||||
@@ -214,6 +213,7 @@ void lv_kb_set_close_action(lv_obj_t * kb, lv_action_t action)
|
||||
ext->close_action = action;
|
||||
}
|
||||
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@@ -362,10 +362,10 @@ static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, uint16_t i)
|
||||
lv_ta_set_cursor_pos(ext->ta, cur + 1);
|
||||
}
|
||||
} else if(strcmp(txt, "Hide") == 0) {
|
||||
//lv_app_kb_close(false);
|
||||
if(ext->close_action) ext->close_action(kb, NULL);
|
||||
return LV_ACTION_RES_INV;
|
||||
} else if(strcmp(txt, "Ok") == 0) {
|
||||
//lv_app_kb_close(true);
|
||||
if(ext->ok_action) ext->ok_action(kb, NULL);
|
||||
return LV_ACTION_RES_INV;
|
||||
} else {
|
||||
lv_ta_add_text(ext->ta, txt);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#if USE_LV_LABEL != 0
|
||||
|
||||
#include "misc/gfx/color.h"
|
||||
#include "misc/gfx/text.h"
|
||||
#include "misc/math/math_base.h"
|
||||
#include "lv_label.h"
|
||||
#include "../lv_obj/lv_obj.h"
|
||||
@@ -165,22 +166,28 @@ void lv_label_set_text(lv_obj_t * label, const char * text)
|
||||
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
|
||||
/*If trying to set its own text or the text is NULL then refresh */
|
||||
if(text == ext->txt || text == NULL) {
|
||||
/*If text is NULL then refresh */
|
||||
if(text == NULL) {
|
||||
lv_label_refr_text(label);
|
||||
return;
|
||||
}
|
||||
|
||||
/*Allocate space for the new text*/
|
||||
uint32_t len = strlen(text) + 1;
|
||||
if(ext->txt != NULL && ext->static_txt == 0) {
|
||||
dm_free(ext->txt);
|
||||
ext->txt = NULL;
|
||||
if(ext->txt == text) {
|
||||
/*If set its own text then reallocate it (maybe its size changed)*/
|
||||
ext->txt = dm_realloc(ext->txt, strlen(ext->txt) + 1);
|
||||
} else {
|
||||
/*Allocate space for the new text*/
|
||||
uint32_t len = strlen(text) + 1;
|
||||
if(ext->txt != NULL && ext->static_txt == 0) {
|
||||
dm_free(ext->txt);
|
||||
ext->txt = NULL;
|
||||
}
|
||||
|
||||
ext->txt = dm_alloc(len);
|
||||
strcpy(ext->txt, text);
|
||||
ext->static_txt = 0; /*Now the text is dynamically allocated*/
|
||||
}
|
||||
ext->txt = dm_alloc(len);
|
||||
strcpy(ext->txt, text);
|
||||
ext->static_txt = 0; /*Now the text is dynamically allocated*/
|
||||
|
||||
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
/**
|
||||
@@ -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 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);
|
||||
|
||||
@@ -253,11 +263,19 @@ void lv_label_append_text(lv_obj_t * label, const char * text)
|
||||
|
||||
/*Allocate space for the new text*/
|
||||
uint32_t old_len = strlen(ext->txt);
|
||||
uint32_t app_len = strlen(text);
|
||||
uint32_t new_len = app_len + old_len;
|
||||
uint32_t ins_len = strlen(txt);
|
||||
uint32_t new_len = ins_len + old_len;
|
||||
ext->txt = dm_realloc(ext->txt, new_len + 1);
|
||||
memcpy(ext->txt + old_len, text, app_len);
|
||||
ext->txt[new_len] = '\0';
|
||||
|
||||
if(pos == LV_LABEL_POS_LAST) {
|
||||
#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);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
/*When changing from dot mode reload the characters replaced by dots*/
|
||||
if(ext->long_mode == LV_LABEL_LONG_DOTS &&
|
||||
ext->dot_end != LV_LABEL_DOT_END_INV) {
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_LABEL_DOT_NUM + 1; i++) {
|
||||
ext->txt[ext->dot_end - LV_LABEL_DOT_NUM + i] = ext->dot_tmp[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*Delete the old animation (if exists)*/
|
||||
anim_del(label, (anim_fp_t) lv_obj_set_x);
|
||||
anim_del(label, (anim_fp_t) lv_obj_set_y);
|
||||
@@ -363,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)
|
||||
@@ -388,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);
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/*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;
|
||||
@@ -404,16 +416,20 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
|
||||
|
||||
/*Calculate the x coordinate*/
|
||||
cord_t x = 0;
|
||||
uint32_t i;
|
||||
uint32_t i = line_start;
|
||||
uint32_t cnt = line_start; /*Count the letter (in UTF-8 1 letter not 1 byte)*/
|
||||
txt_cmd_state_t cmd_state = TXT_CMD_STATE_WAIT;
|
||||
for(i = line_start; i < index; i++) {
|
||||
uint32_t letter;
|
||||
while(cnt < index) {
|
||||
cnt += txt_utf8_size(txt[i]);
|
||||
letter = txt_utf8_next(txt, &i);
|
||||
/*Handle the recolor command*/
|
||||
if((flag & TXT_FLAG_RECOLOR) != 0) {
|
||||
if(txt_is_cmd(&cmd_state, txt[i]) != false) {
|
||||
continue; /*Skip the letter is it is part of a command*/
|
||||
}
|
||||
}
|
||||
x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
x += (font_get_width(font, letter) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
}
|
||||
|
||||
if(style->txt_align == LV_TXT_ALIGN_MID) {
|
||||
@@ -474,8 +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;
|
||||
uint16_t i;
|
||||
for(i = line_start; i < new_line_start - 1; i++) {
|
||||
uint32_t i = line_start;
|
||||
uint32_t letter;
|
||||
while(i < new_line_start - 1) {
|
||||
letter = txt_utf8_next(txt, &i);
|
||||
/*Handle the recolor command*/
|
||||
if((flag & TXT_FLAG_RECOLOR) != 0) {
|
||||
if(txt_is_cmd(&cmd_state, txt[i]) != false) {
|
||||
@@ -483,8 +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;
|
||||
if(pos->x < x) break;
|
||||
x += (font_get_width(font, letter) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
if(pos->x < x) break; /*Get the position*/
|
||||
}
|
||||
|
||||
return i;
|
||||
@@ -660,40 +678,7 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
else if (ext->long_mode == LV_LABEL_LONG_BREAK) {
|
||||
lv_obj_set_height(label, size.y);
|
||||
}
|
||||
/*Replace the last 'LV_LABEL_DOT_NUM' characters with dots
|
||||
* and save these characters*/
|
||||
else if(ext->long_mode == LV_LABEL_LONG_DOTS) {
|
||||
point_t point;
|
||||
point.x = lv_obj_get_width(label) - 1;
|
||||
point.y = lv_obj_get_height(label) - 1;
|
||||
uint16_t index = lv_label_get_letter_on(label, &point);
|
||||
|
||||
if(index < strlen(ext->txt) - 1) {
|
||||
|
||||
/* Change the last 'LV_LABEL_DOT_NUM' to dots
|
||||
* (if there are at least 'LV_LABEL_DOT_NUM' characters*/
|
||||
if(index > LV_LABEL_DOT_NUM) {
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_LABEL_DOT_NUM; i++) {
|
||||
ext->dot_tmp[i] = ext->txt[index - LV_LABEL_DOT_NUM + i];
|
||||
ext->txt[index - LV_LABEL_DOT_NUM + i] = '.';
|
||||
}
|
||||
/*The last character is '\0'. Save this character from the text too.*/
|
||||
ext->dot_tmp[i] = ext->txt[index];
|
||||
ext->txt[index] = '\0';
|
||||
}
|
||||
/*Else with short text change all characters to dots*/
|
||||
else {
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_LABEL_DOT_NUM; i++) {
|
||||
ext->txt[i] = '.';
|
||||
}
|
||||
ext->txt[i] = '\0';
|
||||
}
|
||||
/*Save the dot end index*/
|
||||
ext->dot_end = index;
|
||||
}
|
||||
}
|
||||
|
||||
lv_obj_inv(label);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ extern "C" {
|
||||
#include "../lv_obj/lv_obj.h"
|
||||
#include "misc/gfx/font.h"
|
||||
#include "misc/gfx/text.h"
|
||||
#include "misc/gfx/fonts/symbol_def.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_LABEL_DOT_NUM 3
|
||||
|
||||
#define LV_LABEL_POS_LAST 0xFFFF
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
@@ -34,7 +35,6 @@ typedef enum
|
||||
{
|
||||
LV_LABEL_LONG_EXPAND, /*Expand the object size to the text size*/
|
||||
LV_LABEL_LONG_BREAK, /*Keep the object width, break the too long lines and expand the object height*/
|
||||
LV_LABEL_LONG_DOTS, /*Keep the object size, break the text and write dots in the last line*/
|
||||
LV_LABEL_LONG_SCROLL, /*Expand the object size and scroll the text on the parent (move the label object)*/
|
||||
LV_LABEL_LONG_ROLL, /*Keep the size and roll the text infinitely*/
|
||||
}lv_label_long_mode_t;
|
||||
@@ -46,7 +46,11 @@ typedef struct
|
||||
/*New data for this type */
|
||||
char * txt; /*Text of the label*/
|
||||
lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/
|
||||
#if TXT_UTF8 == 0
|
||||
char dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/
|
||||
#else
|
||||
uint32_t dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/
|
||||
#endif
|
||||
uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/
|
||||
point_t offset; /*Text draw position offset*/
|
||||
uint8_t static_txt :1; /*Flag to indicate the text is static*/
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
* Append a text to the label. The label current label text can not be static.
|
||||
* Insert a text to the label. The label current label text can not be static.
|
||||
* @param label pointer to label object
|
||||
* @param text pointe rto the new text
|
||||
* @param pos character index to insert
|
||||
* 0: before first char.
|
||||
* LV_LABEL_POS_LAST: after last char.
|
||||
* < 0: count from the end
|
||||
* -1: before the last char.
|
||||
* @param txt pointer to the text to insert
|
||||
*/
|
||||
void lv_label_append_text(lv_obj_t * label, const char * text);
|
||||
void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt);
|
||||
|
||||
/**
|
||||
* 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)
|
||||
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
|
||||
|
||||
@@ -103,13 +103,6 @@ void lv_list_down(lv_obj_t * list);
|
||||
*/
|
||||
void lv_list_set_sb_out(lv_obj_t * list, bool out);
|
||||
|
||||
/**
|
||||
* Enable or disable the text rolling on a list element
|
||||
* @param liste pinter to list element
|
||||
* @param en true: enable text scrolling, false: disable text scrolling
|
||||
*/
|
||||
void lv_list_set_element_text_roll(lv_obj_t * liste, bool en);
|
||||
|
||||
/**
|
||||
* Set styles of the list elements of a list in each state
|
||||
* @param list pointer to list object
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*Search an replace: template -> object normal name with lower case (e.g. button, label etc.)
|
||||
* templ -> object short name with lower case(e.g. btn, label etc)
|
||||
* TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.)
|
||||
/* TODO Remove these instructions
|
||||
* Search an replace: template -> object normal name with lower case (e.g. button, label etc.)
|
||||
* templ -> object short name with lower case(e.g. btn, label etc)
|
||||
* TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
*/
|
||||
|
||||
|
||||
/*Search an replace: template -> object normal name with lower case (e.g. button, label etc.)
|
||||
* templ -> object short name with lower case(e.g. btn, label etc)
|
||||
* TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.)
|
||||
/* TODO Remove these instructions
|
||||
* Search an replace: template -> object normal name with lower case (e.g. button, label etc.)
|
||||
* templ -> object short name with lower case(e.g. btn, label etc)
|
||||
* TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "../lv_obj/lv_group.h"
|
||||
#include "../lv_draw/lv_draw.h"
|
||||
#include "misc/gfx/anim.h"
|
||||
#include "misc/gfx/text.h"
|
||||
#include "misc/math/math_base.h"
|
||||
|
||||
/*********************
|
||||
@@ -244,7 +245,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 c a character
|
||||
*/
|
||||
void lv_ta_add_char(lv_obj_t * ta, char c)
|
||||
void lv_ta_add_char(lv_obj_t * ta, uint32_t c)
|
||||
{
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
|
||||
@@ -305,7 +306,6 @@ void lv_ta_add_char(lv_obj_t * ta, char c)
|
||||
void lv_ta_add_text(lv_obj_t * ta, const char * txt)
|
||||
{
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
|
||||
const char * label_txt = lv_label_get_text(ext->label);
|
||||
uint16_t label_len = strlen(label_txt);
|
||||
uint16_t txt_len = strlen(txt);
|
||||
@@ -325,7 +325,6 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt)
|
||||
|
||||
lv_label_set_text(ext->label, buf);
|
||||
|
||||
|
||||
if(ext->pwd_mode != 0) {
|
||||
ext->pwd_tmp = dm_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + txt_len + 1);
|
||||
dm_assert(ext->pwd_tmp);
|
||||
@@ -816,7 +815,7 @@ static bool lv_ta_design(lv_obj_t * ta, const area_t * masp, lv_design_mode_t mo
|
||||
|
||||
/**
|
||||
* An extended scrollable design of the page. Calls the normal design function and draws a cursor.
|
||||
* @param scrl pointer to the scrollabla part of the Text area
|
||||
* @param scrl pointer to the scrollable part of the Text area
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -865,30 +864,40 @@ static bool lv_ta_scrling_design(lv_obj_t * scrl, const area_t * mask, lv_design
|
||||
|
||||
uint16_t cur_pos = lv_ta_get_cursor_pos(ta);
|
||||
const char * txt = lv_label_get_text(ta_ext->label);
|
||||
cord_t letter_h = font_get_height(label_style->font) >> FONT_ANTIALIAS;
|
||||
uint32_t byte_pos;
|
||||
#if TXT_UTF8 != 0
|
||||
byte_pos = txt_utf8_get_id(txt, cur_pos);
|
||||
#else
|
||||
byte_pos = cur_pos;
|
||||
#endif
|
||||
|
||||
/*Set letter_w (set not 0 on non printable but valid chars)*/
|
||||
uint32_t letter = txt_utf8_next(&txt[byte_pos], NULL);
|
||||
cord_t letter_h = font_get_height(label_style->font) >> FONT_ANTIALIAS;
|
||||
/*Set letter_w (set not 0 on non printable but valid chars)*/
|
||||
cord_t letter_w;
|
||||
if(txt[cur_pos] == '\0' || txt[cur_pos] == '\n' || txt[cur_pos] == '\r') {
|
||||
if(letter == '\0' || letter == '\n' || letter == '\r') {
|
||||
letter_w = font_get_width(label_style->font, ' ');
|
||||
} else {
|
||||
letter_w = font_get_width(label_style->font, txt[cur_pos]);
|
||||
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) {
|
||||
/*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(txt[cur_pos] != '\0') cur_pos++;
|
||||
if(letter != '\0'){
|
||||
byte_pos += txt_utf8_size(txt[byte_pos]);
|
||||
letter = txt_utf8_next(&txt[byte_pos], NULL);
|
||||
}
|
||||
|
||||
if(txt[cur_pos] == '\0' || txt[cur_pos] == '\n' || txt[cur_pos] == '\r') {
|
||||
if(letter == '\0' || letter == '\n' || letter == '\r') {
|
||||
letter_w = font_get_width(label_style->font, ' ');
|
||||
} else {
|
||||
letter_w = font_get_width(label_style->font, txt[cur_pos]);
|
||||
letter_w = font_get_width(label_style->font, letter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 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
|
||||
|
||||
@@ -151,10 +151,11 @@ bool lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param)
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
||||
dm_free(ext->tab_name_ptr);
|
||||
ext->tab_name_ptr = NULL;
|
||||
} else if(sign == LV_SIGNAL_CORD_CHG) {
|
||||
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
|
||||
if(ext->content != NULL &&
|
||||
(lv_obj_get_width(tabview) != area_get_width(param) ||
|
||||
lv_obj_get_height(tabview) != area_get_height(param)))
|
||||
|
||||
Reference in New Issue
Block a user