MPLABĀ® Harmony Graphics Suite  GFX v3.13.0
Legato API Documentation
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 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
55 
58 
59 // *****************************************************************************
60 // *****************************************************************************
61 // Section: Data Types and Constants
62 // *****************************************************************************
63 // *****************************************************************************
64 
65 // *****************************************************************************
66 /* Enumeration:
67  leButtonState
68 
69  Summary:
70  Controls the button pressed state
71 */
76 typedef enum leButtonState
77 {
78  LE_BUTTON_STATE_UP,
79  LE_BUTTON_STATE_DOWN,
80  LE_BUTTON_STATE_TOGGLED
81 } leButtonState;
82 
87 typedef struct leButtonWidget leButtonWidget;
88 
89 // *****************************************************************************
90 /* Function Pointer:
91  leButtonWidget_PressedEvent
92 
93  Summary:
94  Button pressed event function callback type
95 */
100 typedef void (*leButtonWidget_PressedEvent)(leButtonWidget*);
101 
102 // *****************************************************************************
103 /* Function Pointer:
104  leButtonWidget_ReleasedEvent
105 
106  Summary:
107  Button released event function callback type
108 */
113 typedef void (*leButtonWidget_ReleasedEvent)(leButtonWidget*);
114 
115 
116 /* internal use only */
122 typedef struct leButtonWidget leButtonWidget;
123 
124 #define LE_BUTTONWIDGET_VTABLE(THIS_TYPE) \
125  LE_WIDGET_VTABLE(THIS_TYPE) \
126  \
127  leBool (*getToggleable)(const THIS_TYPE* _this); \
128  leResult (*setToggleable)(THIS_TYPE* _this, leBool toggleable); \
129  leBool (*getPressed)(const THIS_TYPE* _this); \
130  leResult (*setPressed)(THIS_TYPE* _this, leBool pressed); \
131  leString* (*getString)(const THIS_TYPE* _this); \
132  leResult (*setString)(THIS_TYPE* _this, const leString* str); \
133  leImage* (*getPressedImage)(const THIS_TYPE* _this); \
134  leResult (*setPressedImage)(THIS_TYPE* _this, leImage* img); \
135  leImage* (*getReleasedImage)(const THIS_TYPE* _this); \
136  leResult (*setReleasedImage)(THIS_TYPE* _this, leImage* img); \
137  leRelativePosition (*getImagePosition)(const THIS_TYPE* _this); \
138  leResult (*setImagePosition)(THIS_TYPE* _this, leRelativePosition pos); \
139  uint32_t (*getImageMargin)(const THIS_TYPE* _this); \
140  leResult (*setImageMargin)(THIS_TYPE* _this, uint32_t mg); \
141  int32_t (*getPressedOffset)(const THIS_TYPE* _this); \
142  leResult (*setPressedOffset)(THIS_TYPE* _this, int32_t offs); \
143  leButtonWidget_PressedEvent (*getPressedEventCallback)(const THIS_TYPE* _this); \
144  leResult (*setPressedEventCallback)(THIS_TYPE* _this, leButtonWidget_PressedEvent cb); \
145  leButtonWidget_ReleasedEvent (*getReleasedEventCallback)(const THIS_TYPE* _this); \
146  leResult (*setReleasedEventCallback)(THIS_TYPE* _this, leButtonWidget_ReleasedEvent cb); \
147 
148 
149 typedef struct leButtonWidgetVTable
150 {
151  LE_BUTTONWIDGET_VTABLE(leButtonWidget)
152 } leButtonWidgetVTable;
153 
160 // *****************************************************************************
161 /* Structure:
162  leButtonWidget
163 
164  Summary:
165  Implementation of a button widget. A button is an interactive element
166  that simulates a typical button with a pressed an released state.
167 
168  Description:
169 
170 
171  Remarks:
172  None.
173 */
179 typedef struct leButtonWidget
180 {
181  leWidget widget; // base widget header
182 
183  const leButtonWidgetVTable* fn;
184 
185  leButtonState state; // button state
186  uint8_t toggleable; // indicates if the button is toggleable
187 
188  const leString* string; // the string that holds the button text
189 
190  const leImage* pressedImage; // button pressed icon image
191  const leImage* releasedImage; // button released icon image
192 
193  leRelativePosition imagePosition; // icon position in relation to text
194  uint32_t imageMargin; // distance between text and icon
195  int32_t pressedOffset; // pressed text offset distance
196 
197  leButtonWidget_PressedEvent pressedEvent; // pressed event callback
198  leButtonWidget_ReleasedEvent releasedEvent; // released event callback
199 } leButtonWidget;
200 
201 // *****************************************************************************
202 // *****************************************************************************
203 // Section: Routines
204 // *****************************************************************************
205 // *****************************************************************************
206 
218 leButtonWidget* leButtonWidget_New(void);
219 
230 void leButtonWidget_Constructor(leButtonWidget* wgt);
231 
232 #ifdef _DOXYGEN_
233 #define THIS_TYPE struct leWidget
234 
245 virtual leBool getToggleable(const leButtonWidget* _this);
246 
260 virtual leResult setToggleable(leButtonWidget* _this,
261  leBool toggleable);
262 
273 virtual leBool getPressed(const leButtonWidget* _this);
274 
288 virtual leResult setPressed(leButtonWidget* _this,
289  leBool pressed);
290 
291 
302 virtual leString* getString(const leButtonWidget* _this);
303 
304 
318 virtual leResult setString(leButtonWidget* _this,
319  const leString* str);
320 
331 virtual leImage* getPressedImage(const leButtonWidget* _this);
332 
333 
347 virtual leResult setPressedImage(leButtonWidget* _this,
348  leImage* img);
349 
350 
361 virtual leImage* getReleasedImage(const leButtonWidget* _this);
362 
376 virtual leResult setReleasedImage(leButtonWidget* _this,
377  leImage* img);
378 
379 
391 virtual leRelativePosition getImagePosition(const leButtonWidget* _this);
392 
406 virtual leResult setImagePosition(leButtonWidget* _this,
407  leRelativePosition pos);
408 
419 virtual uint32_t getImageMargin(const leButtonWidget* _this);
420 
434 virtual leResult setImageMargin(leButtonWidget* _this,
435  uint32_t mg);
436 
437 
449 virtual int32_t getPressedOffset(const leButtonWidget* _this);
450 
451 
465 virtual leResult setPressedOffset(leButtonWidget* _this,
466  int32_t offs);
467 
478 virtual leButtonWidget_PressedEvent getPressedEventCallback(const leButtonWidget* _this);
479 
493 virtual leResult setPressedEventCallback(leButtonWidget* _this,
494  leButtonWidget_PressedEvent cb);
495 
506 virtual leButtonWidget_ReleasedEvent getReleasedEventCallback(const leButtonWidget* _this);
507 
508 
522 virtual leResult setReleasedEventCallback(leButtonWidget* _this,
523  leButtonWidget_ReleasedEvent cb);
524 
525 #undef THIS_TYPE
526 #endif
527 
528 #ifdef __cplusplus
529 }
530 #endif
531 
532 
533 #endif /* LE_BUTTON_WIDGET_ENABLED */
534 #endif /* LEGATO_BUTTON_H */
535 
Common macros and definitions used by Legato.
Image functions and defintions.
Definition: legato_image.h:181
This struct represents a string.
Definition: legato_string.h:107
leResult
This enum represents function call results.
Definition: legato_common.h:123
Used to define a widget.
Definition: legato_widget.h:624
leRelativePosition
This enum represents the relative position modes for objects.
Definition: legato_common.h:302
Legato widget definitions.
leBool
This enum represents booleans.
Definition: legato_common.h:146
Definition: widget.py:1
Fixed string functions and definitions.