GUIslice  0.16.0
Embedded GUI in C
XSeekbar.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_EX_XSEEKBAR_H_
2 #define _GUISLICE_EX_XSEEKBAR_H_
3 
4 #include "GUIslice.h"
5 
6 
7 // =======================================================================
8 // GUIslice library extension: Seekbar control
9 // - Paul Conti
10 // - Seekbar is a modern Slider Control with Android like style
11 // - Based on Calvin Hass's Slider control
12 // - https://www.impulseadventure.com/elec/guislice-gui.html
13 // - https://github.com/ImpulseAdventure/GUIslice
14 // =======================================================================
15 //
16 // The MIT License
17 //
18 // Copyright 2016-2020 Calvin Hass
19 //
20 // Permission is hereby granted, free of charge, to any person obtaining a copy
21 // of this software and associated documentation files (the "Software"), to deal
22 // in the Software without restriction, including without limitation the rights
23 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24 // copies of the Software, and to permit persons to whom the Software is
25 // furnished to do so, subject to the following conditions:
26 //
27 // The above copyright notice and this permission notice shall be included in
28 // all copies or substantial portions of the Software.
29 //
30 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
36 // THE SOFTWARE.
37 //
38 // =======================================================================
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif // __cplusplus
44 
45 
46 // ============================================================================
47 // Extended Element: Seekbar
48 // ============================================================================
49 
50 // Define unique identifier for extended element type
51 // - Select any number above GSLC_TYPE_BASE_EXTEND
52 #define GSLC_TYPEX_SEEKBAR GSLC_TYPE_BASE_EXTEND + 6
53 
55 typedef bool (*GSLC_CB_XSEEKBAR_POS)(void* pvGui,void* pvElem,int16_t nPos);
56 
57 // Extended element data structures
58 // - These data structures are maintained in the gslc_tsElem
59 // structure via the pXData pointer
60 
62 typedef struct {
63  // Config
64  bool bVert;
65  uint8_t nProgressW;
66  uint8_t nRemainW;
67  uint8_t nThumbSz;
68  int16_t nPosMin;
69  int16_t nPosMax;
70  // Style config
74  uint16_t nTickDiv;
75  int16_t nTickLen;
77  bool bTrimThumb;
79  bool bFrameThumb;
81  // State
82  int16_t nPos;
83  // Callbacks
86 
87 
109 gslc_tsElemRef* gslc_ElemXSeekbarCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t nPage,
110  gslc_tsXSeekbar* pXData,gslc_tsRect rElem,int16_t nPosMin,int16_t nPosMax,int16_t nPos,
111  uint8_t nProgressW,uint8_t nRemainW,uint8_t nThumbSz,
112  gslc_tsColor colProgress,gslc_tsColor colRemain,gslc_tsColor colThumb,bool bVert);
113 
114 
131  bool bTrimThumb,gslc_tsColor colTrim,bool bFrameThumb,gslc_tsColor colFrame,uint16_t nTickDiv,
132  int16_t nTickLen,gslc_tsColor colTick);
133 
143 
144 
155 void gslc_ElemXSeekbarSetPos(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,int16_t nPos);
156 
167 
178 bool gslc_ElemXSeekbarDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
179 
192 bool gslc_ElemXSeekbarTouch(void* pvGui,void* pvElemRef,gslc_teTouch eTouch,int16_t nRelX,int16_t nRelY);
193 
194 // ============================================================================
195 
196 // ------------------------------------------------------------------------
197 // Read-only element macros
198 // ------------------------------------------------------------------------
199 
200 // Macro initializers for Read-Only Elements in Flash/PROGMEM
201 //
202 
203 
204 
232 
233 #if (GSLC_USE_PROGMEM)
234 
235 
236 #define gslc_ElemXSeekbarCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,nPosMin_,nPosMax_, \
237  nPos_,nProgressW_,nRemainW_,nThumbSz_,colProgress_,colRemain_,colThumb_,bVert_, \
238  colFrame_,colFill_) \
239  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
240  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_CLICK_EN | GSLC_ELEM_FEA_FILL_EN; \
241  static gslc_tsXSeekbar sSeekbar##nElemId; \
242  sSeekbar##nElemId.bVert = bVert_; \
243  sSeekbar##nElemId.nProgressW = nProgressW_; \
244  sSeekbar##nElemId.nRemainW = nRemainW_; \
245  sSeekbar##nElemId.nThumbSz = nThumbSz_; \
246  sSeekbar##nElemId.nPosMin = nPosMin_; \
247  sSeekbar##nElemId.nPosMax = nPosMax_; \
248  sSeekbar##nElemId.colProgress = colProgress_; \
249  sSeekbar##nElemId.colRemain = colRemain_; \
250  sSeekbar##nElemId.colThumb = colThumb_; \
251  sSeekbar##nElemId.nPos = nPos_; \
252  sSeekbar##nElemId.pfuncXPos = NULL; \
253  static const gslc_tsElem sElem##nElemId PROGMEM = { \
254  nElemId, \
255  nFeatures##nElemId, \
256  GSLC_TYPEX_SEEKBAR, \
257  (gslc_tsRect){nX,nY,nW,nH}, \
258  GSLC_GROUP_ID_NONE, \
259  colFrame_,colFill_,colFrame_,colFill_, \
260  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
261  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
262  NULL, \
263  NULL, \
264  0, \
265  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
266  GSLC_COL_WHITE, \
267  GSLC_COL_WHITE, \
268  GSLC_ALIGN_MID_MID, \
269  0, \
270  0, \
271  NULL, \
272  (void*)(&sSeekbar##nElemId), \
273  NULL, \
274  &gslc_ElemXSeekbarDraw, \
275  &gslc_ElemXSeekbarTouch, \
276  NULL, \
277  }; \
278  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
279  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_PROG | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
280 
281 #else
282 
283 
284 #define gslc_ElemXSeekbarCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,nPosMin_,nPosMax_, \
285  nPos_,nProgressW_,nRemainW_,nThumbSz_,colProgress_,colRemain_,colThumb_,bVert_, \
286  colFrame_,colFill_) \
287  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
288  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_CLICK_EN | GSLC_ELEM_FEA_FILL_EN; \
289  static gslc_tsXSeekbar sSeekbar##nElemId; \
290  sSeekbar##nElemId.bVert = bVert_; \
291  sSeekbar##nElemId.nProgressW = nProgressW_; \
292  sSeekbar##nElemId.nRemainW = nRemainW_; \
293  sSeekbar##nElemId.nThumbSz = nThumbSz_; \
294  sSeekbar##nElemId.nPosMin = nPosMin_; \
295  sSeekbar##nElemId.nPosMax = nPosMax_; \
296  sSeekbar##nElemId.colProgress = colProgress_; \
297  sSeekbar##nElemId.colRemain = colRemain_; \
298  sSeekbar##nElemId.colThumb = colThumb_; \
299  sSeekbar##nElemId.nPos = nPos_; \
300  sSeekbar##nElemId.pfuncXPos = NULL; \
301  static const gslc_tsElem sElem##nElemId = { \
302  nElemId, \
303  nFeatures##nElemId, \
304  GSLC_TYPEX_SEEKBAR, \
305  (gslc_tsRect){nX,nY,nW,nH}, \
306  GSLC_GROUP_ID_NONE, \
307  colFrame_,colFill_,colFrame_,colFill_, \
308  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
309  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
310  NULL, \
311  NULL, \
312  0, \
313  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
314  GSLC_COL_WHITE, \
315  GSLC_COL_WHITE, \
316  GSLC_ALIGN_MID_MID, \
317  0, \
318  0, \
319  NULL, \
320  (void*)(&sSeekbar##nElemId), \
321  NULL, \
322  &gslc_ElemXSeekbarDraw, \
323  &gslc_ElemXSeekbarTouch, \
324  NULL, \
325  }; \
326  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
327  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_CONST | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
328 
329 #endif
330 
331 
332 
333 #ifdef __cplusplus
334 }
335 #endif // __cplusplus
336 #endif // _GUISLICE_EX_XSEEKBAR_H_
gslc_tsColor colTrim
Style: color of trim.
Definition: XSeekbar.h:78
int16_t nTickLen
Style: length of tickmarks.
Definition: XSeekbar.h:75
bool bFrameThumb
Style: draw frame around thumb.
Definition: XSeekbar.h:79
uint8_t nThumbSz
Size of the thumb control.
Definition: XSeekbar.h:67
int gslc_ElemXSeekbarGetPos(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef)
Get a Seekbar element's current position.
Definition: XSeekbar.c:171
gslc_teRedrawType
Redraw types.
Definition: GUIslice.h:370
gslc_tsColor colRemain
Style: color remaining fill bar.
Definition: XSeekbar.h:72
int16_t nPosMin
Minimum position value of the slider.
Definition: XSeekbar.h:68
int16_t nPosMax
Maximum position value of the slider.
Definition: XSeekbar.h:69
void gslc_ElemXSeekbarSetStyle(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, bool bTrimThumb, gslc_tsColor colTrim, bool bFrameThumb, gslc_tsColor colFrame, uint16_t nTickDiv, int16_t nTickLen, gslc_tsColor colTick)
Set a Seekbar element's style, this includes thumb customizations and tick marks. ...
Definition: XSeekbar.c:147
gslc_tsElemRef * gslc_ElemXSeekbarCreate(gslc_tsGui *pGui, int16_t nElemId, int16_t nPage, gslc_tsXSeekbar *pXData, gslc_tsRect rElem, int16_t nPosMin, int16_t nPosMax, int16_t nPos, uint8_t nProgressW, uint8_t nRemainW, uint8_t nThumbSz, gslc_tsColor colProgress, gslc_tsColor colRemain, gslc_tsColor colThumb, bool bVert)
Create a Seekbar Element.
Definition: XSeekbar.c:79
gslc_tsColor colProgress
Style: color of progress fill bar.
Definition: XSeekbar.h:71
gslc_tsColor colThumb
Style: color of thumb.
Definition: XSeekbar.h:73
bool(* GSLC_CB_XSEEKBAR_POS)(void *pvGui, void *pvElem, int16_t nPos)
Callback function for slider feedback.
Definition: XSeekbar.h:55
bool gslc_ElemXSeekbarDraw(void *pvGui, void *pvElemRef, gslc_teRedrawType eRedraw)
Draw a Seekbar element on the screen.
Definition: XSeekbar.c:235
void gslc_ElemXSeekbarSetPosFunc(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, GSLC_CB_XSEEKBAR_POS funcCb)
Assign the position callback function for a slider.
Definition: XSeekbar.c:218
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
void gslc_ElemXSeekbarSetPos(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int16_t nPos)
Set a Seekbar element's current position.
Definition: XSeekbar.c:185
bool bTrimThumb
Style: show a trim color for thumb.
Definition: XSeekbar.h:77
uint8_t nRemainW
Width of remaining track.
Definition: XSeekbar.h:66
Element reference structure.
Definition: GUIslice.h:578
Extended data for Seekbar element.
Definition: XSeekbar.h:62
gslc_tsColor colFrame
Style: color of trim.
Definition: XSeekbar.h:80
gslc_tsColor colTick
Style: color of ticks.
Definition: XSeekbar.h:76
int16_t nPos
Current position value of the slider.
Definition: XSeekbar.h:82
uint16_t nTickDiv
Style: number of tickmark divisions (0 for none)
Definition: XSeekbar.h:74
gslc_teTouch
Processed event from input raw events and actions.
Definition: GUIslice.h:305
bool gslc_ElemXSeekbarTouch(void *pvGui, void *pvElemRef, gslc_teTouch eTouch, int16_t nRelX, int16_t nRelY)
Handle touch events to Seekbar element.
Definition: XSeekbar.c:418
GUI structure.
Definition: GUIslice.h:716
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534
uint8_t nProgressW
Width of progress track.
Definition: XSeekbar.h:65
bool bVert
Orientation: true if vertical, else horizontal.
Definition: XSeekbar.h:64
GSLC_CB_XSEEKBAR_POS pfuncXPos
Callback func ptr for position update.
Definition: XSeekbar.h:84