MPLABĀ® Harmony Graphics Suite
legato_widget_button.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_widget_button.h
32 
33  Summary:
34  Defines a button widget
35 *******************************************************************************/
36 
43 #ifndef LEGATO_BUTTON_H
44 #define LEGATO_BUTTON_H
45 
47 
48 #if LE_BUTTON_WIDGET_ENABLED == 1
49 
51 
54 
55 // *****************************************************************************
56 // *****************************************************************************
57 // Section: Data Types and Constants
58 // *****************************************************************************
59 // *****************************************************************************
60 
61 // *****************************************************************************
62 /* Enumeration:
63  leButtonState
64 
65  Summary:
66  Controls the button pressed state
67 */
72 typedef enum leButtonState
73 {
74  LE_BUTTON_STATE_UP,
75  LE_BUTTON_STATE_DOWN,
76  LE_BUTTON_STATE_TOGGLED
77 } leButtonState;
78 
83 typedef struct leButtonWidget leButtonWidget;
84 
85 // *****************************************************************************
86 /* Function Pointer:
87  leButtonWidget_PressedEvent
88 
89  Summary:
90  Button pressed event function callback type
91 */
96 typedef void (*leButtonWidget_PressedEvent)(leButtonWidget*);
97 
98 // *****************************************************************************
99 /* Function Pointer:
100  leButtonWidget_ReleasedEvent
101 
102  Summary:
103  Button released event function callback type
104 */
109 typedef void (*leButtonWidget_ReleasedEvent)(leButtonWidget*);
110 
111 
112 /* internal use only */
118 typedef struct leButtonWidget leButtonWidget;
119 
120 #define LE_BUTTONWIDGET_VTABLE(THIS_TYPE) \
121  LE_WIDGET_VTABLE(THIS_TYPE) \
122  \
123  leBool (*getToggleable)(const THIS_TYPE* _this); \
124  leResult (*setToggleable)(THIS_TYPE* _this, leBool toggleable); \
125  leBool (*getPressed)(const THIS_TYPE* _this); \
126  leResult (*setPressed)(THIS_TYPE* _this, leBool pressed); \
127  leString* (*getString)(const THIS_TYPE* _this); \
128  leResult (*setString)(THIS_TYPE* _this, const leString* str); \
129  leImage* (*getPressedImage)(const THIS_TYPE* _this); \
130  leResult (*setPressedImage)(THIS_TYPE* _this, leImage* img); \
131  leImage* (*getReleasedImage)(const THIS_TYPE* _this); \
132  leResult (*setReleasedImage)(THIS_TYPE* _this, leImage* img); \
133  leRelativePosition (*getImagePosition)(const THIS_TYPE* _this); \
134  leResult (*setImagePosition)(THIS_TYPE* _this, leRelativePosition pos); \
135  uint32_t (*getImageMargin)(const THIS_TYPE* _this); \
136  leResult (*setImageMargin)(THIS_TYPE* _this, uint32_t mg); \
137  int32_t (*getPressedOffset)(const THIS_TYPE* _this); \
138  leResult (*setPressedOffset)(THIS_TYPE* _this, int32_t offs); \
139  leButtonWidget_PressedEvent (*getPressedEventCallback)(const THIS_TYPE* _this); \
140  leResult (*setPressedEventCallback)(THIS_TYPE* _this, leButtonWidget_PressedEvent cb); \
141  leButtonWidget_ReleasedEvent (*getReleasedEventCallback)(const THIS_TYPE* _this); \
142  leResult (*setReleasedEventCallback)(THIS_TYPE* _this, leButtonWidget_ReleasedEvent cb); \
143 
144 
145 typedef struct leButtonWidgetVTable
146 {
147  LE_BUTTONWIDGET_VTABLE(leButtonWidget)
148 } leButtonWidgetVTable;
149 
156 // *****************************************************************************
157 /* Structure:
158  leButtonWidget
159 
160  Summary:
161  Implementation of a button widget. A button is an interactive element
162  that simulates a typical button with a pressed an released state.
163 
164  Description:
165 
166 
167  Remarks:
168  None.
169 */
175 typedef struct leButtonWidget
176 {
177  leWidget widget; // base widget header
178 
179  const leButtonWidgetVTable* fn;
180 
181  leButtonState state; // button state
182  uint8_t toggleable; // indicates if the button is toggleable
183 
184  const leString* string; // the string that holds the button text
185 
186  const leImage* pressedImage; // button pressed icon image
187  const leImage* releasedImage; // button released icon image
188 
189  leRelativePosition imagePosition; // icon position in relation to text
190  uint32_t imageMargin; // distance between text and icon
191  int32_t pressedOffset; // pressed text offset distance
192 
193  leButtonWidget_PressedEvent pressedEvent; // pressed event callback
194  leButtonWidget_ReleasedEvent releasedEvent; // released event callback
195 } leButtonWidget;
196 
197 // *****************************************************************************
198 // *****************************************************************************
199 // Section: Routines
200 // *****************************************************************************
201 // *****************************************************************************
202 
214 LIB_EXPORT leButtonWidget* leButtonWidget_New();
215 
226 LIB_EXPORT void leButtonWidget_Constructor(leButtonWidget* wgt);
227 
228 #ifdef _DOXYGEN_
229 #define THIS_TYPE struct leWidget
230 
241 virtual leBool getToggleable(const leButtonWidget* _this);
242 
256 virtual leResult setToggleable(leButtonWidget* _this,
257  leBool toggleable);
258 
269 virtual leBool getPressed(const leButtonWidget* _this);
270 
284 virtual leResult setPressed(leButtonWidget* _this,
285  leBool pressed);
286 
287 
298 virtual leString* getString(const leButtonWidget* _this);
299 
300 
314 virtual leResult setString(leButtonWidget* _this,
315  const leString* str);
316 
327 virtual leImage* getPressedImage(const leButtonWidget* _this);
328 
329 
343 virtual leResult setPressedImage(leButtonWidget* _this,
344  leImage* img);
345 
346 
357 virtual leImage* getReleasedImage(const leButtonWidget* _this);
358 
372 virtual leResult setReleasedImage(leButtonWidget* _this,
373  leImage* img);
374 
375 
387 virtual leRelativePosition getImagePosition(const leButtonWidget* _this);
388 
402 virtual leResult setImagePosition(leButtonWidget* _this,
403  leRelativePosition pos);
404 
415 virtual uint32_t getImageMargin(const leButtonWidget* _this);
416 
430 virtual leResult setImageMargin(leButtonWidget* _this,
431  uint32_t mg);
432 
433 
445 virtual int32_t getPressedOffset(const leButtonWidget* _this);
446 
447 
461 virtual leResult setPressedOffset(leButtonWidget* _this,
462  int32_t offs);
463 
474 virtual leButtonWidget_PressedEvent getPressedEventCallback(const leButtonWidget* _this);
475 
489 virtual leResult setPressedEventCallback(leButtonWidget* _this,
490  leButtonWidget_PressedEvent cb);
491 
502 virtual leButtonWidget_ReleasedEvent getReleasedEventCallback(const leButtonWidget* _this);
503 
504 
518 virtual leResult setReleasedEventCallback(leButtonWidget* _this,
519  leButtonWidget_ReleasedEvent cb);
520 
521 #undef THIS_TYPE
522 #endif
523 
524 
525 #endif /* LE_BUTTON_WIDGET_ENABLED */
526 #endif /* LEGATO_BUTTON_H */
527 
_leWidget_SetAlphaAmount
leResult _leWidget_SetAlphaAmount(leWidget *_this, uint32_t alpha)
Set alpha amount.
Definition: legato_widget.c:570
legato_widget_button.h
Button widget functions and definitions.
legato_error.h
Error functions, macros and definitions.
_leWidget_GetType
leWidgetType _leWidget_GetType(const leWidget *_this)
Get widget type.
Definition: legato_widget.c:176
_leWidget_GetScheme
leScheme * _leWidget_GetScheme(const leWidget *_this)
Get widget scheme.
Definition: legato_widget.c:938
leResult
leResult
This enum represents function call results.
Definition: legato_common.h:134
_leWidget_RectToScreenSpace
leRect _leWidget_RectToScreenSpace(const leWidget *_this)
Get widget rectangle.
Definition: legato_widget.c:701
leRect
This struct represents a rectangle.
Definition: legato_common.h:405
_leWidget_IsOpaque
leBool _leWidget_IsOpaque(const leWidget *_this)
Determine is widget is opaque.
Definition: legato_widget.c:594
_leWidget_SetBorderType
leResult _leWidget_SetBorderType(leWidget *_this, leBorderType type)
Set widget scheme.
Definition: legato_widget.c:967
_leWidget_RemoveAllChildren
void _leWidget_RemoveAllChildren(leWidget *_this)
Remove all children from widget.
Definition: legato_widget.c:823
_leWidget_SetParent
leResult _leWidget_SetParent(leWidget *_this, leWidget *parent)
Set parent widget.
Definition: legato_widget.c:862
leWidgetEvent_TouchUp
Used to define widget touch up event.
Definition: legato_widget.h:403
legato_image.h
Image functions and defintions.
_leWidget_SetCornerRadius
leResult _leWidget_SetCornerRadius(leWidget *_this, uint32_t radius)
Set widget scheme.
Definition: legato_widget.c:1091
_leWidget_InstallEventFilter
leResult _leWidget_InstallEventFilter(leWidget *_this, leWidgetEventFilter fltr)
Install event filter.
Definition: legato_widget.c:1215
_leWidget_SetX
leResult _leWidget_SetX(leWidget *_this, int32_t x)
Set widget x position.
Definition: legato_widget.c:190
_leWidget_SetSize
leResult _leWidget_SetSize(leWidget *_this, uint32_t width, uint32_t height)
Set widget height.
Definition: legato_widget.c:381
_leWidget_HasFocus
leBool _leWidget_HasFocus(const leWidget *_this)
Determines the focus status.
Definition: legato_widget.c:1110
legato_memory.h
Memory functions and definitions.
_leWidget_Resize
leResult _leWidget_Resize(leWidget *_this, int32_t width, int32_t height)
Resize widget.
Definition: legato_widget.c:426
_leWidget_SetAlphaEnabled
leResult _leWidget_SetAlphaEnabled(leWidget *_this, leBool enable)
Set cumulative alpha enable status.
Definition: legato_widget.c:501
leWidgetEvent_TouchDown
Used to define widget touch down event.
Definition: legato_widget.h:377
_leWidget_ContainsDescendant
leBool _leWidget_ContainsDescendant(const leWidget *_this, const leWidget *wgt)
Determine widget exists.
Definition: legato_widget.c:910
_leWidget_SetBackgroundType
leResult _leWidget_SetBackgroundType(leWidget *_this, leBackgroundType type)
Set widget scheme.
Definition: legato_widget.c:989
_leWidget_GetWidth
uint32_t _leWidget_GetWidth(const leWidget *_this)
Get widget width.
Definition: legato_widget.c:317
leImage
Definition: legato_image.h:180
_leWidget_GetCumulativeAlphaEnabled
leBool _leWidget_GetCumulativeAlphaEnabled(const leWidget *_this)
Get cumulative alpha enable status.
Definition: legato_widget.c:484
_leWidget_RectToParentSpace
leRect _leWidget_RectToParentSpace(const leWidget *_this)
Get widget rectangle.
Definition: legato_widget.c:684
_leWidget_Translate
leResult _leWidget_Translate(leWidget *_this, int32_t x, int32_t y)
Translate widget x and y position.
Definition: legato_widget.c:282
legato_renderer.h
legato_string_renderer.h
String Renderer.
_leWidget_SetHeight
leResult _leWidget_SetHeight(leWidget *_this, uint32_t height)
Set widget height.
Definition: legato_widget.c:356
_leWidget_SetWidth
leResult _leWidget_SetWidth(leWidget *_this, uint32_t width)
Set the widget width.
Definition: legato_widget.c:324
_leWidget_SetVisible
leResult _leWidget_SetVisible(leWidget *_this, leBool visible)
Set widget visible status.
Definition: legato_widget.c:649
_leWidget_GetRootWidget
leWidget * _leWidget_GetRootWidget(const leWidget *_this)
Get root widget.
Definition: legato_widget.c:843
_leWidget_Update
void _leWidget_Update(leWidget *_this, uint32_t dt)
Update widget.
Definition: legato_widget.c:1491
LE_HALIGN_CENTER
@ LE_HALIGN_CENTER
Definition: legato_common.h:208
legato_widget.h
Legato widget definitions.
_leWidget_GetHAlignment
leHAlignment _leWidget_GetHAlignment(const leWidget *_this)
Get widget horizontal alignment.
Definition: legato_widget.c:1003
_leWidget_GetHeight
uint32_t _leWidget_GetHeight(const leWidget *_this)
Get widget height.
Definition: legato_widget.c:349
leString
This struct represents a string.
Definition: legato_string.h:108
_leWidget_LocalRect
leRect _leWidget_LocalRect(const leWidget *_this)
Get widget rectangle.
Definition: legato_widget.c:670
leBool
leBool
This enum represents booleans.
Definition: legato_common.h:157
_leWidget_GetBackgroundType
leBackgroundType _leWidget_GetBackgroundType(const leWidget *_this)
Get widget background type.
Definition: legato_widget.c:982
_leWidget_SetScheme
leResult _leWidget_SetScheme(leWidget *_this, const leScheme *scheme)
Set widget scheme.
Definition: legato_widget.c:945
_leWidget_SetHAlignment
leResult _leWidget_SetHAlignment(leWidget *_this, leHAlignment align)
Set widget scheme.
Definition: legato_widget.c:1010
_leWidget_GetEnabled
leBool _leWidget_GetEnabled(const leWidget *_this)
Get widget enabled flag.
Definition: legato_widget.c:615
length
virtual uint32_t length(const leString *_this)
Get length of the string.
_leWidget_SetFocus
leResult _leWidget_SetFocus(leWidget *_this)
Set widget scheme.
Definition: legato_widget.c:1117
LE_FALSE
@ LE_FALSE
Definition: legato_common.h:158
_leWidget_GetAlphaEnabled
leBool _leWidget_GetAlphaEnabled(const leWidget *_this)
Get alpha enable status.
Definition: legato_widget.c:473
leRectContainsPoint
LIB_EXPORT leBool leRectContainsPoint(const leRect *rect, const lePoint *point)
Determines if a point is inside a rectangle.
Definition: legato_rect.c:31
_leWidget_GetChildAtIndex
leWidget * _leWidget_GetChildAtIndex(const leWidget *_this, uint32_t idx)
Get child at index.
Definition: legato_widget.c:888
leWidgetEvent
Used to define widget event.
Definition: legato_widget.h:352
_leWidget_GetCumulativeAlphaAmount
uint32_t _leWidget_GetCumulativeAlphaAmount(const leWidget *_this)
Get cumulative alpha amount.
Definition: legato_widget.c:538
_leWidget_SetY
leResult _leWidget_SetY(leWidget *_this, int32_t y)
Set widget y position.
Definition: legato_widget.c:222
_leWidget_GetBorderType
leBorderType _leWidget_GetBorderType(const leWidget *_this)
Get widget bordertype.
Definition: legato_widget.c:960
_leWidget_SetMargins
leResult _leWidget_SetMargins(leWidget *_this, uint32_t l, uint32_t t, uint32_t r, uint32_t b)
Set widget margins.
Definition: legato_widget.c:1058
legato_utils.h
General internal utilities for the library.
_leWidget_GetVAlignment
leVAlignment _leWidget_GetVAlignment(const leWidget *_this)
Get widget vertical alignment.
Definition: legato_widget.c:1027
legato_string.h
Fixed string functions and definitions.
leCStringRenderRequest
This struct represents a c-style string render request.
Definition: legato_string_renderer.h:128
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
legato_stringutils.h
String utility functions and definitions.
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.h
The header file joins all header files used in the graphics object library.
leUtils_ClipRectToParent
void leUtils_ClipRectToParent(const leWidget *widget, leRect *rect)
Clips a rectangle to the parent of a widge.
Definition: legato_utils.c:112
_leWidget_GetX
int32_t _leWidget_GetX(const leWidget *_this)
Get widget x position.
Definition: legato_widget.c:183
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
_leWidget_SetVAlignment
leResult _leWidget_SetVAlignment(leWidget *_this, leVAlignment align)
Set widget vertical alignment.
Definition: legato_widget.c:1034
_leWidget_GetVisible
leBool _leWidget_GetVisible(const leWidget *_this)
Get widget visible status.
Definition: legato_widget.c:642
leWidgetEvent_TouchMove
Used to define widget touch move event.
Definition: legato_widget.h:429
_leWidget_AddChild
leResult _leWidget_AddChild(leWidget *_this, leWidget *child)
Add child to widget.
Definition: legato_widget.c:734
_leWidget_GetIndexOfChild
uint32_t _leWidget_GetIndexOfChild(const leWidget *_this, const leWidget *child)
Get index of child.
Definition: legato_widget.c:899
leArray_Get
void * leArray_Get(const leArray *arr, uint32_t idx)
Get entry at index.
Definition: legato_array.c:224
_leWidget_GetChildCount
uint32_t _leWidget_GetChildCount(const leWidget *_this)
Get child count.
Definition: legato_widget.c:881
LE_RELATIVE_POSITION_LEFTOF
@ LE_RELATIVE_POSITION_LEFTOF
Definition: legato_common.h:314
_leWidget_GetMargins
leMargin _leWidget_GetMargins(const leWidget *_this)
Get widget margins.
Definition: legato_widget.c:1051
leStringRenderer_DrawCString
leResult leStringRenderer_DrawCString(leCStringRenderRequest *req)
Draw leChar string.
Definition: legato_string_renderer.c:297
leWidget_Constructor
LIB_EXPORT void leWidget_Constructor(leWidget *wgt)
Initialize widget.
Definition: legato_widget.c:67
leScheme_GetRenderColor
leColor leScheme_GetRenderColor(const leScheme *schm, leSchemeColor clr)
Gets a scheme render color for the current layer color mode.
Definition: legato_scheme.c:68
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
_leWidget_GetAlphaAmount
uint32_t _leWidget_GetAlphaAmount(const leWidget *_this)
Get alpha amount.
Definition: legato_widget.c:527
_leWidget_GetCornerRadius
uint32_t _leWidget_GetCornerRadius(const leWidget *_this)
Get widget corner radius.
Definition: legato_widget.c:1084
legato_common.h
Common macros and definitions used by Legato.
_leWidget_RemoveEventFilter
leResult _leWidget_RemoveEventFilter(leWidget *_this, leWidgetEventFilter fltr)
Remove event filter.
Definition: legato_widget.c:1238
leString::fn
const leStringVTable * fn
Definition: legato_string.h:109
_leWidget_RemoveChild
leResult _leWidget_RemoveChild(leWidget *_this, leWidget *child)
Remove child from widget.
Definition: legato_widget.c:785
leStringUtils_GetRectCStr
LIB_EXPORT leResult leStringUtils_GetRectCStr(const char *str, const leFont *font, leRect *rect)
Gets the bounding rectangle for a C-style string.
Definition: legato_stringutils.c:128
_leWidget_SetEnabled
leResult _leWidget_SetEnabled(leWidget *_this, leBool enable)
Set widget enabled flag.
Definition: legato_widget.c:620
_leWidget_SetPosition
leResult _leWidget_SetPosition(leWidget *_this, int32_t x, int32_t y)
Set widget x and y position.
Definition: legato_widget.c:247
_leWidget_Invalidate
void _leWidget_Invalidate(const leWidget *_this)
Invalidate widget.
Definition: legato_widget.c:1142
lePoint
This structure represents a integer Cartesian point.
Definition: legato_common.h:357
legato_widget_bar_graph.h
Bar graph widget functions and definitions.
_leWidget_GetY
int32_t _leWidget_GetY(const leWidget *_this)
Get widget y position.
Definition: legato_widget.c:215