MPLABĀ® Harmony Graphics Suite
legato_string.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries.
3 *
4 * Subject to your compliance with these terms, you may use Microchip software
5 * and any derivatives exclusively with Microchip products. It is your
6 * responsibility to comply with third party license terms applicable to your
7 * use of third party software (including open source software) that may
8 * accompany Microchip software.
9 *
10 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
11 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
12 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
13 * PARTICULAR PURPOSE.
14 *
15 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
16 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
17 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
18 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
19 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
20 * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
21 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
22 *******************************************************************************/
23 
24 /*******************************************************************************
25  Module for Microchip Graphics Library - Legato User Interface Library
26 
27  Company:
28  Microchip Technology Inc.
29 
30  File Name:
31  legato_string.h
32 
33  Summary:
34  A string library implementation for the Legato user interface library.
35 
36  Description:
37  This is a string library implementation that is used internally by the
38  Legato user interface library.
39 
40  This implementation relies on the leChar definition for characters.
41  This chararcter definition is 16 bits in size and allows the library to
42  support international character code points and Unicode encoding standards.
43 *******************************************************************************/
44 
56 #ifndef LEGATO_STRING_H
57 #define LEGATO_STRING_H
58 
60 
63 
64 /* internal use only */
65 struct leString;
66 
67 typedef void (*leString_InvalidateCallback)(const struct leString* str, void* userData);
68 
69 #define LE_STRING_VTABLE(THIS_TYPE) \
70  void (*destructor)(THIS_TYPE* _this); \
71  leFont* (*getFont)(const THIS_TYPE* _this); \
72  leResult (*setFont)(THIS_TYPE* _this, const leFont* font); \
73  leResult (*setFromString)(THIS_TYPE* _this, const struct leString* src); \
74  leResult (*setFromChar)(THIS_TYPE* _this, const leChar* buf, uint32_t size); \
75  leResult (*setFromCStr)(THIS_TYPE* _this, const char* cstr); \
76  leChar (*charAt)(const THIS_TYPE* _this, uint32_t idx); \
77  uint32_t (*length)(const THIS_TYPE* _this); \
78  leBool (*isEmpty)(const THIS_TYPE* _this); \
79  int32_t (*compare)(const THIS_TYPE* _this, const struct leString* tgt); \
80  leResult (*append)(THIS_TYPE* _this, const struct leString* val); \
81  leResult (*insert)(THIS_TYPE* _this, const struct leString* val, uint32_t idx); \
82  leResult (*remove)(THIS_TYPE* _this, uint32_t idx, uint32_t count); \
83  void (*clear)(THIS_TYPE* _this); \
84  uint32_t (*toChar)(const THIS_TYPE* _this, leChar* buf, uint32_t size); \
85  leResult (*getRect)(const THIS_TYPE* _this, leRect* rect); \
86  uint32_t (*getLineCount)(const THIS_TYPE* _this); \
87  leResult (*getLineRect)(const THIS_TYPE* _this, uint32_t line, leRect* rect); \
88  leResult (*getLineIndices)(const THIS_TYPE* _this, uint32_t line, uint32_t* start, uint32_t* end); \
89  leResult (*getCharRect)(const THIS_TYPE* _this, uint32_t idx, leRect* rect); \
90  leResult (*getCharIndexAtPoint)(const THIS_TYPE* _this, const lePoint* pt, uint32_t* idx); \
91  leResult (*_draw)(const THIS_TYPE* _this, int32_t x, int32_t y, leHAlignment align, leColor clr, uint32_t a); \
92  void (*preinvalidate)(THIS_TYPE* _this); \
93  void (*invalidate)(THIS_TYPE* _this); \
94  leResult (*setPreInvalidateCallback)(THIS_TYPE* _this, leString_InvalidateCallback, void* userData); \
95  leResult (*setInvalidateCallback)(THIS_TYPE* _this, leString_InvalidateCallback, void* userData); \
96 
97 typedef struct leStringVTable
98 {
99  LE_STRING_VTABLE(struct leString)
101 
102 // *****************************************************************************
107 typedef struct leString
108 {
111  leString_InvalidateCallback preInvCallback;
114  leString_InvalidateCallback invCallback;
117 
118 // *****************************************************************************
131 LIB_EXPORT void leString_Delete(leString* str);
132 
133 #ifdef _DOXYGEN_
134 #define THIS_TYPE struct leWidget
135 
136 // *****************************************************************************
137 
148 virtual void destructor(leString* _this);
149 
150 // *****************************************************************************
161 virtual leFont* getFont(const leString* _this);
162 
163 
164 // *****************************************************************************
175 virtual leResult setFont(leString* _this,
176  const leFont* font);
177 
178 
179 // *****************************************************************************
192  const struct leString* src);
193 
194 // *****************************************************************************
210  const leChar* buf,
211  uint32_t size);
212 
213 
214 // *****************************************************************************
227  const char* cstr);
228 
229 
230 // *****************************************************************************
244 virtual leChar charAt(const leString* _this,
245  uint32_t idx);
246 
247 // *****************************************************************************
261 virtual uint32_t length(const leString* _this);
262 
263 // *****************************************************************************
274 virtual leBool isEmpty(const leString* _this);
275 
276 
277 // *****************************************************************************
291 virtual int32_t compare(const leString* _this,
292  const struct leString* tgt);
293 
294 
295 // *****************************************************************************
308 virtual leResult append(leString* _this,
309  const struct leString* val);
310 
311 // *****************************************************************************
328 virtual leResult insert(leString* _this,
329  const struct leString* val,
330  uint32_t idx);
331 
332 // *****************************************************************************
349  virtual leResult remove(leString* _this,
350  uint32_t idx,
351  uint32_t count);
352 
353 // *****************************************************************************
365 virtual void clear(leString* _this);
366 
367 // *****************************************************************************
383 virtual uint32_t toChar(const leString* _this,
384  leChar* buf,
385  uint32_t size);
386 virtual
387 // *****************************************************************************
400 virtual leResult getRect(const leString* _this,
401  leRect* rect);
402 
403 
404 // *****************************************************************************
415 uint32_t getLineCount(const leString* _this);
416 
417 
418 // *****************************************************************************
433 virtual leResult getLineRect(const leString* _this,
434  uint32_t line,
435  leRect* rect);
436 
437 
438 // *****************************************************************************
455 virtual leResult getLineIndices(const leString* _this,
456  uint32_t line,
457  uint32_t* start,
458  uint32_t* end);
459 
460 
461 // *****************************************************************************
475 virtual leResult getCharRect(const leString* _this,
476  uint32_t idx,
477  leRect* rect);
478 
479 // *****************************************************************************
493 virtual leResult getCharIndexAtPoint(const leString* _this,
494  const lePoint* pt,
495  uint32_t* idx);
496 
497 
498 // *****************************************************************************
515 virtual leResult _draw(const leString* _this,
516  int32_t x,
517  int32_t y,
518  leHAlignment align,
519  leColor clr,
520  uint32_t a);
521 
522 
523 // *****************************************************************************
534 virtual void preinvalidate(leString* _this);
535 
536 // *****************************************************************************
550 virtual void invalidate(leString* _this);
551 
552 // *****************************************************************************
568  leString_InvalidateCallback,
569  void* userData);
570 
571 // *****************************************************************************
587  leString_InvalidateCallback cb,
588  void* userData);
589 
590 #undef THIS_TYPE
591 #endif
592 
593 #endif /* LE_STRING_H */
getCharIndexAtPoint
virtual leResult getCharIndexAtPoint(const leString *_this, const lePoint *pt, uint32_t *idx)
Get character index at point.
setFromString
virtual leResult setFromString(leString *_this, const struct leString *src)
Set string value from another string.
remove
virtual leResult remove(leString *_this, uint32_t idx, uint32_t count)
Remove substring.
legato_error.h
Error functions, macros and definitions.
getRect
virtual virtual leResult getRect(const leString *_this, leRect *rect)
Get rectangle of the rendered string in pixels.
leResult
leResult
This enum represents function call results.
Definition: legato_common.h:134
setInvalidateCallback
virtual leResult setInvalidateCallback(leString *_this, leString_InvalidateCallback cb, void *userData)
Set string invalidate event.
leRect
This struct represents a rectangle.
Definition: legato_common.h:405
getLineIndices
virtual leResult getLineIndices(const leString *_this, uint32_t line, uint32_t *start, uint32_t *end)
Get indices of a string line.
leStringRenderer_DrawString
leResult leStringRenderer_DrawString(leStringRenderRequest *req)
Draw an leString.
Definition: legato_string_renderer.c:114
legato_memory.h
Memory functions and definitions.
leHAlignment
leHAlignment
This enum represents the horizontal alignment mode of objects.
Definition: legato_common.h:206
legato_renderer.h
leString::invCallback
leString_InvalidateCallback invCallback
Definition: legato_string.h:114
legato_string_renderer.h
String Renderer.
getLineCount
uint32_t getLineCount(const leString *_this)
Get number of lines in the string.
leString::invCBUserData
void * invCBUserData
Definition: legato_string.h:115
preinvalidate
virtual void preinvalidate(leString *_this)
Raise pre-invalidate event.
invalidate
virtual void invalidate(leString *_this)
Invalidate.
_draw
virtual leResult _draw(const leString *_this, int32_t x, int32_t y, leHAlignment align, leColor clr, uint32_t a)
Draw.
leFont
This struct represents a font object.
Definition: legato_font.h:136
getCharRect
virtual leResult getCharRect(const leString *_this, uint32_t idx, leRect *rect)
Get rendered rectangle of a string codepoint.
leRasterFont
This struct represents a rasterized font object.
Definition: legato_font.h:167
leStringVTable
Definition: legato_string.h:98
leString
This struct represents a string.
Definition: legato_string.h:108
setFromChar
virtual leResult setFromChar(leString *_this, const leChar *buf, uint32_t size)
Set string value from a leChar buffer.
charAt
virtual leChar charAt(const leString *_this, uint32_t idx)
Get codepoint at the given index.
setPreInvalidateCallback
virtual leResult setPreInvalidateCallback(leString *_this, leString_InvalidateCallback, void *userData)
Set string invalidate event.
leBool
leBool
This enum represents booleans.
Definition: legato_common.h:157
leStringRenderRequest
This struct represents a string render request.
Definition: legato_string_renderer.h:59
leString
struct leString leString
This struct represents a string.
leFontGlyph
This struct represents a font glyph.
Definition: legato_font.h:90
length
virtual uint32_t length(const leString *_this)
Get length of the string.
setFont
virtual leResult setFont(leString *_this, const leFont *font)
Set font.
leString::preInvCallback
leString_InvalidateCallback preInvCallback
Definition: legato_string.h:111
insert
virtual leResult insert(leString *_this, const struct leString *val, uint32_t idx)
Insert string at a given index.
leRectContainsPoint
LIB_EXPORT leBool leRectContainsPoint(const leRect *rect, const lePoint *point)
Determines if a point is inside a rectangle.
Definition: legato_rect.c:31
legato_string.h
Fixed string functions and definitions.
leFont_GetGlyphInfo
leResult leFont_GetGlyphInfo(const leFont *fnt, uint32_t codepoint, leFontGlyph *glyph)
Get glyph info.
Definition: legato_font.c:171
leString_Delete
LIB_EXPORT void leString_Delete(leString *str)
Delete string.
compare
virtual int32_t compare(const leString *_this, const struct leString *tgt)
Compare string to another string.
getLineRect
virtual leResult getLineRect(const leString *_this, uint32_t line, leRect *rect)
Get rectangle of a string line.
leChar
uint16_t leChar
This typedef represents Legato character.
Definition: legato_common.h:424
toChar
virtual uint32_t toChar(const leString *_this, leChar *buf, uint32_t size)
Convert string to a C-style string.
getFont
virtual leFont * getFont(const leString *_this)
Get font.
isEmpty
virtual leBool isEmpty(const leString *_this)
Determine if string is empty.
append
virtual leResult append(leString *_this, const struct leString *val)
Append string.
LE_TRUE
@ LE_TRUE
Definition: legato_common.h:159
legato_font.h
Font functions and definitions.
clear
virtual void clear(leString *_this)
Clear string.
leString::preCBUserData
void * preCBUserData
Definition: legato_string.h:112
legato_common.h
Common macros and definitions used by Legato.
leString::fn
const leStringVTable * fn
Definition: legato_string.h:109
legato_state.h
destructor
virtual void destructor(leString *_this)
Destruct string.
setFromCStr
virtual leResult setFromCStr(leString *_this, const char *cstr)
Set string value from a C string buffer.
lePoint
This structure represents a integer Cartesian point.
Definition: legato_common.h:357