1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_objx/lv_label.h

316 lines
10 KiB
C
Raw Normal View History

2016-06-08 07:25:08 +02:00
/**
* @file lv_rect.h
2018-06-19 09:49:58 +02:00
*
2016-06-08 07:25:08 +02:00
*/
#ifndef LV_LABEL_H
#define LV_LABEL_H
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
extern "C" {
#endif
2016-06-08 07:25:08 +02:00
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_LABEL != 0
2016-06-08 07:25:08 +02:00
2019-08-06 09:28:50 -04:00
#include <stdarg.h>
2017-11-30 11:35:33 +01:00
#include "../lv_core/lv_obj.h"
#include "../lv_font/lv_font.h"
#include "../lv_font/lv_symbol_def.h"
2017-11-26 23:57:39 +01:00
#include "../lv_misc/lv_txt.h"
2019-06-14 16:04:15 +02:00
#include "../lv_draw/lv_draw.h"
2016-06-08 07:25:08 +02:00
/*********************
* DEFINES
*********************/
2019-06-06 06:05:40 +02:00
#define LV_LABEL_DOT_NUM 3
#define LV_LABEL_POS_LAST 0xFFFF
#define LV_LABEL_TEXT_SEL_OFF LV_DRAW_LABEL_NO_TXT_SEL
2017-11-13 16:11:05 +01:00
LV_EXPORT_CONST_INT(LV_LABEL_DOT_NUM);
LV_EXPORT_CONST_INT(LV_LABEL_POS_LAST);
LV_EXPORT_CONST_INT(LV_LABEL_TEXT_SEL_OFF);
2016-06-08 07:25:08 +02:00
/**********************
* TYPEDEFS
**********************/
2019-06-27 18:07:26 -04:00
/** Long mode behaviors. Used in 'lv_label_ext_t' */
2019-04-04 07:15:40 +02:00
enum {
2019-06-27 18:07:26 -04:00
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
2019-04-04 07:15:40 +02:00
height*/
2019-06-27 18:07:26 -04:00
LV_LABEL_LONG_DOT, /**< Keep the size and write dots at the end if the text is too long*/
LV_LABEL_LONG_SROLL, /**< Keep the size and roll the text back and forth*/
LV_LABEL_LONG_SROLL_CIRC, /**< Keep the size and roll the text circularly*/
LV_LABEL_LONG_CROP, /**< Keep the size and crop the text out of it*/
2018-09-18 13:59:40 +02:00
};
typedef uint8_t lv_label_long_mode_t;
2019-06-27 18:07:26 -04:00
/** Label align policy*/
2018-09-18 13:59:40 +02:00
enum {
2019-06-27 18:07:26 -04:00
LV_LABEL_ALIGN_LEFT, /**< Align text to left */
LV_LABEL_ALIGN_CENTER, /**< Align text to center */
LV_LABEL_ALIGN_RIGHT, /**< Align text to right */
LV_LABEL_ALIGN_AUTO, /**< Use LEFT or RIGHT depending on the direction of the text (LTR/RTL)*/
2018-09-18 13:59:40 +02:00
};
typedef uint8_t lv_label_align_t;
2019-06-27 18:07:26 -04:00
/** Data of label*/
typedef struct
{
2019-04-04 07:15:40 +02:00
/*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/
/*New data for this type */
char * text; /*Text of the label*/
2019-06-06 06:05:40 +02:00
union
{
char * tmp_ptr; /* Pointer to the allocated memory containing the character which are replaced by dots (Handled
by the library)*/
char tmp[LV_LABEL_DOT_NUM + 1]; /* Directly store the characters if <=4 characters */
2019-04-20 09:05:36 -04:00
} dot;
2019-11-21 12:45:41 +01:00
2019-06-06 06:05:40 +02:00
uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/
#if LV_USE_ANIMATION
2019-06-06 06:05:40 +02:00
uint16_t anim_speed; /*Speed of scroll and roll animation in px/sec unit*/
#endif
2019-11-21 12:45:41 +01:00
lv_point_t offset; /*Text draw position offset*/
#if LV_LABEL_LONG_TXT_HINT
lv_draw_label_hint_t hint; /*Used to buffer info about large text*/
#endif
2019-04-18 07:11:43 +02:00
#if LV_LABEL_TEXT_SEL
2019-12-19 22:44:18 +01:00
uint16_t sel_start;
uint16_t sel_end;
#endif
lv_label_long_mode_t long_mode : 3; /*Determinate what to do with the long texts*/
2019-06-06 06:05:40 +02:00
uint8_t static_txt : 1; /*Flag to indicate the text is static*/
uint8_t align : 2; /*Align type from 'lv_label_align_t'*/
uint8_t recolor : 1; /*Enable in-line letter re-coloring*/
uint8_t expand : 1; /*Ignore real width (used by the library with LV_LABEL_LONG_SROLL)*/
2019-06-06 06:05:40 +02:00
uint8_t dot_tmp_alloc : 1; /*True if dot_tmp has been allocated. False if dot_tmp directly holds up to 4 bytes of
characters */
2018-06-19 09:49:58 +02:00
} lv_label_ext_t;
2019-06-27 18:07:26 -04:00
/** Label styles*/
enum {
LV_LABEL_PART_MAIN,
};
2019-12-19 22:44:18 +01:00
typedef uint8_t lv_label_part_t;
2016-06-08 07:25:08 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a label objects
* @param par pointer to an object, it will be the parent of the new label
* @param copy pointer to a button object, if not NULL then the new object will be copied from it
* @return pointer to the created button
*/
lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy);
2017-11-13 16:11:05 +01:00
/*=====================
* Setter functions
*====================*/
/**
* Set a new text for a label. Memory will be allocated to store the text by the label.
* @param label pointer to a label object
* @param text '\0' terminated character string. NULL to refresh with the current text.
*/
2016-10-07 11:15:46 +02:00
void lv_label_set_text(lv_obj_t * label, const char * text);
2019-08-06 09:28:50 -04:00
/**
* Set a new formatted text for a label. Memory will be allocated to store the text by the label.
* @param label pointer to a label object
* @param fmt `printf`-like format
*/
void lv_label_set_text_fmt(lv_obj_t * label, const char * fmt, ...);
/**
* Set a new text for a label from a character array. The array don't has to be '\0' terminated.
* Memory will be allocated to store the array by the label.
* @param label pointer to a label object
* @param array array of characters or NULL to refresh the label
* @param size the size of 'array' in bytes
*/
2017-11-13 16:11:05 +01:00
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
* has to be 'alive' while the label exist.
* @param label pointer to a label object
* @param text pointer to a text. NULL to refresh with the current text.
*/
2017-11-13 16:11:05 +01:00
void lv_label_set_static_text(lv_obj_t * label, const char * text);
2017-04-21 09:15:39 +02:00
/**
* Set the behavior of the label with longer text then the object size
* @param label pointer to a label object
* @param long_mode the new mode from 'lv_label_long_mode' enum.
2019-04-04 07:15:40 +02:00
* In LV_LONG_BREAK/LONG/ROLL the size of the label should be set AFTER this
* function
*/
void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode);
2017-11-13 16:11:05 +01:00
/**
* 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'
*/
2019-04-04 07:15:40 +02:00
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 en true: enable recoloring, false: disable
*/
void lv_label_set_recolor(lv_obj_t * label, bool en);
2017-11-13 16:11:05 +01:00
/**
2019-06-20 06:20:23 +02:00
* Set the label's animation speed in LV_LABEL_LONG_SROLL/SCROLL_CIRC modes
2017-11-13 16:11:05 +01:00
* @param label pointer to a label object
* @param anim_speed speed of animation in px/sec unit
*/
2019-04-04 07:15:40 +02:00
void lv_label_set_anim_speed(lv_obj_t * label, uint16_t anim_speed);
2017-10-30 17:11:56 +01:00
/**
* @brief Set the selection start index.
* @param label pointer to a label object.
2019-04-18 06:45:45 +02:00
* @param index index to set. `LV_LABEL_TXT_SEL_OFF` to select nothing.
*/
2019-06-06 06:05:40 +02:00
void lv_label_set_text_sel_start(lv_obj_t * label, uint16_t index);
/**
* @brief Set the selection end index.
* @param label pointer to a label object.
2019-04-18 06:45:45 +02:00
* @param index index to set. `LV_LABEL_TXT_SEL_OFF` to select nothing.
*/
2019-06-06 06:05:40 +02:00
void lv_label_set_text_sel_end(lv_obj_t * label, uint16_t index);
2017-11-13 16:11:05 +01:00
/*=====================
* Getter functions
*====================*/
/**
* Get the text of a label
* @param label pointer to a label object
* @return the text of the label
*/
char * lv_label_get_text(const lv_obj_t * label);
/**
2017-11-13 16:11:05 +01:00
* Get the long mode of a label
* @param label pointer to a label object
2017-11-13 16:11:05 +01:00
* @return the long mode
*/
lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * label);
/**
2017-11-13 16:11:05 +01:00
* Get the align attribute
* @param label pointer to a label object
2017-11-13 16:11:05 +01:00
* @return LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER
*/
lv_label_align_t lv_label_get_align(const lv_obj_t * label);
/**
* Get the recoloring attribute
* @param label pointer to a label object
* @return true: recoloring is enabled, false: disable
*/
bool lv_label_get_recolor(const lv_obj_t * label);
2017-06-13 14:17:33 +02:00
/**
2017-11-13 16:11:05 +01:00
* Get the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes
2017-06-13 14:17:33 +02:00
* @param label pointer to a label object
2017-11-13 16:11:05 +01:00
* @return speed of animation in px/sec unit
2017-06-13 14:17:33 +02:00
*/
2019-04-04 07:15:40 +02:00
uint16_t lv_label_get_anim_speed(const lv_obj_t * label);
2017-06-13 14:17:33 +02:00
/**
* Get the relative x and y coordinates of a letter
* @param label pointer to a label object
2019-04-04 07:15:40 +02:00
* @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(const lv_obj_t * label, uint16_t index, lv_point_t * pos);
/**
* Get the index of letter on a relative point of a label
* @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)
2017-11-13 16:11:05 +01:00
* Expressed in character index and not byte index (different in UTF-8)
*/
uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos);
2016-06-08 07:25:08 +02:00
/**
* Check if a character is drawn under a point.
* @param label Label object
* @param pos Point to check for characte under
* @return whether a character is drawn under the point
*/
bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos);
/**
* @brief Get the selection start index.
* @param label pointer to a label object.
2019-04-18 06:45:45 +02:00
* @return selection start index. `LV_LABEL_TXT_SEL_OFF` if nothing is selected.
*/
2019-06-06 06:05:40 +02:00
uint16_t lv_label_get_text_sel_start(const lv_obj_t * label);
/**
* @brief Get the selection end index.
* @param label pointer to a label object.
2019-04-18 06:45:45 +02:00
* @return selection end index. `LV_LABEL_TXT_SEL_OFF` if nothing is selected.
*/
2019-06-06 06:05:40 +02:00
uint16_t lv_label_get_text_sel_end(const lv_obj_t * label);
2019-12-19 22:44:18 +01:00
lv_style_list_t * lv_label_get_style(lv_obj_t * label, uint8_t type);
2019-12-19 22:44:18 +01:00
2017-11-13 16:11:05 +01:00
/*=====================
* Other functions
*====================*/
/**
* Insert a text to the label. The label text can not be static.
* @param label pointer to a label object
2019-04-04 07:15:40 +02:00
* @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.
2017-11-13 16:11:05 +01:00
* @param txt pointer to the text to insert
*/
2019-04-04 07:15:40 +02:00
void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt);
2017-11-13 16:11:05 +01:00
/**
* Delete characters from a label. The label text can not be static.
* @param label pointer to a label object
2019-04-04 07:15:40 +02:00
* @param pos character index to insert. Expressed in character index and not byte index (Different
* in UTF-8) 0: before first char.
2017-11-13 16:11:05 +01:00
* @param cnt number of characters to cut
*/
2019-04-04 07:15:40 +02:00
void lv_label_cut_text(lv_obj_t * label, uint32_t pos, uint32_t cnt);
2017-11-13 16:11:05 +01:00
2016-06-08 07:25:08 +02:00
/**********************
* MACROS
**********************/
2019-04-04 07:15:40 +02:00
#endif /*LV_USE_LABEL*/
2016-06-08 07:25:08 +02:00
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
} /* extern "C" */
2016-06-08 07:25:08 +02:00
#endif
2017-07-09 15:32:49 +02:00
2019-04-04 07:15:40 +02:00
#endif /*LV_LABEL_H*/