MPLABĀ® Harmony Graphics Suite  GFX v3.13.0
Legato API Documentation
legato_widget_keypad.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_keypad.h
32 
33  Summary:
34 
35 
36  Description:
37  This module implements keypad widget functions.
38 *******************************************************************************/
39 
46 #ifndef LEGATO_KEYPAD_H
47 #define LEGATO_KEYPAD_H
48 
50 
51 #if LE_KEYPAD_WIDGET_ENABLED == 1 && LE_BUTTON_WIDGET_ENABLED == 1
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
59 
60 typedef struct leKeyPadWidget leKeyPadWidget;
61 typedef struct leButtonWidget leButtonWidget;
62 
63 // *****************************************************************************
64 /* Function Pointer:
65  leKeyPadWidget_KeyClickEvent
66 
67  Summary:
68  Key click event function callback type
69 */
70 typedef void (* leKeyPadWidget_KeyClickEvent)(leKeyPadWidget*,
71  leButtonWidget*,
72  uint32_t,
73  uint32_t);
74 
75 // *****************************************************************************
76 // *****************************************************************************
77 // Section: Data Types and Constants
78 // *****************************************************************************
79 // *****************************************************************************
80 
81 // *****************************************************************************
82 /* Structure:
83  leKeyPadCellAction
84 
85  Summary:
86  Defines an assigned action to a key pad cell
87 
88  Description:
89 
90 
91  Remarks:
92  None.
93 */
94 typedef enum leKeyPadCellAction
95 {
96  LE_KEYPAD_CELL_ACTION_NONE,
97  LE_KEYPAD_CELL_ACTION_APPEND,
98  LE_KEYPAD_CELL_ACTION_SET,
99  LE_KEYPAD_CELL_ACTION_BACKSPACE,
100  LE_KEYPAD_CELL_ACTION_CLEAR,
101  LE_KEYPAD_CELL_ACTION_ACCEPT
102 } leKeyPadCellAction;
103 
104 // *****************************************************************************
105 /* Structure:
106  leKeyPadActionTrigger
107 
108  Summary:
109  Defines the trigger for keypad action and events
110 
111  Description:
112 
113 
114  Remarks:
115  None.
116 */
117 typedef enum leKeyPadActionTrigger
118 {
119  LE_KEYPAD_TRIGGER_KEYRELEASED,
120  LE_KEYPAD_TRIGGER_KEYPRESSED,
121 } leKeyPadActionTrigger;
122 
123 // *****************************************************************************
124 /* Structure:
125  leKeyPadCell
126 
127  Summary:
128  Defines a key pad cell struct
129 
130  Description:
131  A key pad is made up of an array of key pad cells. Each cell is individually
132  an leButtonWidget, an action, a value, and a few other options.
133 
134  Remarks:
135  None.
136 */
137 typedef struct leKeyPadCell
138 {
139  leBool enabled; // indicates if the cell should be drawn
140  leButtonWidget* button; // the button that handles the cell input events
141  // and rendering
142  leKeyPadCellAction action; // the action that occurs when the cell is
143  // activated
144  const leString* value; // the value that is passed to the edit event system
145 } leKeyPadCell;
146 
147 /* internal use only */
152 #define LE_KEYPADWIDGET_VTABLE(THIS_TYPE) \
153  LE_WIDGET_VTABLE(THIS_TYPE) \
154  \
155  leResult (*setCellArraySize)(THIS_TYPE* _this, uint32_t rows, uint32_t cols); \
156  leKeyPadActionTrigger (*getKeyPadActionTrigger)(const THIS_TYPE* _this); \
157  leResult (*setKeyPadActionTrigger)(THIS_TYPE* _this, leKeyPadActionTrigger trg); \
158  leKeyPadWidget_KeyClickEvent (*getKeyClickEventCallback)(const THIS_TYPE* _this); \
159  leResult (*setKeyClickEventCallback)(THIS_TYPE* _this, leKeyPadWidget_KeyClickEvent cb); \
160  leResult (*setKeyVisible)(THIS_TYPE* _this, uint32_t row, uint32_t col, leBool b); \
161  leKeyPadCellAction (*getKeyAction)(const THIS_TYPE* _this, uint32_t row, uint32_t col); \
162  leResult (*setKeyAction)(THIS_TYPE* _this, uint32_t row, uint32_t col, leKeyPadCellAction action); \
163  leString* (*getKeyValue)(const THIS_TYPE* _this, uint32_t row, uint32_t col); \
164  leResult (*setKeyValue)(THIS_TYPE* _this, uint32_t row, uint32_t col, const leString* val); \
165  leButtonWidget* (*getCellButton)(const THIS_TYPE* _this, uint32_t row, uint32_t col); \
166 
167 typedef struct leKeyPadWidgetVTable
168 {
169  LE_KEYPADWIDGET_VTABLE(leKeyPadWidget)
170 } leKeyPadWidgetVTable;
171 
177 // *****************************************************************************
185 typedef struct leKeyPadWidget
186 {
187  leWidget widget; // widget base class
188 
189  const leKeyPadWidgetVTable* fn;
190 
191  uint32_t rows; // number of button rows
192  uint32_t cols; // number of button columns
193 
194  leKeyPadActionTrigger trigger; //trigger for action and events
195 
196  leKeyPadCell** cells; // key cell array
197 
198  leKeyPadWidget_KeyClickEvent clickEvt; // key click callback event
199 } leKeyPadWidget;
200 
201 // *****************************************************************************
202 // *****************************************************************************
203 // Section: Routines
204 // *****************************************************************************
205 // *****************************************************************************
206 
218 leKeyPadWidget* leKeyPadWidget_New(uint32_t rows,
219  uint32_t cols);
220 
235 void leKeyPadWidget_Constructor(leKeyPadWidget* wgt,
236  uint32_t rows,
237  uint32_t cols);
238 
239 #ifdef _DOXYGEN_
240 #define THIS_TYPE struct leWidget
241 
242 // *****************************************************************************
243 /* Virtual Member Function:
244  leKeyPadActionTrigger getKeyPadActionTrigger(const leKeyPadWidget* _this)
245 
246  Summary:
247  Gets the keypad trigger action
248 
249  Description:
250  Gets the keypad trigger action
251 
252  Parameters:
253  const leKeyPadWidget* _this - The keypad widget to operate on
254 
255  Remarks:
256  Usage - _this->fn->getKeyPadActionTrigger(_this);
257 
258  Returns:
259  leKeyPadActionTrigger - the trigger action
260 */
261 
262 // *****************************************************************************
263 /* Virtual Member Function:
264  leResult setKeyPadActionTrigger(leKeyPadWidget* _this,
265  leKeyPadActionTrigger trg)
266 
267  Summary:
268  Sets the keypad trigger action
269 
270  Description:
271  Sets the keypad trigger action
272 
273  Parameters:
274  leKeyPadWidget* _this - The keypad widget to operate on
275  leKeyPadActionTrigger trg - the trigger action
276 
277  Remarks:
278  Usage - _this->fn->setKeyPadActionTrigger(_this, trg);
279 
280  Returns:
281  leResult - the result of the operation
282 */
283 
294 virtual leKeyPadWidget_KeyClickEvent getKeyClickEventCallback(const leKeyPadWidget* _this);
295 
309 virtual leResult setKeyClickEventCallback(leKeyPadWidget* _this,
310  leKeyPadWidget_KeyClickEvent cb);
311 
312 // *****************************************************************************
313 /* Virtual Member Function:
314  leResult setKeyClickEventCallback(leKeyPadWidget* _this,
315  leKeyPadWidget_KeyClickEvent cb)
316 
317  Summary:
318  Sets the key click event callback
319 
320  Description:
321  Sets the key click event callback
322 
323  Parameters:
324  leKeyPadWidget* _this - The keypad widget to operate on
325  leKeyPadWidget_KeyClickEvent cb - the callback pointer
326 
327  Remarks:
328  Usage - _this->fn->setKeyClickEventCallback(_this, cb);
329 
330  Returns:
331  leResult - the result of the operation
332 */
333 
334 // *****************************************************************************
335 /* Virtual Member Function:
336  leResult setKeyVisible(leKeyPadWidget* _this,
337  uint32_t row,
338  uint32_t col,
339  leBool b)
340 
341  Summary:
342  Sets the enabled state of a key
343 
344  Description:
345  Sets the enabled state of a key
346 
347  Parameters:
348  leKeyPadWidget* _this - The keypad widget to operate on
349  uint32_t row - the row index
350  uint32_t col - the column index
351  leBool b -
352 
353  Remarks:
354  Usage - _this->fn->setKeyVisible(_this, row, col, b);
355 
356  Returns:
357  leResult - the result of the operation
358 */
359 
360 // *****************************************************************************
361 /* Virtual Member Function:
362  leKeyPadCellAction getKeyAction(const leKeyPadWidget* _this,
363  uint32_t row,
364  uint32_t col)
365 
366  Summary:
367  Gets the key action setting
368 
369  Description:
370  Gets the key action setting
371 
372  Parameters:
373  const leKeyPadWidget* _this - The keypad widget to operate on
374  uint32_t row - the row index
375  uint32_t col - the column index
376 
377  Remarks:
378  Usage - _this->fn->getKeyAction(_this, row, col);
379 
380  Returns:
381  leKeyPadCellAction - the cell action value
382 */
383 
384 // *****************************************************************************
385 /* Virtual Member Function:
386  leResult setKeyAction(leKeyPadWidget* _this,
387  uint32_t row,
388  uint32_t col,
389  leKeyPadCellAction action)
390 
391  Summary:
392  Sets the key action setting
393 
394  Description:
395  Sets the key action setting
396 
397  Parameters:
398  leKeyPadWidget* _this - The keypad widget to operate on
399  uint32_t row - the row index
400  uint32_t col - the column index
401  leKeyPadCellAction action - the cell action value
402 
403  Remarks:
404  Usage - _this->fn->setKeyAction(_this, row, col, action);
405 
406  Returns:
407  leResult - the result of the operation
408 */
409 
410 // *****************************************************************************
411 /* Virtual Member Function:
412  leString* getKeyValue(const leKeyPadWidget* _this,
413  uint32_t row,
414  uint32_t col)
415 
416  Summary:
417  Gets the key value
418 
419  Description:
420  Gets the key value
421 
422  Parameters:
423  const leKeyPadWidget* _this - The keypad widget to operate on
424  uint32_t row - the row index
425  uint32_t col - the column index
426 
427  Remarks:
428  Usage - _this->fn->getKeyValue(_this, row, col);
429 
430  Returns:
431  leString* - the string pointer
432 */
433 
434 // *****************************************************************************
435 /* Virtual Member Function:
436  leResult setKeyValue(leKeyPadWidget* _this,
437  uint32_t row,
438  uint32_t col,
439  const leString* val)
440 
441  Summary:
442  Sets the key value
443 
444  Description:
445  Sets the key value
446 
447  Parameters:
448  leKeyPadWidget* _this - The keypad widget to operate on
449  uint32_t row - the row index
450  uint32_t col - the column index
451  const leString* val - the string pointer
452 
453  Remarks:
454  Usage - _this->fn->setKeyValue(_this, row, col, val);
455 
456  Returns:
457  leResult - the result of the operation
458 */
459 
460 // *****************************************************************************
461 /* Virtual Member Function:
462  leButtonWidget* getCellButton(const leKeyPadWidget* _this,
463  uint32_t row,
464  uint32_t col)
465 
466  Summary:
467  Get a button widget pointer from the keypad
468 
469  Description:
470  Get a button widget pointer from the keypad
471 
472  Parameters:
473  const leKeyPadWidget* _this - The keypad widget to operate on
474  uint32_t row - the row index
475  uint32_t col - the column index
476 
477  Remarks:
478  Usage - _this->fn->getCellButton(_this, row, col);
479 
480  Returns:
481  leButtonWidget* - pointer to the button widget
482 */
483 
484 #undef THIS_TYPE
485 #endif
486 
487 #ifdef __cplusplus
488 }
489 #endif
490 
491 #endif // LE_WIDGET_KEYPAD_ENABLED && LE_WIDGET_BUTTON_ENABLED
492 #endif /* LEGATO_KEYPAD_H */
Definition: action.py:1
Common macros and definitions used by Legato.
This struct represents a string.
Definition: legato_string.h:107
leResult
This enum represents function call results.
Definition: legato_common.h:123
Edit widget functions and definitions.
Used to define a widget.
Definition: legato_widget.h:624
leBool
This enum represents booleans.
Definition: legato_common.h:146
Definition: widget.py:1
Fixed string functions and definitions.