MPLABĀ® Harmony Graphics Suite
legato_utils.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_utils.h
32 
33  Summary:
34  General internal utilities for the library
35 
36 *******************************************************************************/
37 
44 #ifndef LEGATO_UTILS_H
45 #define LEGATO_UTILS_H
46 
48 
49 typedef struct leWidget leWidget;
50 typedef struct leList leList;
51 
52 #define LE_TEST_FLAG(val, flag) ((val & flag) > 0)
53 
54 // *****************************************************************************
55 // *****************************************************************************
56 // Section: Routines
57 // *****************************************************************************
58 // *****************************************************************************
59 
74  int32_t x,
75  int32_t y);
76 
77 
92 void leUtils_PointToScreenSpace(const leWidget* widget,
93  lePoint* pnt);
94 
108 void leUtils_PointScreenToLocalSpace(const leWidget* widget,
109  lePoint* pnt);
110 
124 void leUtils_ClipRectToParent(const leWidget* widget,
125  leRect* rect);
126 
127 /* Function:
128  void leUtils_RectToParentSpace(leWidget* widget, leRect* rect)
129 
130  Summary:
131  Converts a rectangle from widget local space to widget parent
132  space. Widget must be a child of a layer for this to function.
133 
134  Parameters:
135  leWidget* widget - the subject widget
136  leRect* rect - the rectangle to convert
137 
138  Returns:
139  void
140 */
155 void leUtils_RectToParentSpace(const leWidget* widget,
156  leRect* rect);
157 
171 void leUtils_RectFromParentSpace(const leWidget* widget,
172  leRect* rect);
173 
174 
188 void leUtils_RectToScreenSpace(const leWidget* widget,
189  leRect* rect);
190 
205  const leWidget* child);
206 
219 
220 /* Function:
221  void leUtils_ArrangeRectangle(leRect* sub,
222  leRect obj,
223  leRect bounds,
224  leHAlignment hAlignment,
225  leVAlignment vAlignment,
226  leRelativePosition position,
227  uint8_t leftMargin,
228  uint8_t topMargin,
229  uint8_t rightMargin,
230  uint8_t bottomMargin,
231  uint16_t rectMargin)
232 
233  Summary:
234  Calculates the position of a rectangle within the given bounds and
235  in accordance with the given parameters. A use case for this is
236  when an image and a text rectangle must be arranged in a button box.
237  This version of the algorithm will calculate the location of the
238  image rectangle.
239 
240  Parameters:
241  leRect* sub - the bounds of the subject rectangle (image)
242  leRect obj - the bounds of the object rectangle (text)
243  leRect bounds - the bounds of the bounding rectangle (widget)
244  leHAlignment hAlignment - the horizontal alignment of the rects
245  leVAlignment vAlignment - the vertical alignment of the rects
246  leRelativePosition position - the relative position of the rectangles
247  uint8_t leftMargin - the left margin of the bounding rectangle
248  uint8_t topMargin - the top margin of the bounding rectangle
249  uint8_t rightMargin - the right margin of the bounding rectangle
250  uint8_t bottomMargin - the bottom margin of the bounding rectangle
251  uint16_t rectMargin - the distance between the image and the text rects
252 
253  Returns:
254  void
255 
256  Remarks:
257  The x and y position of sub will be manipulated by this function. The
258  dimensions of the rectangle should be set before calling and should
259  remain unchanged after execution.
260 */
275  leRect obj,
276  leRect bounds,
277  leHAlignment hAlignment,
278  leVAlignment vAlignment,
279  leRelativePosition position,
280  uint8_t leftMargin,
281  uint8_t topMargin,
282  uint8_t rightMargin,
283  uint8_t bottomMargin,
284  uint16_t rectMargin);
285 
286 /* Function:
287  void leUtils_ArrangeRectangleRelative(leRect* sub,
288  leRect obj,
289  leRect bounds,
290  leHAlignment hAlignment,
291  leVAlignment vAlignment,
292  leRelativePosition position,
293  uint8_t leftMargin,
294  uint8_t topMargin,
295  uint8_t rightMargin,
296  uint8_t bottomMargin,
297  uint16_t rectMargin)
298 
299  Summary:
300  Calculates the position of a rectangle within the given bounds and
301  in accordance with the given parameters. A use case for this is
302  when an image and a text rectangle must be arranged in a button box.
303  This version of the algorithm will calculate the location of the
304  text rectangle.
305 
306  Parameters:
307  leRect* sub - the bounds of the subject rectangle (text)
308  leRect obj - the bounds of the object rectangle (image)
309  leRect bounds - the bounds of the bounding rectangle (widget)
310  leHAlignment hAlignment - the horizontal alignment of the rects
311  leVAlignment vAlignment - the vertical alignment of the rects
312  leRelativePosition position - the relative position of the rectangles
313  uint8_t leftMargin - the left margin of the bounding rectangle
314  uint8_t topMargin - the top margin of the bounding rectangle
315  uint8_t rightMargin - the right margin of the bounding rectangle
316  uint8_t bottomMargin - the bottom margin of the bounding rectangle
317  uint16_t rectMargin - the distance between the image and the text rects
318 
319  Returns:
320  void
321 
322  Remarks:
323  The x and y position of sub will be manipulated by this function. The
324  dimensions of the rectangle should be set before calling and should
325  remain unchanged after execution.
326 */
344  leRect obj,
345  leRect bounds,
346  leHAlignment hAlignment,
347  leVAlignment vAlignment,
348  leRelativePosition position,
349  uint8_t leftMargin,
350  uint8_t topMargin,
351  uint8_t rightMargin,
352  uint8_t bottomMargin,
353  uint16_t rectMargin);
354 
355 #endif // LEGATO_UTILS_H
leUtils_PointScreenToLocalSpace
void leUtils_PointScreenToLocalSpace(const leWidget *widget, lePoint *pnt)
Convert point from layer space into the local space of a widget.
Definition: legato_utils.c:90
leRect
This struct represents a rectangle.
Definition: legato_common.h:405
leArray::size
uint32_t size
Definition: legato_array.h:63
leList
This struct represents a list.
Definition: legato_list.h:91
leList_PushBack
int32_t leList_PushBack(leList *list, void *val)
Push value on back.
Definition: legato_list.c:141
leArray_Find
int32_t leArray_Find(const leArray *arr, void *val)
Find a first index of value.
Definition: legato_array.c:242
leHAlignment
leHAlignment
This enum represents the horizontal alignment mode of objects.
Definition: legato_common.h:206
LE_VALIGN_MIDDLE
@ LE_VALIGN_MIDDLE
Definition: legato_common.h:183
leUtils_RectToParentSpace
void leUtils_RectToParentSpace(const leWidget *widget, leRect *rect)
Convert rectangle from widget local space to widget parent space.
Definition: legato_utils.c:131
leList_Clear
void leList_Clear(leList *list)
Clear array.
Definition: legato_list.c:421
leRectIntersects
LIB_EXPORT leBool leRectIntersects(const leRect *l_rect, const leRect *r_rect)
Determines if two rectangles are intersecting.
Definition: legato_rect.c:51
LE_HALIGN_CENTER
@ LE_HALIGN_CENTER
Definition: legato_common.h:208
legato_widget.h
Legato widget definitions.
leList_Copy
int32_t leList_Copy(leList *l, leList *r)
Copy list.
Definition: legato_list.c:373
leArray::values
void ** values
Definition: legato_array.h:62
leList::size
size_t size
Definition: legato_list.h:94
leBool
leBool
This enum represents booleans.
Definition: legato_common.h:157
leRectContainsRect
LIB_EXPORT leBool leRectContainsRect(const leRect *l_rect, const leRect *r_rect)
Determines if a rectangle is completely inside another rectangle.
Definition: legato_rect.c:40
leUtils_PointToScreenSpace
void leUtils_PointToScreenSpace(const leWidget *widget, lePoint *pnt)
Converts a point from widget space into screen space.
Definition: legato_utils.c:75
legato_list.h
A linked list implementation.
LE_FALSE
@ LE_FALSE
Definition: legato_common.h:158
leRectContainsPoint
LIB_EXPORT leBool leRectContainsPoint(const leRect *rect, const lePoint *point)
Determines if a point is inside a rectangle.
Definition: legato_rect.c:31
leUtils_ChildIntersectsParent
leBool leUtils_ChildIntersectsParent(const leWidget *parent, const leWidget *child)
Determines if parent and child intersect.
Definition: legato_utils.c:166
LE_VALIGN_TOP
@ LE_VALIGN_TOP
Definition: legato_common.h:182
leUtils_PickFromWidget
leWidget * leUtils_PickFromWidget(const leWidget *wgt, int32_t x, int32_t y)
Finds the top-most visible widget in a layer at the given coordinates.
Definition: legato_utils.c:34
legato_utils.h
General internal utilities for the library.
LE_RELATIVE_POSITION_RIGHTOF
@ LE_RELATIVE_POSITION_RIGHTOF
Definition: legato_common.h:317
LE_HALIGN_LEFT
@ LE_HALIGN_LEFT
Definition: legato_common.h:207
LE_WIDGET_BACKGROUND_NONE
@ LE_WIDGET_BACKGROUND_NONE
Definition: legato_widget.h:225
leWidget
Used to define a widget.
Definition: legato_widget.h:623
leUtils_RectToScreenSpace
void leUtils_RectToScreenSpace(const leWidget *widget, leRect *rect)
Convert rectangle from widget local space to screen space.
Definition: legato_utils.c:151
legato_rect.h
Rectangle functions and definitions.
leUtils_ClipRectToParent
void leUtils_ClipRectToParent(const leWidget *widget, leRect *rect)
Clips a rectangle to the parent of a widge.
Definition: legato_utils.c:112
leRectClip
LIB_EXPORT void leRectClip(const leRect *l_rect, const leRect *r_rect, leRect *result)
Clips a rectangle to the space of another rectangle.
Definition: legato_rect.c:122
leUtils_GetNextHighestWidget
leWidget * leUtils_GetNextHighestWidget(const leWidget *wgt)
Get next highest Z order widget in the tree from 'wgt'.
Definition: legato_utils.c:182
leList_Create
int32_t leList_Create(leList *list)
Create a new list.
Definition: legato_list.c:31
leUtils_RectFromParentSpace
void leUtils_RectFromParentSpace(const leWidget *widget, leRect *rect)
Convert rectangle from widget parent space to widget local space.
Definition: legato_utils.c:141
leArray_Get
void * leArray_Get(const leArray *arr, uint32_t idx)
Get entry at index.
Definition: legato_array.c:224
LE_RELATIVE_POSITION_LEFTOF
@ LE_RELATIVE_POSITION_LEFTOF
Definition: legato_common.h:314
leRelativePosition
leRelativePosition
This enum represents the relative position modes for objects.
Definition: legato_common.h:313
LE_TRUE
@ LE_TRUE
Definition: legato_common.h:159
LE_RELATIVE_POSITION_BELOW
@ LE_RELATIVE_POSITION_BELOW
Definition: legato_common.h:316
LE_RELATIVE_POSITION_ABOVE
@ LE_RELATIVE_POSITION_ABOVE
Definition: legato_common.h:315
legato_common.h
Common macros and definitions used by Legato.
leUtils_ArrangeRectangle
void leUtils_ArrangeRectangle(leRect *sub, leRect obj, leRect bounds, leHAlignment hAlignment, leVAlignment vAlignment, leRelativePosition position, uint8_t leftMargin, uint8_t topMargin, uint8_t rightMargin, uint8_t bottomMargin, uint16_t rectMargin)
Calculates the position of a rectangle within the given bound.
Definition: legato_utils.c:213
leUtils_ArrangeRectangleRelative
void leUtils_ArrangeRectangleRelative(leRect *sub, leRect obj, leRect bounds, leHAlignment hAlignment, leVAlignment vAlignment, leRelativePosition position, uint8_t leftMargin, uint8_t topMargin, uint8_t rightMargin, uint8_t bottomMargin, uint16_t rectMargin)
Calculates the position of a rectangle within the given bounds.
Definition: legato_utils.c:286
leVAlignment
leVAlignment
This enum represents the vertical alignment mode of objects.
Definition: legato_common.h:181
lePoint
This structure represents a integer Cartesian point.
Definition: legato_common.h:357
leList_Get
void * leList_Get(const leList *list, uint32_t idx)
Get a value from the list.
Definition: legato_list.c:181