MPLABĀ® Harmony Graphics Suite  GFX v3.13.0
Legato API Documentation
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;
116 } leString;
117 
118 // *****************************************************************************
133 void leString_Delete(leString* str);
134 
135 #ifdef _DOXYGEN_
136 #define THIS_TYPE struct leWidget
137 
138 // *****************************************************************************
139 
150 virtual void destructor(leString* _this);
151 
152 // *****************************************************************************
163 virtual leFont* getFont(const leString* _this);
164 
165 
166 // *****************************************************************************
177 virtual leResult setFont(leString* _this,
178  const leFont* font);
179 
180 
181 // *****************************************************************************
193 virtual leResult setFromString(leString* _this,
194  const struct leString* src);
195 
196 // *****************************************************************************
211 virtual leResult setFromChar(leString* _this,
212  const leChar* buf,
213  uint32_t size);
214 
215 
216 // *****************************************************************************
228 virtual leResult setFromCStr(leString* _this,
229  const char* cstr);
230 
231 
232 // *****************************************************************************
246 virtual leChar charAt(const leString* _this,
247  uint32_t idx);
248 
249 // *****************************************************************************
263 virtual uint32_t length(const leString* _this);
264 
265 // *****************************************************************************
276 virtual leBool isEmpty(const leString* _this);
277 
278 
279 // *****************************************************************************
293 virtual int32_t compare(const leString* _this,
294  const struct leString* tgt);
295 
296 
297 // *****************************************************************************
310 virtual leResult append(leString* _this,
311  const struct leString* val);
312 
313 // *****************************************************************************
330 virtual leResult insert(leString* _this,
331  const struct leString* val,
332  uint32_t idx);
333 
334 // *****************************************************************************
351  virtual leResult remove(leString* _this,
352  uint32_t idx,
353  uint32_t count);
354 
355 // *****************************************************************************
367 virtual void clear(leString* _this);
368 
369 // *****************************************************************************
385 virtual uint32_t toChar(const leString* _this,
386  leChar* buf,
387  uint32_t size);
388 virtual
389 // *****************************************************************************
402 virtual leResult getRect(const leString* _this,
403  leRect* rect);
404 
405 
406 // *****************************************************************************
417 uint32_t getLineCount(const leString* _this);
418 
419 
420 // *****************************************************************************
435 virtual leResult getLineRect(const leString* _this,
436  uint32_t line,
437  leRect* rect);
438 
439 
440 // *****************************************************************************
457 virtual leResult getLineIndices(const leString* _this,
458  uint32_t line,
459  uint32_t* start,
460  uint32_t* end);
461 
462 
463 // *****************************************************************************
477 virtual leResult getCharRect(const leString* _this,
478  uint32_t idx,
479  leRect* rect);
480 
481 // *****************************************************************************
495 virtual leResult getCharIndexAtPoint(const leString* _this,
496  const lePoint* pt,
497  uint32_t* idx);
498 
499 
500 // *****************************************************************************
517 virtual leResult _draw(const leString* _this,
518  int32_t x,
519  int32_t y,
520  leHAlignment align,
521  leColor clr,
522  uint32_t a);
523 
524 
525 // *****************************************************************************
536 virtual void preinvalidate(leString* _this);
537 
538 // *****************************************************************************
552 virtual void invalidate(leString* _this);
553 
554 // *****************************************************************************
570  leString_InvalidateCallback,
571  void* userData);
572 
573 // *****************************************************************************
589  leString_InvalidateCallback cb,
590  void* userData);
591 
592 #undef THIS_TYPE
593 #endif
594 
595 #endif /* LE_STRING_H */
virtual uint32_t length(const leString *_this)
Get length of the string.
virtual int32_t compare(const leString *_this, const struct leString *tgt)
Compare string to another string.
virtual leResult insert(leString *_this, const struct leString *val, uint32_t idx)
Insert string at a given index.
Common macros and definitions used by Legato.
Font functions and definitions.
virtual leBool isEmpty(const leString *_this)
Determine if string is empty.
This struct represents a string.
Definition: legato_string.h:107
const leStringVTable * fn
Definition: legato_string.h:109
virtual leResult getCharRect(const leString *_this, uint32_t idx, leRect *rect)
Get rendered rectangle of a string codepoint.
virtual leResult setFont(leString *_this, const leFont *font)
Set font.
virtual leResult append(leString *_this, const struct leString *val)
Append string.
This struct represents a font object.
Definition: legato_font.h:156
virtual uint32_t toChar(const leString *_this, leChar *buf, uint32_t size)
Convert string to a C-style string.
virtual void preinvalidate(leString *_this)
Raise pre-invalidate event.
leResult
This enum represents function call results.
Definition: legato_common.h:123
virtual leResult setFromString(leString *_this, const struct leString *src)
Set string value from another string.
virtual virtual leResult getRect(const leString *_this, leRect *rect)
Get rectangle of the rendered string in pixels.
This struct represents a rectangle.
Definition: legato_common.h:394
Definition: legato_string.h:97
leHAlignment
This enum represents the horizontal alignment mode of objects.
Definition: legato_common.h:195
virtual void invalidate(leString *_this)
Invalidate.
Error functions, macros and definitions.
virtual leResult getLineRect(const leString *_this, uint32_t line, leRect *rect)
Get rectangle of a string line.
virtual leResult setFromCStr(leString *_this, const char *cstr)
Set string value from a C string buffer.
void leString_Delete(leString *str)
Delete string.
Definition: legato_string.c:44
This structure represents a integer Cartesian point.
Definition: legato_common.h:346
virtual void clear(leString *_this)
Clear string.
struct leString leString
This struct represents a string.
virtual leResult setInvalidateCallback(leString *_this, leString_InvalidateCallback cb, void *userData)
Set string invalidate event.
virtual leResult getCharIndexAtPoint(const leString *_this, const lePoint *pt, uint32_t *idx)
Get character index at point.
leBool
This enum represents booleans.
Definition: legato_common.h:146
uint16_t leChar
This typedef represents Legato character.
Definition: legato_common.h:414
virtual leResult setPreInvalidateCallback(leString *_this, leString_InvalidateCallback, void *userData)
Set string invalidate event.
virtual leResult _draw(const leString *_this, int32_t x, int32_t y, leHAlignment align, leColor clr, uint32_t a)
Draw.
virtual leResult getLineIndices(const leString *_this, uint32_t line, uint32_t *start, uint32_t *end)
Get indices of a string line.
virtual leFont * getFont(const leString *_this)
Get font.
void * invCBUserData
Definition: legato_string.h:115
virtual leChar charAt(const leString *_this, uint32_t idx)
Get codepoint at the given index.
virtual void destructor(leString *_this)
Destruct string.
virtual leResult setFromChar(leString *_this, const leChar *buf, uint32_t size)
Set string value from a leChar buffer.
uint32_t getLineCount(const leString *_this)
Get number of lines in the string.
void * preCBUserData
Definition: legato_string.h:112