GUIslice  0.16.0
Embedded GUI in C
XSlider.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_EX_XSLIDER_H_
2 #define _GUISLICE_EX_XSLIDER_H_
3 
4 #include "GUIslice.h"
5 
6 
7 // =======================================================================
8 // GUIslice library extension: Slider 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 // ============================================================================
45 // Extended Element: Slider
46 // ============================================================================
47 
48 // Define unique identifier for extended element type
49 // - Select any number above GSLC_TYPE_BASE_EXTEND
50 #define GSLC_TYPEX_SLIDER GSLC_TYPE_BASE_EXTEND + 2
51 
53 typedef bool (*GSLC_CB_XSLIDER_POS)(void* pvGui,void* pvElem,int16_t nPos);
54 
55 // Extended element data structures
56 // - These data structures are maintained in the gslc_tsElem
57 // structure via the pXData pointer
58 
60 typedef struct {
61  // Config
62  bool bVert;
63  bool bSnapEn;
64  int16_t nThumbSz;
65  int16_t nPosMin;
66  int16_t nPosMax;
67  // Style config
68  uint16_t nTickDiv;
69  int16_t nTickLen;
71  bool bTrim;
73  // State
74  int16_t nPos;
75  // Callbacks
78 
79 
96 gslc_tsElemRef* gslc_ElemXSliderCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t nPage,
97  gslc_tsXSlider* pXData,gslc_tsRect rElem,int16_t nPosMin,int16_t nPosMax,int16_t nPos,
98  uint16_t nThumbSz,bool bVert);
99 
100 
115  bool bTrim,gslc_tsColor colTrim,uint16_t nTickDiv,
116  int16_t nTickLen,gslc_tsColor colTick);
117 
128 void gslc_ElemXSliderSetSnapEn(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,bool bSnapEn);
129 
130 
140 
141 
152 void gslc_ElemXSliderSetPos(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,int16_t nPos);
153 
164 
175 bool gslc_ElemXSliderDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
176 
189 bool gslc_ElemXSliderTouch(void* pvGui,void* pvElemRef,gslc_teTouch eTouch,int16_t nRelX,int16_t nRelY);
190 
191 // ============================================================================
192 
193 // ------------------------------------------------------------------------
194 // Read-only element macros
195 // ------------------------------------------------------------------------
196 
197 // Macro initializers for Read-Only Elements in Flash/PROGMEM
198 //
199 
200 
201 
224 
225 
226 #if (GSLC_USE_PROGMEM)
227 
228 
229 #define gslc_ElemXSliderCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH, \
230  nPosMin_,nPosMax_,nPos_,nThumbSz_,bVert_,colFrame_,colFill_) \
231  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
232  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_CLICK_EN | GSLC_ELEM_FEA_FILL_EN; \
233  static gslc_tsXSlider sSlider##nElemId; \
234  sSlider##nElemId.bVert = bVert_; \
235  sSlider##nElemId.bSnapEn = false; \
236  sSlider##nElemId.nThumbSz = nThumbSz_; \
237  sSlider##nElemId.nPosMin = nPosMin_; \
238  sSlider##nElemId.nPosMax = nPosMax_; \
239  sSlider##nElemId.nTickDiv = 0; \
240  sSlider##nElemId.nTickLen = 0; \
241  sSlider##nElemId.colTick = GSLC_COL_WHITE; \
242  sSlider##nElemId.bTrim = false; \
243  sSlider##nElemId.colTrim = GSLC_COL_BLACK; \
244  sSlider##nElemId.nPos = nPos_; \
245  sSlider##nElemId.pfuncXPos = NULL; \
246  static const gslc_tsElem sElem##nElemId PROGMEM = { \
247  nElemId, \
248  nFeatures##nElemId, \
249  GSLC_TYPEX_SLIDER, \
250  (gslc_tsRect){nX,nY,nW,nH}, \
251  GSLC_GROUP_ID_NONE, \
252  colFrame_,colFill_,colFrame_,colFill_, \
253  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
254  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
255  NULL, \
256  NULL, \
257  0, \
258  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
259  GSLC_COL_WHITE, \
260  GSLC_COL_WHITE, \
261  GSLC_ALIGN_MID_MID, \
262  0, \
263  0, \
264  NULL, \
265  (void*)(&sSlider##nElemId), \
266  NULL, \
267  &gslc_ElemXSliderDraw, \
268  &gslc_ElemXSliderTouch, \
269  NULL, \
270  }; \
271  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
272  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_PROG | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
273 
274 #else
275 
276 
277 #define gslc_ElemXSliderCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH, \
278  nPosMin_,nPosMax_,nPos_,nThumbSz_,bVert_,colFrame_,colFill_) \
279  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
280  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_CLICK_EN | GSLC_ELEM_FEA_FILL_EN; \
281  static gslc_tsXSlider sSlider##nElemId; \
282  sSlider##nElemId.bVert = bVert_; \
283  sSlider##nElemId.bSnapEn = false; \
284  sSlider##nElemId.nThumbSz = nThumbSz_; \
285  sSlider##nElemId.nPosMin = nPosMin_; \
286  sSlider##nElemId.nPosMax = nPosMax_; \
287  sSlider##nElemId.nTickDiv = 0; \
288  sSlider##nElemId.nTickLen = 0; \
289  sSlider##nElemId.colTick = GSLC_COL_WHITE; \
290  sSlider##nElemId.bTrim = false; \
291  sSlider##nElemId.colTrim = GSLC_COL_BLACK; \
292  sSlider##nElemId.nPos = nPos_; \
293  sSlider##nElemId.pfuncXPos = NULL; \
294  static const gslc_tsElem sElem##nElemId = { \
295  nElemId, \
296  nFeatures##nElemId, \
297  GSLC_TYPEX_SLIDER, \
298  (gslc_tsRect){nX,nY,nW,nH}, \
299  GSLC_GROUP_ID_NONE, \
300  colFrame_,colFill_,colFrame_,colFill_, \
301  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
302  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
303  NULL, \
304  NULL, \
305  0, \
306  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
307  GSLC_COL_WHITE, \
308  GSLC_COL_WHITE, \
309  GSLC_ALIGN_MID_MID, \
310  0, \
311  0, \
312  NULL, \
313  (void*)(&sSlider##nElemId), \
314  NULL, \
315  &gslc_ElemXSliderDraw, \
316  &gslc_ElemXSliderTouch, \
317  NULL, \
318  }; \
319  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
320  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_CONST | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
321 
322 #endif
323 
324 
325 
326 #ifdef __cplusplus
327 }
328 #endif // __cplusplus
329 #endif // _GUISLICE_EX_XSLIDER_H_
330 
int16_t nPos
Current position value of the slider.
Definition: XSlider.h:74
gslc_tsColor colTick
Style: color of ticks.
Definition: XSlider.h:70
bool bVert
Orientation: true if vertical, else horizontal.
Definition: XSlider.h:62
int16_t nPosMax
Maximum position value of the slider.
Definition: XSlider.h:66
void gslc_ElemXSliderSetPosFunc(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, GSLC_CB_XSLIDER_POS funcCb)
Assign the position callback function for a slider.
Definition: XSlider.c:219
gslc_teRedrawType
Redraw types.
Definition: GUIslice.h:370
bool gslc_ElemXSliderDraw(void *pvGui, void *pvElemRef, gslc_teRedrawType eRedraw)
Draw a Slider element on the screen.
Definition: XSlider.c:236
void gslc_ElemXSliderSetSnapEn(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, bool bSnapEn)
Enable touch to snap to the nearest tick mark.
Definition: XSlider.c:158
int16_t nTickLen
Style: length of tickmarks.
Definition: XSlider.h:69
int gslc_ElemXSliderGetPos(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef)
Get a Slider element's current position.
Definition: XSlider.c:172
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
uint16_t nTickDiv
Style: number of tickmark divisions (0 for none)
Definition: XSlider.h:68
bool bSnapEn
Enable for touch snap behavior.
Definition: XSlider.h:63
bool(* GSLC_CB_XSLIDER_POS)(void *pvGui, void *pvElem, int16_t nPos)
Callback function for slider feedback.
Definition: XSlider.h:53
gslc_tsElemRef * gslc_ElemXSliderCreate(gslc_tsGui *pGui, int16_t nElemId, int16_t nPage, gslc_tsXSlider *pXData, gslc_tsRect rElem, int16_t nPosMin, int16_t nPosMax, int16_t nPos, uint16_t nThumbSz, bool bVert)
Create a Slider Element.
Definition: XSlider.c:77
void gslc_ElemXSliderSetStyle(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, bool bTrim, gslc_tsColor colTrim, uint16_t nTickDiv, int16_t nTickLen, gslc_tsColor colTick)
Set a Slider element's current position.
Definition: XSlider.c:136
Extended data for Slider element.
Definition: XSlider.h:60
Element reference structure.
Definition: GUIslice.h:578
bool gslc_ElemXSliderTouch(void *pvGui, void *pvElemRef, gslc_teTouch eTouch, int16_t nRelX, int16_t nRelY)
Handle touch events to Slider element.
Definition: XSlider.c:381
gslc_teTouch
Processed event from input raw events and actions.
Definition: GUIslice.h:305
void gslc_ElemXSliderSetPos(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int16_t nPos)
Set a Slider element's current position.
Definition: XSlider.c:186
bool bTrim
Style: show a trim color.
Definition: XSlider.h:71
GSLC_CB_XSLIDER_POS pfuncXPos
Callback func ptr for position update.
Definition: XSlider.h:76
GUI structure.
Definition: GUIslice.h:716
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534
gslc_tsColor colTrim
Style: color of trim.
Definition: XSlider.h:72
int16_t nPosMin
Minimum position value of the slider.
Definition: XSlider.h:65
int16_t nThumbSz
Size of the thumb control.
Definition: XSlider.h:64