GUIslice  0.16.0
Embedded GUI in C
XSpinner.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_EX_XSPINNER_H_
2 #define _GUISLICE_EX_XSPINNER_H_
3 
4 #include "GUIslice.h"
5 
6 
7 // =======================================================================
8 // GUIslice library extension: Spinner (number selection) control
9 // - Extension by Paul Conti, Calvin Hass
10 // - https://www.impulseadventure.com/elec/guislice-gui.html
11 // - https://github.com/ImpulseAdventure/GUIslice
12 // =======================================================================
13 //
14 // The MIT License
15 //
16 // Copyright 2016-2020 Calvin Hass
17 //
18 // Permission is hereby granted, free of charge, to any person obtaining a copy
19 // of this software and associated documentation files (the "Software"), to deal
20 // in the Software without restriction, including without limitation the rights
21 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22 // copies of the Software, and to permit persons to whom the Software is
23 // furnished to do so, subject to the following conditions:
24 //
25 // The above copyright notice and this permission notice shall be included in
26 // all copies or substantial portions of the Software.
27 //
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34 // THE SOFTWARE.
35 //
36 // =======================================================================
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif // __cplusplus
42 
43 
44 
45 #if (GSLC_FEATURE_COMPOUND)
46 // ============================================================================
47 // Extended Element: Spinner (Number Selector)
48 // - Demonstration of a compound element consisting of
49 // a counter text field along with an increment and
50 // decrement button.
51 // ============================================================================
52 
53 // Define unique identifier for extended element type
54 // - Select any number above GSLC_TYPE_BASE_EXTEND
55 #define GSLC_TYPEX_SPINNER GSLC_TYPE_BASE_EXTEND + 15
56 
57 // Define the max number of sub-elements in compound element
58 #define XSPINNER_COMP_CNT 3
59 
60 // Define the max string length to allocate for dynamic text elements
61 #define XSPINNER_STR_LEN 8
62 
63 // Define the status for GSLC_CB_INPUT callback
64 #define XSPINNER_CB_STATE_UPDATE 3
65 
66 // Extended element data structures
67 // - These data structures are maintained in the gslc_tsElem
68 // structure via the pXData pointer
70 typedef struct {
71 
72  // Core functionality for Spinner
73  int16_t nMin;
74  int16_t nMax;
75  int16_t nIncr;
76  int16_t nCounter;
79 
80  // Internal sub-element members
84 
85  // Provide storage for any dynamic text elements
86  // Simple example here uses fixed-length character array
87  char acElemTxt[1][XSPINNER_STR_LEN];
88  char acIncr[2];
89  char acDecr[2];
90 
92 
93 
94 
95 
114 gslc_tsElemRef* gslc_ElemXSpinnerCreate(gslc_tsGui* pGui, int16_t nElemId, int16_t nPage, gslc_tsXSpinner* pXData,
115  gslc_tsRect rElem, int16_t nMin, int16_t nMax, int16_t nVal, int16_t nIncr,
116  int8_t nFontId, int8_t nButtonSz, GSLC_CB_INPUT cbInput);
117 
118 
130 bool gslc_ElemXSpinnerSetChars(void* pvGui,gslc_tsElemRef* pElemRef,uint8_t cIncr, uint8_t cDecr);
131 
132 
143 bool gslc_ElemXSpinnerDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
144 
154 
155 
165 void gslc_ElemXSpinnerSetCounter(gslc_tsGui* pGui,gslc_tsXSpinner* pSpinner,int16_t nCount);
166 
167 
180 bool gslc_ElemXSpinnerClick(void* pvGui,void *pvElemRef,gslc_teTouch eTouch,int16_t nX,int16_t nY);
181 
194 bool gslc_ElemXSpinnerTouch(void* pvGui,void* pvElemRef,gslc_teTouch eTouch,int16_t nRelX,int16_t nRelY);
195 
196 #endif // GLSC_COMPOUND
197 
198 // ============================================================================
199 
200 // ------------------------------------------------------------------------
201 // Read-only element macros
202 // ------------------------------------------------------------------------
203 
204 // Macro initializers for Read-Only Elements in Flash/PROGMEM
205 //
206 #ifdef __cplusplus
207 }
208 #endif // __cplusplus
209 #endif // _GUISLICE_EX_XSPINNER_H_
210 
bool gslc_ElemXSpinnerClick(void *pvGui, void *pvElemRef, gslc_teTouch eTouch, int16_t nX, int16_t nY)
Handle a click event within the Spinner.
Definition: XSpinner.c:343
bool(* GSLC_CB_INPUT)(void *pvGui, void *pvElemRef, int16_t nStatus, void *pvData)
Callback function for element input ready.
Definition: GUIslice.h:511
int16_t nMax
Maximum control value.
Definition: XSpinner.h:74
int gslc_ElemXSpinnerGetCounter(gslc_tsGui *pGui, gslc_tsXSpinner *pSpinner)
Get the current counter associated with Spinner.
Definition: XSpinner.c:301
gslc_tsCollect sCollect
Collection management for sub-elements.
Definition: XSpinner.h:81
gslc_teRedrawType
Redraw types.
Definition: GUIslice.h:370
gslc_tsElemRef * pElemRef
Save our ElemRef for the callback.
Definition: XSpinner.h:78
Extended data for Spinner element.
Definition: XSpinner.h:70
int16_t nCounter
Current value.
Definition: XSpinner.h:76
#define XSPINNER_COMP_CNT
Definition: XSpinner.h:58
int16_t nIncr
Increment by value.
Definition: XSpinner.h:75
bool gslc_ElemXSpinnerSetChars(void *pvGui, gslc_tsElemRef *pElemRef, uint8_t cIncr, uint8_t cDecr)
Set Up and Down characters for the Spinner element.
Definition: XSpinner.c:232
gslc_tsElemRef * gslc_ElemXSpinnerCreate(gslc_tsGui *pGui, int16_t nElemId, int16_t nPage, gslc_tsXSpinner *pXData, gslc_tsRect rElem, int16_t nMin, int16_t nMax, int16_t nVal, int16_t nIncr, int8_t nFontId, int8_t nButtonSz, GSLC_CB_INPUT cbInput)
Create a Spinner Element.
Definition: XSpinner.c:84
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
int16_t nMin
Minimum control value.
Definition: XSpinner.h:73
Element collection struct.
Definition: GUIslice.h:656
Element reference structure.
Definition: GUIslice.h:578
bool gslc_ElemXSpinnerTouch(void *pvGui, void *pvElemRef, gslc_teTouch eTouch, int16_t nRelX, int16_t nRelY)
Handle touch (up,down,move) events to Spinner element.
Definition: XSpinner.c:409
bool gslc_ElemXSpinnerDraw(void *pvGui, void *pvElemRef, gslc_teRedrawType eRedraw)
Draw a Spinner element on the screen.
Definition: XSpinner.c:254
#define XSPINNER_STR_LEN
Definition: XSpinner.h:61
gslc_teTouch
Processed event from input raw events and actions.
Definition: GUIslice.h:305
void gslc_ElemXSpinnerSetCounter(gslc_tsGui *pGui, gslc_tsXSpinner *pSpinner, int16_t nCount)
Set the current counter associated with Spinner.
Definition: XSpinner.c:312
GUI structure.
Definition: GUIslice.h:716
Element Struct.
Definition: GUIslice.h:593
GSLC_CB_INPUT pfuncXInput
Callback func ptr for input ready.
Definition: XSpinner.h:77