GUIslice  0.16.0
Embedded GUI in C
XCheckbox.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_EX_XCHECKBOX_H_
2 #define _GUISLICE_EX_XCHECKBOX_H_
3 
4 #include "GUIslice.h"
5 
6 
7 // =======================================================================
8 // GUIslice library extension: Checkbox/Radio button control
9 // - 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 // Extended Element: Checkbox
45 // ============================================================================
46 
47 // Define unique identifier for extended element type
48 // - Select any number above GSLC_TYPE_BASE_EXTEND
49 #define GSLC_TYPEX_CHECKBOX GSLC_TYPE_BASE_EXTEND + 1
50 
52 typedef enum {
57 
61 typedef bool (*GSLC_CB_XCHECKBOX)(void* pvGui,void* pvElemRef,int16_t nSelId, bool bChecked);
62 
63 // Extended element data structures
64 // - These data structures are maintained in the gslc_tsElem
65 // structure via the pXData pointer
66 
68 typedef struct {
69  bool bRadio;
70  gslc_teXCheckboxStyle nStyle;
71  bool bChecked;
75 
76 
92 gslc_tsElemRef* gslc_ElemXCheckboxCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t nPage,
93  gslc_tsXCheckbox* pXData,gslc_tsRect rElem,bool bRadio,
94  gslc_teXCheckboxStyle nStyle,gslc_tsColor colCheck,bool bChecked);
95 
96 
106 
116 void gslc_ElemXCheckboxSetState(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,bool bChecked);
117 
127 
137 
148 
159 bool gslc_ElemXCheckboxDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
160 
173 bool gslc_ElemXCheckboxTouch(void* pvGui,void* pvElemRef,gslc_teTouch eTouch,int16_t nRelX,int16_t nRelY);
174 // ============================================================================
175 
176 // ------------------------------------------------------------------------
177 // Read-only element macros
178 // ------------------------------------------------------------------------
179 
180 // Macro initializers for Read-Only Elements in Flash/PROGMEM
181 //
182 
183 
205 
206 #if (GSLC_USE_PROGMEM)
207 
208 #define gslc_ElemXCheckboxCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,colFill,bFillEn,nGroup,bRadio_,nStyle_,colCheck_,bChecked_) \
209  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
210  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_CLICK_EN | (bFillEn?GSLC_ELEM_FEA_FILL_EN:0); \
211  static gslc_tsXCheckbox sCheckbox##nElemId; \
212  sCheckbox##nElemId.bRadio = bRadio_; \
213  sCheckbox##nElemId.bChecked = bChecked_; \
214  sCheckbox##nElemId.colCheck = colCheck_; \
215  sCheckbox##nElemId.nStyle = nStyle_; \
216  static const gslc_tsElem sElem##nElemId PROGMEM = { \
217  nElemId, \
218  nFeatures##nElemId, \
219  GSLC_TYPEX_CHECKBOX, \
220  (gslc_tsRect){nX,nY,nW,nH}, \
221  nGroup, \
222  GSLC_COL_GRAY,colFill,GSLC_COL_WHITE,GSLC_COL_BLACK, \
223  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
224  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
225  NULL, \
226  NULL, \
227  0, \
228  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
229  GSLC_COL_WHITE, \
230  GSLC_COL_WHITE, \
231  GSLC_ALIGN_MID_MID, \
232  0, \
233  0, \
234  NULL, \
235  (void*)(&sCheckbox##nElemId), \
236  NULL, \
237  &gslc_ElemXCheckboxDraw, \
238  &gslc_ElemXCheckboxTouch, \
239  NULL, \
240  }; \
241  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
242  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_PROG | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
243 
244 
245 #else
246 
247 #define gslc_ElemXCheckboxCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,colFill,bFillEn,nGroup,bRadio_,nStyle_,colCheck_,bChecked_) \
248  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
249  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_CLICK_EN | (bFillEn?GSLC_ELEM_FEA_FILL_EN:0); \
250  static gslc_tsXCheckbox sCheckbox##nElemId; \
251  sCheckbox##nElemId.bRadio = bRadio_; \
252  sCheckbox##nElemId.bChecked = bChecked_; \
253  sCheckbox##nElemId.colCheck = colCheck_; \
254  sCheckbox##nElemId.nStyle = nStyle_; \
255  static const gslc_tsElem sElem##nElemId = { \
256  nElemId, \
257  nFeatures##nElemId, \
258  GSLC_TYPEX_CHECKBOX, \
259  (gslc_tsRect){nX,nY,nW,nH}, \
260  nGroup, \
261  GSLC_COL_GRAY,colFill,GSLC_COL_WHITE,GSLC_COL_BLACK, \
262  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
263  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
264  NULL, \
265  NULL, \
266  0, \
267  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
268  GSLC_COL_WHITE, \
269  GSLC_COL_WHITE, \
270  GSLC_ALIGN_MID_MID, \
271  0, \
272  0, \
273  NULL, \
274  (void*)(&sCheckbox##nElemId), \
275  NULL, \
276  &gslc_ElemXCheckboxDraw, \
277  &gslc_ElemXCheckboxTouch, \
278  NULL, \
279  }; \
280  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
281  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_CONST | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
282 
283 #endif
284 
285 
286 #ifdef __cplusplus
287 }
288 #endif // __cplusplus
289 #endif // _GUISLICE_EX_XCHECKBOX_H_
290 
void gslc_ElemXCheckboxToggleState(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef)
Toggle a Checkbox element's current state.
Definition: XCheckbox.c:358
bool gslc_ElemXCheckboxDraw(void *pvGui, void *pvElemRef, gslc_teRedrawType eRedraw)
Draw a Checkbox element on the screen.
Definition: XCheckbox.c:378
gslc_teRedrawType
Redraw types.
Definition: GUIslice.h:370
GSLC_CB_XCHECKBOX pfuncXToggle
Callback event to say element has changed.
Definition: XCheckbox.h:73
Extended data for Checkbox element.
Definition: XCheckbox.h:68
Crossed.
Definition: XCheckbox.h:54
gslc_teXCheckboxStyle nStyle
Drawing style for element.
Definition: XCheckbox.h:70
gslc_tsColor colCheck
Color of checked inner fill.
Definition: XCheckbox.h:72
bool bChecked
Indicates if it is selected (checked)
Definition: XCheckbox.h:71
bool gslc_ElemXCheckboxGetState(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef)
Get a Checkbox element's current state.
Definition: XCheckbox.c:130
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
gslc_tsElemRef * gslc_ElemXCheckboxFindChecked(gslc_tsGui *pGui, int16_t nGroupId)
Find the checkbox within a group that has been checked.
Definition: XCheckbox.c:140
bool(* GSLC_CB_XCHECKBOX)(void *pvGui, void *pvElemRef, int16_t nSelId, bool bChecked)
Callback function for checkbox/radio element state change.
Definition: XCheckbox.h:61
Inner box.
Definition: XCheckbox.h:53
Element reference structure.
Definition: GUIslice.h:578
bool gslc_ElemXCheckboxTouch(void *pvGui, void *pvElemRef, gslc_teTouch eTouch, int16_t nRelX, int16_t nRelY)
Handle touch events to Checkbox element.
Definition: XCheckbox.c:455
gslc_teXCheckboxStyle
Checkbox drawing style.
Definition: XCheckbox.h:52
bool bRadio
Radio-button operation if true.
Definition: XCheckbox.h:69
void gslc_ElemXCheckboxSetStateFunc(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, GSLC_CB_XCHECKBOX pfuncCb)
Assign the state callback function for a checkbox/radio button.
Definition: XCheckbox.c:192
gslc_teTouch
Processed event from input raw events and actions.
Definition: GUIslice.h:305
GUI structure.
Definition: GUIslice.h:716
void gslc_ElemXCheckboxSetState(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, bool bChecked)
Set a Checkbox element's current state.
Definition: XCheckbox.c:270
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534
Circular.
Definition: XCheckbox.h:55
gslc_tsElemRef * gslc_ElemXCheckboxCreate(gslc_tsGui *pGui, int16_t nElemId, int16_t nPage, gslc_tsXCheckbox *pXData, gslc_tsRect rElem, bool bRadio, gslc_teXCheckboxStyle nStyle, gslc_tsColor colCheck, bool bChecked)
Create a Checkbox or Radio button Element.
Definition: XCheckbox.c:78