mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
update label, image and line API
This commit is contained in:
parent
eb0383ea89
commit
39075fe06d
@ -28,11 +28,13 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t mode);
|
||||
static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param);
|
||||
static bool lv_img_is_symbol(const char * txt);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_signal_func_t ancestor_signal;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@ -55,6 +57,7 @@ lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Create a basic object*/
|
||||
new_img = lv_obj_create(par, copy);
|
||||
dm_assert(new_img);
|
||||
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_img);
|
||||
|
||||
/*Extend the basic object to image object*/
|
||||
lv_img_ext_t * ext = lv_obj_allocate_ext_attr(new_img, sizeof(lv_img_ext_t));
|
||||
@ -91,37 +94,6 @@ lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
return new_img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the image
|
||||
* @param img pointer to animage object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid = true;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_obj_signal(img, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
dm_free(ext->fn);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_STYLE_CHG) {
|
||||
/*Refresh the file name to refresh the symbol text size*/
|
||||
if(lv_img_is_symbol(ext->fn) != false) {
|
||||
lv_img_set_file(img, ext->fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a file to the RAMFS from a picture data
|
||||
* @param fn file name of the new file (e.g. "pic1", will be available at "U:/pic1")
|
||||
@ -215,30 +187,30 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
|
||||
* Enable the auto size feature.
|
||||
* If enabled the object size will be same as the picture size.
|
||||
* @param img pointer to an image
|
||||
* @param en true: auto size enable, false: auto size disable
|
||||
* @param autosize_en true: auto size enable, false: auto size disable
|
||||
*/
|
||||
void lv_img_set_auto_size(lv_obj_t * img, bool en)
|
||||
void lv_img_set_auto_size(lv_obj_t * img, bool autosize_en)
|
||||
{
|
||||
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
||||
|
||||
ext->auto_size = (en == false ? 0 : 1);
|
||||
ext->auto_size = (autosize_en == false ? 0 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the upscaling if LV_ANTIALIAS is enabled.
|
||||
* If enabled the object size will be same as the picture size.
|
||||
* @param img pointer to an image
|
||||
* @param en true: upscale enable, false: upscale disable
|
||||
* @param upscale_en true: upscale enable, false: upscale disable
|
||||
*/
|
||||
void lv_img_set_upscale(lv_obj_t * img, bool en)
|
||||
void lv_img_set_upscale(lv_obj_t * img, bool upscale_en)
|
||||
{
|
||||
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
||||
|
||||
/*Upscale works only if antialiassing is enabled*/
|
||||
#if LV_ANTIALIAS == 0
|
||||
en = false;
|
||||
upscale_en = false;
|
||||
#else
|
||||
ext->upscale = (en == false ? 0 : 1);
|
||||
ext->upscale = (upscale_en == false ? 0 : 1);
|
||||
#endif
|
||||
/*Refresh the image with the new size*/
|
||||
lv_img_set_file(img, ext->fn);
|
||||
@ -285,6 +257,7 @@ bool lv_img_get_upscale(lv_obj_t * img)
|
||||
|
||||
return ext->upscale == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@ -336,6 +309,36 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Signal function of the image
|
||||
* @param img pointer to animage object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
||||
*/
|
||||
static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
|
||||
{
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = ancestor_signal(img, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
lv_img_ext_t * ext = lv_obj_get_ext_attr(img);
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
dm_free(ext->fn);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_STYLE_CHG) {
|
||||
/*Refresh the file name to refresh the symbol text size*/
|
||||
if(lv_img_is_symbol(ext->fn) != false) {
|
||||
lv_img_set_file(img, ext->fn);
|
||||
}
|
||||
}
|
||||
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* From the settings in lv_conf.h and the file name
|
||||
* tells it a filename or a symbol text.
|
||||
|
@ -61,14 +61,6 @@ typedef struct
|
||||
*/
|
||||
lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
|
||||
/**
|
||||
* Signal function of the image
|
||||
* @param img pointer to animage object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param);
|
||||
|
||||
/**
|
||||
* Create a file to the RAMFS from a picture data
|
||||
* @param fn file name of the new file (e.g. "pic1", will be available at "U:/pic1")
|
||||
@ -77,6 +69,10 @@ bool lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param);
|
||||
*/
|
||||
fs_res_t lv_img_create_file(const char * fn, const color_int_t * data);
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set a file to the image
|
||||
* @param img pointer to an image object
|
||||
@ -88,18 +84,32 @@ void lv_img_set_file(lv_obj_t * img, const char * fn);
|
||||
* Enable the auto size feature.
|
||||
* If enabled the object size will be same as the picture size.
|
||||
* @param img pointer to an image
|
||||
* @param en true: auto size enable, false: auto size disable
|
||||
* @param autosize_en true: auto size enable, false: auto size disable
|
||||
*/
|
||||
void lv_img_set_auto_size(lv_obj_t * img, bool en);
|
||||
void lv_img_set_auto_size(lv_obj_t * img, bool autosize_en);
|
||||
|
||||
/**
|
||||
* Enable the upscaling with LV_DOWNSCALE.
|
||||
* Enable the upscaling if LV_ANTIALIAS is enabled.
|
||||
* If enabled the object size will be same as the picture size.
|
||||
* @param img pointer to an image
|
||||
* @param en true: upscale enable, false: upscale disable
|
||||
*/
|
||||
void lv_img_set_upscale(lv_obj_t * img, bool en);
|
||||
|
||||
/**
|
||||
* Set the style of an image
|
||||
* @param img pointer to an image object
|
||||
* @param style pointer to a style
|
||||
*/
|
||||
static inline void lv_img_set_style(lv_obj_t *img, lv_style_t *style)
|
||||
{
|
||||
lv_obj_set_style(img, style);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the name of the file set for an image
|
||||
* @param img pointer to an image
|
||||
@ -107,6 +117,7 @@ void lv_img_set_upscale(lv_obj_t * img, bool en);
|
||||
*/
|
||||
const char * lv_img_get_file_name(lv_obj_t * img);
|
||||
|
||||
|
||||
/**
|
||||
* Get the auto size enable attribute
|
||||
* @param img pointer to an image
|
||||
@ -121,6 +132,16 @@ bool lv_img_get_auto_size(lv_obj_t * img);
|
||||
*/
|
||||
bool lv_img_get_upscale(lv_obj_t * img);
|
||||
|
||||
/**
|
||||
* Get the style of an image object
|
||||
* @param img pointer to an image object
|
||||
* @return the style an image
|
||||
*/
|
||||
static inline lv_style_t* lv_img_get_style(lv_obj_t *img)
|
||||
{
|
||||
return lv_obj_get_style(img);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
@ -27,19 +27,8 @@
|
||||
#define LV_LABEL_SCROLL_SPEED (25 << LV_ANTIALIAS) /*Hor, or ver. scroll speed (px/sec) in 'LV_LABEL_LONG_SCROLL' mode*/
|
||||
#endif
|
||||
|
||||
#ifndef LV_LABEL_SCROLL_SPEED_VER
|
||||
#define LV_LABEL_SCROLL_SPEED_VER (10 << LV_ANTIALIAS) /*Ver. scroll speed if hor. scroll is applied too*/
|
||||
#endif
|
||||
#define ANIM_WAIT_CHAR_COUNT 3
|
||||
|
||||
#ifndef LV_LABEL_SCROLL_PLAYBACK_PAUSE
|
||||
#define LV_LABEL_SCROLL_PLAYBACK_PAUSE 500 /*Wait before the scroll turns back in ms*/
|
||||
#endif
|
||||
|
||||
#ifndef LV_LABEL_SCROLL_REPEAT_PAUSE
|
||||
#define LV_LABEL_SCROLL_REPEAT_PAUSE 500 /*Wait before the scroll begins again in ms*/
|
||||
#endif
|
||||
|
||||
#define LV_LABEL_DOT_NUM 3
|
||||
#define LV_LABEL_DOT_END_INV 0xFFFF
|
||||
|
||||
/**********************
|
||||
@ -49,14 +38,18 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_res_t lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param);
|
||||
static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_label_refr_text(lv_obj_t * label);
|
||||
static void lv_label_revert_dots(lv_obj_t *label);
|
||||
static void lv_label_set_offset_x(lv_obj_t * label, cord_t x);
|
||||
static void lv_label_set_offset_y(lv_obj_t * label, cord_t y);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_signal_func_t ancestor_signal;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
@ -76,13 +69,14 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Create a basic object*/
|
||||
lv_obj_t * new_label = lv_obj_create(par, copy);
|
||||
dm_assert(new_label);
|
||||
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_label);
|
||||
|
||||
/*Extend the basic object to a label object*/
|
||||
lv_obj_allocate_ext_attr(new_label, sizeof(lv_label_ext_t));
|
||||
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(new_label);
|
||||
dm_assert(ext);
|
||||
ext->txt = NULL;
|
||||
ext->text = NULL;
|
||||
ext->static_txt = 0;
|
||||
ext->recolor = 0;
|
||||
ext->no_break = 0;
|
||||
@ -90,6 +84,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
ext->align = LV_LABEL_ALIGN_LEFT;
|
||||
ext->dot_end = LV_LABEL_DOT_END_INV;
|
||||
ext->long_mode = LV_LABEL_LONG_EXPAND;
|
||||
ext->anim_speed = LV_LABEL_SCROLL_SPEED;
|
||||
ext->offset.x = 0;
|
||||
ext->offset.y = 0;
|
||||
lv_obj_set_design_func(new_label, lv_label_design);
|
||||
@ -110,7 +105,16 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
lv_label_set_body_draw(new_label, lv_label_get_body_draw(copy));
|
||||
lv_label_set_align(new_label, lv_label_get_align(copy));
|
||||
if(copy_ext->static_txt == 0) lv_label_set_text(new_label, lv_label_get_text(copy));
|
||||
else lv_label_set_text_static(new_label, lv_label_get_text(copy));
|
||||
else lv_label_set_static_text(new_label, lv_label_get_text(copy));
|
||||
|
||||
/*In DOT mode save the text byte-to-byte because a '\0' can be in the middle*/
|
||||
if(copy_ext->long_mode == LV_LABEL_LONG_DOT) {
|
||||
ext->text = dm_realloc(ext->text, dm_get_size(copy_ext->text));
|
||||
memcpy(ext->text, copy_ext->text, dm_get_size(copy_ext->text));
|
||||
}
|
||||
|
||||
memcpy(ext->dot_tmp, copy_ext->dot_tmp, sizeof(ext->dot_tmp));
|
||||
ext->dot_end = copy_ext->dot_end;
|
||||
|
||||
/*Refresh the style with new signal function*/
|
||||
lv_obj_refresh_style(new_label);
|
||||
@ -118,46 +122,6 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
return new_label;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Signal function of the label
|
||||
* @param label pointer to a label object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_obj_signal(label, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
if(ext->static_txt == 0) {
|
||||
dm_free(ext->txt);
|
||||
ext->txt = NULL;
|
||||
}
|
||||
}
|
||||
else if(sign == LV_SIGNAL_STYLE_CHG) {
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
else if (sign == LV_SIGNAL_CORD_CHG) {
|
||||
if(area_get_width(&label->coords) != area_get_width(param) ||
|
||||
area_get_height(&label->coords) != area_get_height(param))
|
||||
{
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
@ -179,19 +143,19 @@ void lv_label_set_text(lv_obj_t * label, const char * text)
|
||||
return;
|
||||
}
|
||||
|
||||
if(ext->txt == text) {
|
||||
if(ext->text == text) {
|
||||
/*If set its own text then reallocate it (maybe its size changed)*/
|
||||
ext->txt = dm_realloc(ext->txt, strlen(ext->txt) + 1);
|
||||
ext->text = dm_realloc(ext->text, strlen(ext->text) + 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;
|
||||
if(ext->text != NULL && ext->static_txt == 0) {
|
||||
dm_free(ext->text);
|
||||
ext->text = NULL;
|
||||
}
|
||||
|
||||
ext->txt = dm_alloc(len);
|
||||
strcpy(ext->txt, text);
|
||||
ext->text = dm_alloc(len);
|
||||
strcpy(ext->text, text);
|
||||
ext->static_txt = 0; /*Now the text is dynamically allocated*/
|
||||
}
|
||||
|
||||
@ -204,26 +168,26 @@ void lv_label_set_text(lv_obj_t * label, const char * text)
|
||||
* @param array array of characters or NULL to refresh the label
|
||||
* @param size the size of 'array' in bytes
|
||||
*/
|
||||
void lv_label_set_text_array(lv_obj_t * label, const char * array, uint16_t size)
|
||||
void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size)
|
||||
{
|
||||
lv_obj_invalidate(label);
|
||||
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
|
||||
/*If trying to set its own text or the array is NULL then refresh */
|
||||
if(array == ext->txt || array == NULL) {
|
||||
if(array == ext->text || array == NULL) {
|
||||
lv_label_refr_text(label);
|
||||
return;
|
||||
}
|
||||
|
||||
/*Allocate space for the new text*/
|
||||
if(ext->txt != NULL && ext->static_txt == 0) {
|
||||
dm_free(ext->txt);
|
||||
ext->txt = NULL;
|
||||
if(ext->text != NULL && ext->static_txt == 0) {
|
||||
dm_free(ext->text);
|
||||
ext->text = NULL;
|
||||
}
|
||||
ext->txt = dm_alloc(size + 1);
|
||||
memcpy(ext->txt, array, size);
|
||||
ext->txt[size] = '\0';
|
||||
ext->text = dm_alloc(size + 1);
|
||||
memcpy(ext->text, array, size);
|
||||
ext->text[size] = '\0';
|
||||
ext->static_txt = 0; /*Now the text is dynamically allocated*/
|
||||
|
||||
lv_label_refr_text(label);
|
||||
@ -235,58 +199,22 @@ void lv_label_set_text_array(lv_obj_t * label, const char * array, uint16_t size
|
||||
* @param label pointer to a label object
|
||||
* @param text pointer to a text. NULL to refresh with the current text.
|
||||
*/
|
||||
void lv_label_set_text_static(lv_obj_t * label, const char * text)
|
||||
void lv_label_set_static_text(lv_obj_t * label, const char * text)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
if(ext->static_txt == 0 && ext->txt != NULL) {
|
||||
dm_free(ext->txt);
|
||||
ext->txt = NULL;
|
||||
if(ext->static_txt == 0 && ext->text != NULL) {
|
||||
dm_free(ext->text);
|
||||
ext->text = NULL;
|
||||
}
|
||||
|
||||
if(text != NULL) {
|
||||
ext->static_txt = 1;
|
||||
ext->txt = (char *) text;
|
||||
ext->text = (char *) text;
|
||||
}
|
||||
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a text to the label. The label current label text can not be static.
|
||||
* @param label pointer to label object
|
||||
* @param pos character index to insert Expressed in character index and not byte index (Different in UTF-8)
|
||||
* 0: before first char.
|
||||
* LV_LABEL_POS_LAST: after 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)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
|
||||
/*Can not append to static text*/
|
||||
if(ext->static_txt != 0) return;
|
||||
|
||||
lv_obj_invalidate(label);
|
||||
|
||||
/*Allocate space for the new text*/
|
||||
uint32_t old_len = strlen(ext->txt);
|
||||
uint32_t ins_len = strlen(txt);
|
||||
uint32_t new_len = ins_len + old_len;
|
||||
ext->txt = dm_realloc(ext->txt, new_len + 1);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the label with longer text then the object size
|
||||
* @param label pointer to a label object
|
||||
@ -307,11 +235,20 @@ void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode)
|
||||
if(long_mode == LV_LABEL_LONG_ROLL) ext->expand = 1;
|
||||
else ext->expand = 0;
|
||||
|
||||
/*Restore the character under the dots*/
|
||||
if(ext->long_mode == LV_LABEL_LONG_DOT && ext->dot_end != LV_LABEL_DOT_END_INV) {
|
||||
lv_label_revert_dots(label);
|
||||
}
|
||||
|
||||
ext->long_mode = long_mode;
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the align of the label (left or center)
|
||||
* @param label pointer to a label object
|
||||
* @param align 'LV_LABEL_ALIGN_LEFT' or 'LV_LABEL_ALIGN_LEFT'
|
||||
*/
|
||||
void lv_label_set_align(lv_obj_t *label, lv_label_align_t align)
|
||||
{
|
||||
lv_label_ext_t *ext = lv_obj_get_ext_attr(label);
|
||||
@ -325,13 +262,13 @@ void lv_label_set_align(lv_obj_t *label, lv_label_align_t align)
|
||||
/**
|
||||
* Enable the recoloring by in-line commands
|
||||
* @param label pointer to a label object
|
||||
* @param recolor_enable true: enable recoloring, false: disable
|
||||
* @param recolor_en true: enable recoloring, false: disable
|
||||
*/
|
||||
void lv_label_set_recolor(lv_obj_t * label, bool recolor_enable)
|
||||
void lv_label_set_recolor(lv_obj_t * label, bool recolor_en)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
|
||||
ext->recolor = recolor_enable == false ? 0 : 1;
|
||||
ext->recolor = recolor_en == false ? 0 : 1;
|
||||
|
||||
lv_label_refr_text(label); /*Refresh the text because the potential colo codes in text needs to be hided or revealed*/
|
||||
}
|
||||
@ -339,12 +276,12 @@ void lv_label_set_recolor(lv_obj_t * label, bool recolor_enable)
|
||||
/**
|
||||
* Set the label to ignore (or accept) line breaks on '\n'
|
||||
* @param label pointer to a label object
|
||||
* @param no_break_enable true: ignore line breaks, false: make line breaks on '\n'
|
||||
* @param no_break_en true: ignore line breaks, false: make line breaks on '\n'
|
||||
*/
|
||||
void lv_label_set_no_break(lv_obj_t * label, bool no_break_enable)
|
||||
void lv_label_set_no_break(lv_obj_t * label, bool no_break_en)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
ext->no_break = no_break_enable == false ? 0 : 1;
|
||||
ext->no_break = no_break_en == false ? 0 : 1;
|
||||
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
@ -352,16 +289,27 @@ void lv_label_set_no_break(lv_obj_t * label, bool no_break_enable)
|
||||
/**
|
||||
* Set the label to draw (or not draw) background specified in its style's body
|
||||
* @param label pointer to a label object
|
||||
* @param body_enable true: draw body; false: don't draw body
|
||||
* @param body_en true: draw body; false: don't draw body
|
||||
*/
|
||||
void lv_label_set_body_draw(lv_obj_t *label, bool body_enable)
|
||||
void lv_label_set_body_draw(lv_obj_t *label, bool body_en)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
ext->body_draw = body_enable == false ? 0 : 1;
|
||||
ext->body_draw = body_en == false ? 0 : 1;
|
||||
|
||||
lv_obj_invalidate(label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes
|
||||
* @param label pointer to a label object
|
||||
* @param anim_speed speed of animation in px/sec unit
|
||||
*/
|
||||
void lv_label_set_anim_speed(lv_obj_t *label, uint16_t anim_speed)
|
||||
{
|
||||
lv_label_ext_t *ext = lv_obj_get_ext_attr(label);
|
||||
ext->anim_speed = anim_speed;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@ -375,7 +323,7 @@ char * lv_label_get_text(lv_obj_t * label)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
|
||||
return ext->txt;
|
||||
return ext->text;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -433,6 +381,16 @@ bool lv_label_get_body_draw(lv_obj_t *label)
|
||||
return ext->body_draw == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes
|
||||
* @param label pointer to a label object
|
||||
* @return speed of animation in px/sec unit
|
||||
*/
|
||||
uint16_t lv_label_get_anim_speed(lv_obj_t *label)
|
||||
{
|
||||
lv_label_ext_t *ext = lv_obj_get_ext_attr(label);
|
||||
return ext->anim_speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relative x and y coordinates of a letter
|
||||
@ -583,6 +541,70 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
|
||||
}
|
||||
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Insert a text to the label. The label text can not be static.
|
||||
* @param label pointer to a label object
|
||||
* @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8)
|
||||
* 0: before first char.
|
||||
* LV_LABEL_POS_LAST: after 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)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
|
||||
/*Can not append to static text*/
|
||||
if(ext->static_txt != 0) return;
|
||||
|
||||
lv_obj_invalidate(label);
|
||||
|
||||
/*Allocate space for the new text*/
|
||||
uint32_t old_len = strlen(ext->text);
|
||||
uint32_t ins_len = strlen(txt);
|
||||
uint32_t new_len = ins_len + old_len;
|
||||
ext->text = dm_realloc(ext->text, new_len + 1);
|
||||
|
||||
if(pos == LV_LABEL_POS_LAST) {
|
||||
#if TXT_UTF8 == 0
|
||||
pos = old_len;
|
||||
#else
|
||||
pos = txt_len(ext->text);
|
||||
#endif
|
||||
}
|
||||
|
||||
txt_ins(ext->text, pos, txt);
|
||||
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete characters from a label. The label text can not be static.
|
||||
* @param label pointer to a label object
|
||||
* @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8)
|
||||
* 0: before first char.
|
||||
* @param cnt number of characters to cut
|
||||
*/
|
||||
void lv_label_cut_text(lv_obj_t * label, uint32_t pos, uint32_t cnt)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
|
||||
/*Can not append to static text*/
|
||||
if(ext->static_txt != 0) return;
|
||||
|
||||
lv_obj_invalidate(label);
|
||||
|
||||
char * label_txt = lv_label_get_text(label);
|
||||
/*Delete the characters*/
|
||||
txt_cut(label_txt, pos, cnt);
|
||||
|
||||
/*Refresh the label*/
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@ -626,11 +648,53 @@ static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mod
|
||||
if(ext->no_break != 0) flag |= TXT_FLAG_NO_BREAK;
|
||||
if(ext->align == LV_LABEL_ALIGN_CENTER) flag |= TXT_FLAG_CENTER;
|
||||
|
||||
lv_draw_label(&cords, mask, style, ext->txt, flag, &ext->offset);
|
||||
lv_draw_label(&cords, mask, style, ext->text, flag, &ext->offset);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Signal function of the label
|
||||
* @param label pointer to a label object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
||||
*/
|
||||
static lv_res_t lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param)
|
||||
{
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = ancestor_signal(label, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
if(ext->static_txt == 0) {
|
||||
dm_free(ext->text);
|
||||
ext->text = NULL;
|
||||
}
|
||||
}
|
||||
else if(sign == LV_SIGNAL_STYLE_CHG) {
|
||||
/*Revert dots for proper refresh*/
|
||||
lv_label_revert_dots(label);
|
||||
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
else if (sign == LV_SIGNAL_CORD_CHG) {
|
||||
if(area_get_width(&label->coords) != area_get_width(param) ||
|
||||
area_get_height(&label->coords) != area_get_height(param))
|
||||
{
|
||||
lv_label_revert_dots(label);
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the label with its text stored in its extended data
|
||||
* @param label pointer to a label object
|
||||
@ -639,14 +703,12 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
|
||||
if(ext->txt == NULL) return;
|
||||
if(ext->text == NULL) return;
|
||||
|
||||
cord_t max_w = lv_obj_get_width(label);
|
||||
lv_style_t * style = lv_obj_get_style(label);
|
||||
const font_t * font = style->text.font;
|
||||
|
||||
ext->dot_end = LV_LABEL_DOT_END_INV; /*Initialize the dot end index*/
|
||||
|
||||
/*If the width will be expanded set the max length to very big */
|
||||
if(ext->long_mode == LV_LABEL_LONG_EXPAND ||
|
||||
ext->long_mode == LV_LABEL_LONG_SCROLL) {
|
||||
@ -659,9 +721,9 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR;
|
||||
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
|
||||
if(ext->no_break != 0) flag |= TXT_FLAG_NO_BREAK;
|
||||
txt_get_size(&size, ext->txt, font, style->text.letter_space, style->text.line_space, max_w, flag);
|
||||
txt_get_size(&size, ext->text, font, style->text.letter_space, style->text.line_space, max_w, flag);
|
||||
|
||||
/*Refresh the full size in expand mode*/
|
||||
/*Set the full size in expand mode*/
|
||||
if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) {
|
||||
lv_obj_set_size(label, size.x, size.y);
|
||||
|
||||
@ -682,29 +744,19 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
anim.end_cb = NULL;
|
||||
anim.path = anim_get_path(ANIM_PATH_LIN);
|
||||
anim.time = 3000;
|
||||
anim.playback_pause = LV_LABEL_SCROLL_PLAYBACK_PAUSE;
|
||||
anim.repeat_pause = LV_LABEL_SCROLL_REPEAT_PAUSE;
|
||||
anim.playback_pause = (((font_get_width(style->text.font, ' ') + style->text.letter_space) * 1000) / ext->anim_speed) * ANIM_WAIT_CHAR_COUNT;
|
||||
anim.repeat_pause = anim.playback_pause;
|
||||
|
||||
bool hor_anim = false;
|
||||
if(lv_obj_get_width(label) > lv_obj_get_width(parent)) {
|
||||
anim.end = lv_obj_get_width(parent) - lv_obj_get_width(label) -
|
||||
(font_get_width(font, ' ') >> FONT_ANTIALIAS);
|
||||
anim.fp = (anim_fp_t) lv_obj_set_x;
|
||||
anim.time = anim_speed_to_time(LV_LABEL_SCROLL_SPEED, anim.start, anim.end);
|
||||
anim.time = anim_speed_to_time(ext->anim_speed, anim.start, anim.end);
|
||||
anim_create(&anim);
|
||||
hor_anim = true;
|
||||
}
|
||||
|
||||
if(lv_obj_get_height(label) > lv_obj_get_height(parent)) {
|
||||
} else if(lv_obj_get_height(label) > lv_obj_get_height(parent)) {
|
||||
anim.end = lv_obj_get_height(parent) - lv_obj_get_height(label) - font_get_height_scale(font);
|
||||
anim.fp = (anim_fp_t)lv_obj_set_y;
|
||||
|
||||
/*Different animation speed if horizontal animation is created too*/
|
||||
if(hor_anim == false) {
|
||||
anim.time = anim_speed_to_time(LV_LABEL_SCROLL_SPEED, anim.start, anim.end);
|
||||
} else {
|
||||
anim.time = anim_speed_to_time(LV_LABEL_SCROLL_SPEED_VER, anim.start, anim.end);
|
||||
}
|
||||
anim.time = anim_speed_to_time(ext->anim_speed, anim.start, anim.end);
|
||||
anim_create(&anim);
|
||||
}
|
||||
}
|
||||
@ -719,8 +771,8 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
anim.act_time = 0;
|
||||
anim.end_cb = NULL;
|
||||
anim.path = anim_get_path(ANIM_PATH_LIN);
|
||||
anim.playback_pause = LV_LABEL_SCROLL_PLAYBACK_PAUSE;
|
||||
anim.repeat_pause = LV_LABEL_SCROLL_REPEAT_PAUSE;
|
||||
anim.playback_pause = (((font_get_width(style->text.font, ' ') + style->text.letter_space) * 1000) / ext->anim_speed) * ANIM_WAIT_CHAR_COUNT;;
|
||||
anim.repeat_pause = anim.playback_pause;
|
||||
|
||||
bool hor_anim = false;
|
||||
if(size.x > lv_obj_get_width(label)) {
|
||||
@ -736,24 +788,67 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
ext->offset.x = 0;
|
||||
}
|
||||
|
||||
if(size.y > lv_obj_get_height(label)) {
|
||||
if(size.y > lv_obj_get_height(label) && hor_anim == false) {
|
||||
anim.end = lv_obj_get_height(label) - size.y - (font_get_height_scale(font));
|
||||
anim.fp = (anim_fp_t)lv_label_set_offset_y;
|
||||
|
||||
/*Different animation speed if horizontal animation is created too*/
|
||||
if(hor_anim == false) {
|
||||
anim.time = anim_speed_to_time(LV_LABEL_SCROLL_SPEED, anim.start, anim.end);
|
||||
} else {
|
||||
anim.time = anim_speed_to_time(LV_LABEL_SCROLL_SPEED_VER, anim.start, anim.end);
|
||||
}
|
||||
anim.time = anim_speed_to_time(ext->anim_speed, anim.start, anim.end);
|
||||
anim_create(&anim);
|
||||
} else {
|
||||
/*Delete the offset animation if not required*/
|
||||
anim_del(label, (anim_fp_t) lv_label_set_offset_y);
|
||||
ext->offset.y = 0;
|
||||
|
||||
}
|
||||
}
|
||||
else if(ext->long_mode == LV_LABEL_LONG_DOT) {
|
||||
if(size.y <= lv_obj_get_height(label)) { /*No dots are required, the text is short enough*/
|
||||
ext->dot_end = LV_LABEL_DOT_END_INV;
|
||||
} else if(txt_len(ext->text) <= LV_LABEL_DOT_NUM) { /*Don't turn to dots all the characters*/
|
||||
ext->dot_end = LV_LABEL_DOT_END_INV;
|
||||
} else {
|
||||
point_t p;
|
||||
p.x = lv_obj_get_width(label) - (font_get_width_scale(style->text.font, '.') + style->text.letter_space) * LV_LABEL_DOT_NUM; /*Shrink with dots*/
|
||||
p.y = lv_obj_get_height(label);
|
||||
p.y -= p.y % (font_get_height_scale(style->text.font) + style->text.line_space); /*Round down to the last line*/
|
||||
p.y -= style->text.line_space; /*Trim the last line space*/
|
||||
uint32_t letter_id = lv_label_get_letter_on(label, &p);
|
||||
|
||||
|
||||
#if TXT_UTF8 == 0
|
||||
/*Save letters under the dots and replace them with dots*/
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_LABEL_DOT_NUM; i++) {
|
||||
ext->dot_tmp[i] = ext->text[letter_id + i];
|
||||
ext->text[letter_id + i] = '.';
|
||||
}
|
||||
|
||||
ext->dot_tmp[LV_LABEL_DOT_NUM] = ext->text[letter_id + LV_LABEL_DOT_NUM];
|
||||
ext->text[letter_id + LV_LABEL_DOT_NUM] = '\0';
|
||||
|
||||
ext->dot_end = letter_id + LV_LABEL_DOT_NUM;
|
||||
#else
|
||||
/*Save letters under the dots and replace them with dots*/
|
||||
uint32_t i;
|
||||
uint32_t byte_id = txt_utf8_get_byte_id(ext->text, letter_id);
|
||||
uint32_t byte_id_ori = byte_id;
|
||||
uint8_t len = 0;
|
||||
for(i = 0; i <= LV_LABEL_DOT_NUM; i++) {
|
||||
len += txt_utf8_size(ext->text[byte_id]);
|
||||
txt_utf8_next(ext->text, &byte_id);
|
||||
}
|
||||
|
||||
memcpy(ext->dot_tmp, &ext->text[byte_id_ori], len);
|
||||
ext->dot_tmp[len] = '\0'; /*Close with a zero*/
|
||||
|
||||
for(i = 0; i < LV_LABEL_DOT_NUM; i++) {
|
||||
ext->text[byte_id_ori + i] = '.';
|
||||
}
|
||||
ext->text[byte_id_ori + LV_LABEL_DOT_NUM] = '\0';
|
||||
|
||||
ext->dot_end = letter_id + LV_LABEL_DOT_NUM;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
/*In break mode only the height can change*/
|
||||
else if (ext->long_mode == LV_LABEL_LONG_BREAK) {
|
||||
lv_obj_set_height(label, size.y);
|
||||
@ -763,6 +858,30 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
lv_obj_invalidate(label);
|
||||
}
|
||||
|
||||
static void lv_label_revert_dots(lv_obj_t *label)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
|
||||
if(ext->long_mode != LV_LABEL_LONG_DOT) return;
|
||||
if(ext->dot_end == LV_LABEL_DOT_END_INV) return;
|
||||
#if TXT_UTF8 == 0
|
||||
uint32_t i;
|
||||
for(i = 0; i <= LV_LABEL_DOT_NUM; i++) {
|
||||
ext->text[ext->dot_end - i] = ext->dot_tmp[LV_LABEL_DOT_NUM - i];
|
||||
}
|
||||
#else
|
||||
uint32_t letter_i = ext->dot_end - LV_LABEL_DOT_NUM;
|
||||
uint32_t byte_i = txt_utf8_get_byte_id(ext->text, letter_i);
|
||||
|
||||
/*Restore the characters*/
|
||||
uint8_t i = 0;
|
||||
while(ext->dot_tmp[i] != '\0') {
|
||||
ext->text[byte_i + i] = ext->dot_tmp[i];
|
||||
i++;
|
||||
}
|
||||
#endif
|
||||
|
||||
ext->dot_end = LV_LABEL_DOT_END_INV;
|
||||
}
|
||||
|
||||
static void lv_label_set_offset_x(lv_obj_t * label, cord_t x)
|
||||
{
|
||||
|
@ -24,8 +24,9 @@ extern "C" {
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_LABEL_DOT_NUM 3
|
||||
#define LV_LABEL_DOT_NUM 3
|
||||
#define LV_LABEL_POS_LAST 0xFFFF
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
@ -36,6 +37,7 @@ 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_SCROLL, /*Expand the object size and scroll the text on the parent (move the label object)*/
|
||||
LV_LABEL_LONG_DOT, /*Keep the size and write dots at the end if the text is too long*/
|
||||
LV_LABEL_LONG_ROLL, /*Keep the size and roll the text infinitely*/
|
||||
}lv_label_long_mode_t;
|
||||
|
||||
@ -50,14 +52,15 @@ typedef struct
|
||||
{
|
||||
/*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
char * txt; /*Text of the label*/
|
||||
char * text; /*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)*/
|
||||
char dot_tmp[LV_LABEL_DOT_NUM * 4 + 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 anim_speed; /*Speed of scroll and roll animation in px/sec unit*/
|
||||
point_t offset; /*Text draw position offset*/
|
||||
uint8_t static_txt :1; /*Flag to indicate the text is static*/
|
||||
uint8_t align :2; /*Align type from 'lv_label_align_t'*/
|
||||
@ -71,6 +74,7 @@ typedef struct
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
|
||||
/**
|
||||
* Create a label objects
|
||||
* @param par pointer to an object, it will be the parent of the new label
|
||||
@ -79,13 +83,9 @@ typedef struct
|
||||
*/
|
||||
lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
|
||||
/**
|
||||
* Signal function of the label
|
||||
* @param label pointer to a label object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param);
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set a new text for a label. Memory will be allocated to store the text by the label.
|
||||
@ -101,7 +101,7 @@ void lv_label_set_text(lv_obj_t * label, const char * text);
|
||||
* @param array array of characters or NULL to refresh the label
|
||||
* @param size the size of 'array' in bytes
|
||||
*/
|
||||
void lv_label_set_text_array(lv_obj_t * label, const char * array, uint16_t size);
|
||||
void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size);
|
||||
|
||||
/**
|
||||
* Set a static text. It will not be saved by the label so the 'text' variable
|
||||
@ -109,19 +109,7 @@ void lv_label_set_text_array(lv_obj_t * label, const char * array, uint16_t size
|
||||
* @param label pointer to a label object
|
||||
* @param text pointer to a text. NULL to refresh with the current text.
|
||||
*/
|
||||
void lv_label_set_text_static(lv_obj_t * label, const char * text);
|
||||
|
||||
/**
|
||||
* Insert a text to the label. The label current label text can not be static.
|
||||
* @param label pointer to label object
|
||||
* @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_ins_text(lv_obj_t * label, uint32_t pos, const char * txt);
|
||||
void lv_label_set_static_text(lv_obj_t * label, const char * text);
|
||||
|
||||
/**
|
||||
* Set the behavior of the label with longer text then the object size
|
||||
@ -130,26 +118,53 @@ void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt);
|
||||
*/
|
||||
void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode);
|
||||
|
||||
|
||||
/**
|
||||
* Set the align of the label (left or center)
|
||||
* @param label pointer to a label object
|
||||
* @param align 'LV_LABEL_ALIGN_LEFT' or 'LV_LABEL_ALIGN_LEFT'
|
||||
*/
|
||||
void lv_label_set_align(lv_obj_t *label, lv_label_align_t align);
|
||||
|
||||
/**
|
||||
* Enable the recoloring by in-line commands
|
||||
* @param label pointer to a label object
|
||||
* @param recolor true: enable recoloring, false: disable
|
||||
* @param recolor_en true: enable recoloring, false: disable
|
||||
*/
|
||||
void lv_label_set_recolor(lv_obj_t * label, bool recolor);
|
||||
|
||||
void lv_label_set_recolor(lv_obj_t * label, bool recolor_en);
|
||||
|
||||
/**
|
||||
* Set the label the ignore (or accept) line breaks on '\n'
|
||||
* Set the label to ignore (or accept) line breaks on '\n'
|
||||
* @param label pointer to a label object
|
||||
* @param en true: ignore line breaks, false: make line breaks on '\n'
|
||||
* @param no_break_en true: ignore line breaks, false: make line breaks on '\n'
|
||||
*/
|
||||
void lv_label_set_no_break(lv_obj_t * label, bool en);
|
||||
void lv_label_set_no_break(lv_obj_t * label, bool no_break_en);
|
||||
|
||||
/**
|
||||
* Set the label to draw (or not draw) background specified in its style's body
|
||||
* @param label pointer to a label object
|
||||
* @param body_en true: draw body; false: don't draw body
|
||||
*/
|
||||
void lv_label_set_body_draw(lv_obj_t *label, bool body_en);
|
||||
|
||||
void lv_label_set_body_draw(lv_obj_t *label, bool body_enable);
|
||||
/**
|
||||
* Set the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes
|
||||
* @param label pointer to a label object
|
||||
* @param anim_speed speed of animation in px/sec unit
|
||||
*/
|
||||
void lv_label_set_anim_speed(lv_obj_t *label, uint16_t anim_speed);
|
||||
|
||||
/**
|
||||
* Set the style of an label
|
||||
* @param label pointer to an label object
|
||||
* @param style pointer to a style
|
||||
*/
|
||||
static inline void lv_label_set_style(lv_obj_t *label, lv_style_t *style)
|
||||
{
|
||||
lv_obj_set_style(label, style);
|
||||
}
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the text of a label
|
||||
@ -158,13 +173,6 @@ void lv_label_set_body_draw(lv_obj_t *label, bool body_enable);
|
||||
*/
|
||||
char * lv_label_get_text(lv_obj_t * label);
|
||||
|
||||
/**
|
||||
* Get the align attribute
|
||||
* @param label pointer to a label object
|
||||
* @return LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER
|
||||
*/
|
||||
lv_label_align_t lv_label_get_align(lv_obj_t * label);
|
||||
|
||||
/**
|
||||
* Get the long mode of a label
|
||||
* @param label pointer to a label object
|
||||
@ -172,6 +180,13 @@ lv_label_align_t lv_label_get_align(lv_obj_t * label);
|
||||
*/
|
||||
lv_label_long_mode_t lv_label_get_long_mode(lv_obj_t * label);
|
||||
|
||||
/**
|
||||
* Get the align attribute
|
||||
* @param label pointer to a label object
|
||||
* @return LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER
|
||||
*/
|
||||
lv_label_align_t lv_label_get_align(lv_obj_t * label);
|
||||
|
||||
/**
|
||||
* Get the recoloring attribute
|
||||
* @param label pointer to a label object
|
||||
@ -179,14 +194,12 @@ lv_label_long_mode_t lv_label_get_long_mode(lv_obj_t * label);
|
||||
*/
|
||||
bool lv_label_get_recolor(lv_obj_t * label);
|
||||
|
||||
|
||||
/**
|
||||
* Get the no break attribute
|
||||
* @param label pointer to a label object
|
||||
* @return true: no_break_enabled (ignore '\n' line breaks); false: make line breaks on '\n'
|
||||
*/
|
||||
bool lv_label_get_no_break(lv_obj_t * label);
|
||||
|
||||
/**
|
||||
* Get the body draw attribute
|
||||
* @param label pointer to a label object
|
||||
@ -195,16 +208,16 @@ bool lv_label_get_no_break(lv_obj_t * label);
|
||||
bool lv_label_get_body_draw(lv_obj_t *label);
|
||||
|
||||
/**
|
||||
* Get the password mode
|
||||
* Get the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes
|
||||
* @param label pointer to a label object
|
||||
* @return true: password mode is enabled, false: disable
|
||||
* @return speed of animation in px/sec unit
|
||||
*/
|
||||
bool lv_label_get_pwd_mode(lv_obj_t * label);
|
||||
uint16_t lv_label_get_anim_speed(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);
|
||||
@ -214,9 +227,43 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos);
|
||||
* @param label pointer to label object
|
||||
* @param pos pointer to point with coordinates on a the label
|
||||
* @return the index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter)
|
||||
* Expressed in character index and not byte index (different in UTF-8)
|
||||
*/
|
||||
uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos);
|
||||
|
||||
/**
|
||||
* Get the style of an label object
|
||||
* @param label pointer to an label object
|
||||
* @return the style an label
|
||||
*/
|
||||
static inline lv_style_t* lv_label_get_style(lv_obj_t *label)
|
||||
{
|
||||
return lv_obj_get_style(label);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Insert a text to the label. The label text can not be static.
|
||||
* @param label pointer to a label object
|
||||
* @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8)
|
||||
* 0: before first char.
|
||||
* LV_LABEL_POS_LAST: after 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);
|
||||
|
||||
/**
|
||||
* Delete characters from a label. The label text can not be static.
|
||||
* @param label pointer to a label object
|
||||
* @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8)
|
||||
* 0: before first char.
|
||||
* @param cnt number of characters to cut
|
||||
*/
|
||||
void lv_label_cut_text(lv_obj_t * label, uint32_t pos, uint32_t cnt);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
@ -29,10 +29,12 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_line_design(lv_obj_t * line, const area_t * mask, lv_design_mode_t mode);
|
||||
static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_signal_func_t ancestor_signal;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@ -52,6 +54,7 @@ lv_obj_t * lv_line_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
/*Create a basic object*/
|
||||
lv_obj_t * new_line = lv_obj_create(par, copy);
|
||||
dm_assert(new_line);
|
||||
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_line);
|
||||
|
||||
/*Extend the basic object to line object*/
|
||||
lv_line_ext_t * ext = lv_obj_allocate_ext_attr(new_line, sizeof(lv_line_ext_t));
|
||||
@ -67,13 +70,14 @@ lv_obj_t * lv_line_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
|
||||
/*Init the new line*/
|
||||
if(copy == NULL) {
|
||||
lv_obj_set_size(new_line, LV_DPI, LV_DPI);
|
||||
lv_obj_set_style(new_line, &lv_style_plain);
|
||||
}
|
||||
/*Copy an existing object*/
|
||||
else {
|
||||
lv_line_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
||||
lv_line_set_auto_size(new_line,lv_line_get_auto_size(copy));
|
||||
lv_line_set_y_inv(new_line,lv_line_get_y_inv(copy));
|
||||
lv_line_set_y_invert(new_line,lv_line_get_y_inv(copy));
|
||||
lv_line_set_auto_size(new_line,lv_line_get_auto_size(copy));
|
||||
lv_line_set_upscale(new_line,lv_line_get_upscale(copy));
|
||||
lv_line_set_points(new_line, copy_ext->point_array, copy_ext->point_num);
|
||||
@ -84,31 +88,6 @@ lv_obj_t * lv_line_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
return new_line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the line
|
||||
* @param line pointer to a line object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_obj_signal(line, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
switch(sign) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
@ -149,18 +128,16 @@ void lv_line_set_points(lv_obj_t * line, const point_t * point_a, uint16_t point
|
||||
* Enable (or disable) the auto-size option. The size of the object will fit to its points.
|
||||
* (set width to x max and height to y max)
|
||||
* @param line pointer to a line object
|
||||
* @param autosize true: auto size is enabled, false: auto size is disabled
|
||||
* @param autosize_en true: auto size is enabled, false: auto size is disabled
|
||||
*/
|
||||
void lv_line_set_auto_size(lv_obj_t * line, bool autosize)
|
||||
void lv_line_set_auto_size(lv_obj_t * line, bool autosize_en)
|
||||
{
|
||||
lv_line_ext_t * ext = lv_obj_get_ext_attr(line);
|
||||
|
||||
ext->auto_size = autosize == false ? 0 : 1;
|
||||
ext->auto_size = autosize_en == false ? 0 : 1;
|
||||
|
||||
/*Refresh the object*/
|
||||
if(autosize != false) {
|
||||
lv_line_set_points(line, ext->point_array, ext->point_num);
|
||||
}
|
||||
if(autosize_en) lv_line_set_points(line, ext->point_array, ext->point_num);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,13 +145,13 @@ void lv_line_set_auto_size(lv_obj_t * line, bool autosize)
|
||||
* If enabled then y will be subtracted from the height of the object,
|
||||
* therefore the y=0 coordinate will be on the bottom.
|
||||
* @param line pointer to a line object
|
||||
* @param yinv true: enable the y inversion, false:disable the y inversion
|
||||
* @param yinv_en true: enable the y inversion, false:disable the y inversion
|
||||
*/
|
||||
void lv_line_set_y_inv(lv_obj_t * line, bool yinv)
|
||||
void lv_line_set_y_invert(lv_obj_t * line, bool yinv_en)
|
||||
{
|
||||
lv_line_ext_t * ext = lv_obj_get_ext_attr(line);
|
||||
|
||||
ext->y_inv = yinv == false ? 0 : 1;
|
||||
ext->y_inv = yinv_en == false ? 0 : 1;
|
||||
|
||||
lv_obj_invalidate(line);
|
||||
}
|
||||
@ -184,13 +161,13 @@ void lv_line_set_y_inv(lv_obj_t * line, bool yinv)
|
||||
* @param line pointer to a line object
|
||||
* @param unscale true: enable the point coordinate upscaling
|
||||
*/
|
||||
void lv_line_set_upscale(lv_obj_t * line, bool unscale)
|
||||
void lv_line_set_upscale(lv_obj_t * line, bool unscale_en)
|
||||
{
|
||||
lv_line_ext_t * ext = lv_obj_get_ext_attr(line);
|
||||
|
||||
ext->upscale = unscale == false ? 0 : 1;
|
||||
ext->upscale = unscale_en == false ? 0 : 1;
|
||||
|
||||
/*Refresh to point to handle auto size*/
|
||||
/*Refresh to point to handle upscale*/
|
||||
lv_line_set_points(line, ext->point_array, ext->point_num);
|
||||
}
|
||||
|
||||
@ -290,4 +267,20 @@ static bool lv_line_design(lv_obj_t * line, const area_t * mask, lv_design_mode_
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the line
|
||||
* @param line pointer to a line object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
||||
*/
|
||||
static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param)
|
||||
{
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = lv_obj_signal(line, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
return LV_RES_OK;
|
||||
}
|
||||
#endif
|
||||
|
@ -41,6 +41,7 @@ typedef struct
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
|
||||
/**
|
||||
* Create a line objects
|
||||
* @param par pointer to an object, it will be the parent of the new line
|
||||
@ -48,13 +49,9 @@ typedef struct
|
||||
*/
|
||||
lv_obj_t * lv_line_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
|
||||
/**
|
||||
* Signal function of the line
|
||||
* @param line pointer to a line object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param);
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set an array of points. The line object will connect these points.
|
||||
@ -69,25 +66,39 @@ void lv_line_set_points(lv_obj_t * line, const point_t * point_a, uint16_t point
|
||||
* Enable (or disable) the auto-size option. The size of the object will fit to its points.
|
||||
* (set width to x max and height to y max)
|
||||
* @param line pointer to a line object
|
||||
* @param autosize true: auto size is enabled, false: auto size is disabled
|
||||
* @param autosize_en true: auto size is enabled, false: auto size is disabled
|
||||
*/
|
||||
void lv_line_set_auto_size(lv_obj_t * line, bool autosize);
|
||||
void lv_line_set_auto_size(lv_obj_t * line, bool autosize_en);
|
||||
|
||||
/**
|
||||
* Enable (or disable) the y coordinate inversion.
|
||||
* If enabled then y will be subtracted from the height of the object,
|
||||
* therefore the y=0 coordinate will be on the bottom.
|
||||
* @param line pointer to a line object
|
||||
* @param yinv true: enable the y inversion, false:disable the y inversion
|
||||
* @param yinv_en true: enable the y inversion, false:disable the y inversion
|
||||
*/
|
||||
void lv_line_set_y_inv(lv_obj_t * line, bool yinv);
|
||||
void lv_line_set_y_invert(lv_obj_t * line, bool yinv_en);
|
||||
|
||||
/**
|
||||
* Enable (or disable) the point coordinate upscaling (compensate LV_DOWNSCALE).
|
||||
* Enable (or disable) the points' coordinate upscaling (if LV_ANTIALIAS is enabled).
|
||||
* @param line pointer to a line object
|
||||
* @param unscale true: enable the point coordinate upscaling
|
||||
* @param unscale_en true: enable the point coordinate upscaling
|
||||
*/
|
||||
void lv_line_set_upscale(lv_obj_t * line, bool unscale);
|
||||
void lv_line_set_upscale(lv_obj_t * line, bool unscale_en);
|
||||
|
||||
/**
|
||||
* Set the style of a line
|
||||
* @param line pointer to a line object
|
||||
* @param style pointer to a style
|
||||
*/
|
||||
static inline void lv_line_set_style(lv_obj_t *line, lv_style_t *style)
|
||||
{
|
||||
lv_obj_set_style(line, style);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the auto size attribute
|
||||
@ -110,6 +121,16 @@ bool lv_line_get_y_inv(lv_obj_t * line);
|
||||
*/
|
||||
bool lv_line_get_upscale(lv_obj_t * line);
|
||||
|
||||
/**
|
||||
* Get the style of an image object
|
||||
* @param line pointer to an line object
|
||||
* @return the style an image
|
||||
*/
|
||||
static inline lv_style_t* lv_line_get_style(lv_obj_t *img)
|
||||
{
|
||||
return lv_obj_get_style(img);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
@ -46,10 +46,6 @@ static lv_design_func_t ancestor_design;
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/*-----------------
|
||||
* Create function
|
||||
*-----------------*/
|
||||
|
||||
/**
|
||||
* Create a template object
|
||||
* @param par pointer to an object, it will be the parent of the new template
|
||||
|
Loading…
x
Reference in New Issue
Block a user