Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_misc/lv_txt.h
1476 views
1
/**
2
* @file lv_text.h
3
*
4
*/
5
6
#ifndef LV_TXT_H
7
#define LV_TXT_H
8
9
#ifdef __cplusplus
10
extern "C" {
11
#endif
12
13
/*********************
14
* INCLUDES
15
*********************/
16
#ifdef LV_CONF_INCLUDE_SIMPLE
17
#include "lv_conf.h"
18
#else
19
#include "../../lv_conf.h"
20
#endif
21
22
#include "lv_area.h"
23
#include "lv_font.h"
24
#include "lv_area.h"
25
26
/*********************
27
* DEFINES
28
*********************/
29
#define LV_TXT_COLOR_CMD "#"
30
31
/**********************
32
* TYPEDEFS
33
**********************/
34
enum
35
{
36
LV_TXT_FLAG_NONE = 0x00,
37
LV_TXT_FLAG_RECOLOR = 0x01, /*Enable parsing of recolor command*/
38
LV_TXT_FLAG_EXPAND = 0x02, /*Ignore width to avoid automatic word wrapping*/
39
LV_TXT_FLAG_CENTER = 0x04, /*Align the text to the middle*/
40
LV_TXT_FLAG_RIGHT = 0x08, /*Align the text to the right*/
41
};
42
typedef uint8_t lv_txt_flag_t;
43
44
enum
45
{
46
LV_TXT_CMD_STATE_WAIT, /*Waiting for command*/
47
LV_TXT_CMD_STATE_PAR, /*Processing the parameter*/
48
LV_TXT_CMD_STATE_IN, /*Processing the command*/
49
};
50
typedef uint8_t lv_txt_cmd_state_t;
51
52
/**********************
53
* GLOBAL PROTOTYPES
54
**********************/
55
56
/**
57
* Get size of a text
58
* @param size_res pointer to a 'point_t' variable to store the result
59
* @param text pointer to a text
60
* @param font pinter to font of the text
61
* @param letter_space letter space of the text
62
* @param line_space line space of the text
63
* @param flags settings for the text from 'txt_flag_t' enum
64
* @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks
65
*/
66
void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font,
67
lv_coord_t letter_space, lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag);
68
69
/**
70
* Get the next line of text. Check line length and break chars too.
71
* @param txt a '\0' terminated string
72
* @param font pointer to a font
73
* @param letter_space letter space
74
* @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks
75
* @param flags settings for the text from 'txt_flag_type' enum
76
* @return the index of the first char of the new line (in byte index not letter index. With UTF-8 they are different)
77
*/
78
uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
79
lv_coord_t letter_space, lv_coord_t max_width, lv_txt_flag_t flag);
80
81
/**
82
* Give the length of a text with a given font
83
* @param txt a '\0' terminate string
84
* @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in UTF-8)
85
* @param font pointer to a font
86
* @param letter_space letter space
87
* @param flags settings for the text from 'txt_flag_t' enum
88
* @return length of a char_num long text
89
*/
90
lv_coord_t lv_txt_get_width(const char * txt, uint16_t length,
91
const lv_font_t * font, lv_coord_t letter_space, lv_txt_flag_t flag);
92
93
94
/**
95
* Check next character in a string and decide if te character is part of the command or not
96
* @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing
97
* @param c the current character
98
* @return true: the character is part of a command and should not be written,
99
* false: the character should be written
100
*/
101
bool lv_txt_is_cmd(lv_txt_cmd_state_t * state, uint32_t c);
102
103
/**
104
* Insert a string into an other
105
* @param txt_buf the original text (must be big enough for the result text)
106
* @param pos position to insert (0: before the original text, 1: after the first char etc.)
107
* @param ins_txt text to insert
108
*/
109
void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt);
110
111
/**
112
* Delete a part of a string
113
* @param txt string to modify
114
* @param pos position where to start the deleting (0: before the first char, 1: after the first char etc.)
115
* @param len number of characters to delete
116
*/
117
void lv_txt_cut(char * txt, uint32_t pos, uint32_t len);
118
119
/***************************************************************
120
* GLOBAL FUNCTION POINTERS FOR CAHRACTER ENCODING INTERFACE
121
***************************************************************/
122
123
/**
124
* Give the size of an encoded character
125
* @param str pointer to a character in a string
126
* @return length of the encoded character (1,2,3 ...). O in invalid
127
*/
128
extern uint8_t (*lv_txt_encoded_size)(const char *);
129
130
131
/**
132
* Convert an Unicode letter to encoded
133
* @param letter_uni an Unicode letter
134
* @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü')
135
*/
136
extern uint32_t (*lv_txt_unicode_to_encoded)(uint32_t );
137
138
/**
139
* Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format.
140
* @param c a wide character
141
* @return `c` in the encoded format
142
*/
143
extern uint32_t (*lv_txt_encoded_conv_wc) (uint32_t c);
144
145
/**
146
* Decode the next encoded character from a string.
147
* @param txt pointer to '\0' terminated string
148
* @param i start index in 'txt' where to start.
149
* After the call it will point to the next encoded char in 'txt'.
150
* NULL to use txt[0] as index
151
* @return the decoded Unicode character or 0 on invalid data code
152
*/
153
extern uint32_t (*lv_txt_encoded_next)(const char *, uint32_t * );
154
155
/**
156
* Get the previous encoded character form a string.
157
* @param txt pointer to '\0' terminated string
158
* @param i_start index in 'txt' where to start. After the call it will point to the previous encoded char in 'txt'.
159
* @return the decoded Unicode character or 0 on invalid data
160
*/
161
extern uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *);
162
163
/**
164
* Convert a letter index (in an the encoded text) to byte index.
165
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
166
* @param txt a '\0' terminated UTF-8 string
167
* @param enc_id letter index
168
* @return byte index of the 'enc_id'th letter
169
*/
170
extern uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t);
171
172
/**
173
* Convert a byte index (in an encoded text) to character index.
174
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
175
* @param txt a '\0' terminated UTF-8 string
176
* @param byte_id byte index
177
* @return character index of the letter at 'byte_id'th position
178
*/
179
extern uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t);
180
181
/**
182
* Get the number of characters (and NOT bytes) in a string.
183
* E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes)
184
* @param txt a '\0' terminated char string
185
* @return number of characters
186
*/
187
extern uint32_t (*lv_txt_get_encoded_length)(const char *);
188
189
/**********************
190
* MACROS
191
**********************/
192
193
#ifdef __cplusplus
194
} /* extern "C" */
195
#endif
196
197
#endif /*USE_TXT*/
198
199