/**1* @file lv_rect.h2*3*/45#ifndef LV_LABEL_H6#define LV_LABEL_H78#ifdef __cplusplus9extern "C" {10#endif1112/*********************13* INCLUDES14*********************/15#ifdef LV_CONF_INCLUDE_SIMPLE16#include "lv_conf.h"17#else18#include "../../lv_conf.h"19#endif2021#if USE_LV_LABEL != 02223#include "../lv_core/lv_obj.h"24#include "../lv_misc/lv_font.h"25#include "../lv_misc/lv_txt.h"26#include "../lv_misc/lv_symbol_def.h"2728/*********************29* DEFINES30*********************/31#define LV_LABEL_DOT_NUM 332#define LV_LABEL_POS_LAST 0xFFFF3334/**********************35* TYPEDEFS36**********************/3738/*Long mode behaviors. Used in 'lv_label_ext_t' */39enum40{41LV_LABEL_LONG_EXPAND, /*Expand the object size to the text size*/42LV_LABEL_LONG_BREAK, /*Keep the object width, break the too long lines and expand the object height*/43LV_LABEL_LONG_SCROLL, /*Expand the object size and scroll the text on the parent (move the label object)*/44LV_LABEL_LONG_DOT, /*Keep the size and write dots at the end if the text is too long*/45LV_LABEL_LONG_ROLL, /*Keep the size and roll the text infinitely*/46LV_LABEL_LONG_CROP, /*Keep the size and crop the text out of it*/47};48typedef uint8_t lv_label_long_mode_t;4950/*Label align policy*/51enum {52LV_LABEL_ALIGN_LEFT,53LV_LABEL_ALIGN_CENTER,54LV_LABEL_ALIGN_RIGHT,55};56typedef uint8_t lv_label_align_t;5758/*Data of label*/59typedef struct60{61/*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/62/*New data for this type */63char * text; /*Text of the label*/64lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/65#if LV_TXT_UTF8 == 066char dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/67#else68char dot_tmp[LV_LABEL_DOT_NUM * 4 + 1]; /*Store the character which are replaced by dots (Handled by the library)*/69#endif7071#if USE_LV_MULTI_LANG72uint16_t lang_txt_id; /*The ID of the text to display*/73#endif74uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/75uint16_t anim_speed; /*Speed of scroll and roll animation in px/sec unit*/76lv_point_t offset; /*Text draw position offset*/77uint8_t static_txt :1; /*Flag to indicate the text is static*/78uint8_t align :2; /*Align type from 'lv_label_align_t'*/79uint8_t recolor :1; /*Enable in-line letter re-coloring*/80uint8_t expand :1; /*Ignore real width (used by the library with LV_LABEL_LONG_ROLL)*/81uint8_t body_draw :1; /*Draw background body*/82} lv_label_ext_t;8384/**********************85* GLOBAL PROTOTYPES86**********************/878889/**90* Create a label objects91* @param par pointer to an object, it will be the parent of the new label92* @param copy pointer to a button object, if not NULL then the new object will be copied from it93* @return pointer to the created button94*/95lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy);9697/*=====================98* Setter functions99*====================*/100101/**102* Set a new text for a label. Memory will be allocated to store the text by the label.103* @param label pointer to a label object104* @param text '\0' terminated character string. NULL to refresh with the current text.105*/106void lv_label_set_text(lv_obj_t * label, const char * text);107108/**109* Set a new text for a label from a character array. The array don't has to be '\0' terminated.110* Memory will be allocated to store the array by the label.111* @param label pointer to a label object112* @param array array of characters or NULL to refresh the label113* @param size the size of 'array' in bytes114*/115void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size);116117/**118* Set a static text. It will not be saved by the label so the 'text' variable119* has to be 'alive' while the label exist.120* @param label pointer to a label object121* @param text pointer to a text. NULL to refresh with the current text.122*/123void lv_label_set_static_text(lv_obj_t * label, const char * text);124125/**126*Set a text ID which means a the same text but on different languages127* @param label pointer to a label object128* @param txt_id ID of the text129*/130#if USE_LV_MULTI_LANG131void lv_label_set_text_id(lv_obj_t * label, uint32_t txt_id);132#endif133134/**135* Set the behavior of the label with longer text then the object size136* @param label pointer to a label object137* @param long_mode the new mode from 'lv_label_long_mode' enum.138* In LV_LONG_BREAK/LONG/ROLL the size of the label should be set AFTER this function139*/140void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode);141142/**143* Set the align of the label (left or center)144* @param label pointer to a label object145* @param align 'LV_LABEL_ALIGN_LEFT' or 'LV_LABEL_ALIGN_LEFT'146*/147void lv_label_set_align(lv_obj_t *label, lv_label_align_t align);148149/**150* Enable the recoloring by in-line commands151* @param label pointer to a label object152* @param en true: enable recoloring, false: disable153*/154void lv_label_set_recolor(lv_obj_t * label, bool en);155156/**157* Set the label to draw (or not draw) background specified in its style's body158* @param label pointer to a label object159* @param en true: draw body; false: don't draw body160*/161void lv_label_set_body_draw(lv_obj_t *label, bool en);162163/**164* Set the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes165* @param label pointer to a label object166* @param anim_speed speed of animation in px/sec unit167*/168void lv_label_set_anim_speed(lv_obj_t *label, uint16_t anim_speed);169170/**171* Set the style of an label172* @param label pointer to an label object173* @param style pointer to a style174*/175static inline void lv_label_set_style(lv_obj_t *label, lv_style_t *style)176{177lv_obj_set_style(label, style);178}179/*=====================180* Getter functions181*====================*/182183/**184* Get the text of a label185* @param label pointer to a label object186* @return the text of the label187*/188char * lv_label_get_text(const lv_obj_t * label);189190#if USE_LV_MULTI_LANG191/**192* Get the text ID of the label. (Used by the multi-language feature)193* @param label pointer to a label object194* @return ID of the text195*/196uint16_t lv_label_get_text_id(lv_obj_t * label);197#endif198199/**200* Get the long mode of a label201* @param label pointer to a label object202* @return the long mode203*/204lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * label);205206/**207* Get the align attribute208* @param label pointer to a label object209* @return LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER210*/211lv_label_align_t lv_label_get_align(const lv_obj_t * label);212213/**214* Get the recoloring attribute215* @param label pointer to a label object216* @return true: recoloring is enabled, false: disable217*/218bool lv_label_get_recolor(const lv_obj_t * label);219220/**221* Get the body draw attribute222* @param label pointer to a label object223* @return true: draw body; false: don't draw body224*/225bool lv_label_get_body_draw(const lv_obj_t *label);226227/**228* Get the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes229* @param label pointer to a label object230* @return speed of animation in px/sec unit231*/232uint16_t lv_label_get_anim_speed(const lv_obj_t *label);233234/**235* Get the relative x and y coordinates of a letter236* @param label pointer to a label object237* @param index index of the letter [0 ... text length]. Expressed in character index, not byte index (different in UTF-8)238* @param pos store the result here (E.g. index = 0 gives 0;0 coordinates)239*/240void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t * pos);241242/**243* Get the index of letter on a relative point of a label244* @param label pointer to label object245* @param pos pointer to point with coordinates on a the label246* @return the index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter)247* Expressed in character index and not byte index (different in UTF-8)248*/249uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos);250251/**252* Get the style of an label object253* @param label pointer to an label object254* @return pointer to the label's style255*/256static inline lv_style_t* lv_label_get_style(const lv_obj_t *label)257{258return lv_obj_get_style(label);259}260261/*=====================262* Other functions263*====================*/264265/**266* Insert a text to the label. The label text can not be static.267* @param label pointer to a label object268* @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8)269* 0: before first char.270* LV_LABEL_POS_LAST: after last char.271* @param txt pointer to the text to insert272*/273void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt);274275/**276* Delete characters from a label. The label text can not be static.277* @param label pointer to a label object278* @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8)279* 0: before first char.280* @param cnt number of characters to cut281*/282void lv_label_cut_text(lv_obj_t * label, uint32_t pos, uint32_t cnt);283284/**********************285* MACROS286**********************/287288#endif /*USE_LV_LABEL*/289290#ifdef __cplusplus291} /* extern "C" */292#endif293294#endif /*LV_LABEL_H*/295296297