GUIslice  0.16.0
Embedded GUI in C
XListbox.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_EX_XLISTBOX_H_
2 #define _GUISLICE_EX_XLISTBOX_H_
3 
4 #include "GUIslice.h"
5 
6 
7 // =======================================================================
8 // GUIslice library extension: Listbox 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: Listbox
46 // - NOTE: The XListbox element is in beta development.
47 // Therefore, its API is subject to change.
48 // ============================================================================
49 
50 // Define unique identifier for extended element type
51 // - Select any number above GSLC_TYPE_BASE_EXTEND
52 #define GSLC_TYPEX_LISTBOX GSLC_TYPE_BASE_EXTEND + 10
53 
54 // Define constants specific to the control
55 #define XLISTBOX_SEL_NONE -9 // Indicator for "no selection"
56 #define XLISTBOX_SIZE_AUTO -1 // Indicator for "auto-size"
57 #define XLISTBOX_BUF_OH_R 2 // Listbox buffer overhead per row
58 
60 typedef bool (*GSLC_CB_XLISTBOX_SEL)(void* pvGui,void* pvElem,int16_t nSel);
61 
62 // Extended element data structures
63 // - These data structures are maintained in the gslc_tsElem
64 // structure via the pXData pointer
65 
67 typedef struct {
68 
69  // Config
70  uint8_t* pBufItems;
71  uint16_t nBufItemsMax;
72  uint16_t nBufItemsPos;
73  int16_t nItemCnt;
74 
75  // Style config
76  int8_t nCols;
77  int8_t nRows;
78  bool bNeedRecalc;
79  int8_t nMarginW;
80  int8_t nMarginH;
81  int16_t nItemW;
82  int16_t nItemH;
83  int8_t nItemGap;
87 
88  // State
89  int16_t nItemCurSel;
90  int16_t nItemCurSelLast;
91  int16_t nItemSavedSel;
92  int16_t nItemTop;
93  bool bGlowLast;
94 
95  // Callbacks
97 
99 
100 
116 gslc_tsElemRef* gslc_ElemXListboxCreate(gslc_tsGui* pGui, int16_t nElemId, int16_t nPage,
117  gslc_tsXListbox* pXData, gslc_tsRect rElem, int16_t nFontId, uint8_t* pBufItems,
118  uint16_t nBufItemsMax, int16_t nSelDefault);
119 
120 
131 void gslc_ElemXListboxSetSize(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef, int8_t nRows, int8_t nCols);
132 
133 
145 void gslc_ElemXListboxSetMargin(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef, int8_t nMarginW, int8_t nMarginH);
146 
157 void gslc_ElemXListboxItemsSetSize(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef, int16_t nItemW, int16_t nItemH);
158 
169 void gslc_ElemXListboxItemsSetGap(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef, int8_t nGap, gslc_tsColor colGap);
170 
171 
180 void gslc_ElemXListboxReset(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef);
181 
182 
192 bool gslc_ElemXListboxAddItem(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef, const char* pStrItem);
193 
204 bool gslc_ElemXListboxInsertItemAt(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef, uint16_t nInsertPos,
205  const char* pStrItem);
206 
216 bool gslc_ElemXListboxDeleteItemAt(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef, uint16_t nDeletePos);
217 
229 bool gslc_ElemXListboxGetItem(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef, int16_t nItemCurSel,
230  char* pStrItem, uint8_t nStrItemLen);
231 
232 
241 int16_t gslc_ElemXListboxGetItemCnt(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef);
242 
253 bool gslc_ElemXListboxDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
254 
267 bool gslc_ElemXListboxTouch(void* pvGui,void* pvElemRef,gslc_teTouch eTouch,int16_t nRelX,int16_t nRelY);
268 
269 
278 int16_t gslc_ElemXListboxGetSel(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef);
279 
280 
290 bool gslc_ElemXListboxSetSel(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef, int16_t nItemCurSel);
291 
301 bool gslc_ElemXListboxSetScrollPos(gslc_tsGui* pGui, gslc_tsElemRef* pElemRef, uint16_t nScrollPos);
302 
303 
314 
315 // ============================================================================
316 
317 // ------------------------------------------------------------------------
318 // Read-only element macros
319 // ------------------------------------------------------------------------
320 
321 // Macro initializers for Read-Only Elements in Flash/PROGMEM
322 //
323 
324 
325 
326 #ifdef __cplusplus
327 }
328 #endif // __cplusplus
329 #endif // _GUISLICE_EX_XLISTBOX_H_
330 
int8_t nRows
Number of columns (or XLSITBOX_SIZE_AUTO to calculate)
Definition: XListbox.h:77
bool gslc_ElemXListboxTouch(void *pvGui, void *pvElemRef, gslc_teTouch eTouch, int16_t nRelX, int16_t nRelY)
Handle touch events to Listbox element.
Definition: XListbox.c:718
int16_t nItemSavedSel
Persistent selected item (ie. saved selection)
Definition: XListbox.h:91
void gslc_ElemXListboxReset(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef)
Empty the listbox of all items.
Definition: XListbox.c:236
bool gslc_ElemXListboxAddItem(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, const char *pStrItem)
Add an item to the listbox.
Definition: XListbox.c:250
int16_t nItemTop
Item to show at top of list after scrolling (0 is default)
Definition: XListbox.h:92
uint16_t nBufItemsMax
Max size of buffer containing items.
Definition: XListbox.h:71
gslc_teRedrawType
Redraw types.
Definition: GUIslice.h:370
int16_t gslc_ElemXListboxGetItemCnt(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef)
Get the number of items in the listbox.
Definition: XListbox.c:464
int16_t nItemW
Width of listbox item.
Definition: XListbox.h:81
int16_t nItemH
Height of listbox item.
Definition: XListbox.h:82
void gslc_ElemXListboxSetSelFunc(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, GSLC_CB_XLISTBOX_SEL funcCb)
Assign the selection callback function for a Listbox.
Definition: XListbox.c:1015
bool gslc_ElemXListboxSetScrollPos(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, uint16_t nScrollPos)
Set the Listbox scroll position.
Definition: XListbox.c:983
bool gslc_ElemXListboxDraw(void *pvGui, void *pvElemRef, gslc_teRedrawType eRedraw)
Draw a Listbox element on the screen.
Definition: XListbox.c:551
bool(* GSLC_CB_XLISTBOX_SEL)(void *pvGui, void *pvElem, int16_t nSel)
Callback function for Listbox feedback.
Definition: XListbox.h:60
uint8_t * pBufItems
Buffer containing items.
Definition: XListbox.h:70
GSLC_CB_XLISTBOX_SEL pfuncXSel
Callback func ptr for selection update.
Definition: XListbox.h:96
int8_t nMarginH
Margin inside main listbox area (Y offset)
Definition: XListbox.h:80
gslc_tsColor colGap
Gap color.
Definition: XListbox.h:84
bool gslc_ElemXListboxGetItem(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int16_t nItemCurSel, char *pStrItem, uint8_t nStrItemLen)
Get the indexed listbox item.
Definition: XListbox.c:424
void gslc_ElemXListboxItemsSetSize(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int16_t nItemW, int16_t nItemH)
Configure the size of the listbox items.
Definition: XListbox.c:207
bool bItemAutoSizeH
Enable auto-sizing of items (in height)
Definition: XListbox.h:86
bool gslc_ElemXListboxDeleteItemAt(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, uint16_t nDeletePos)
Insert an item in the listbox at a specific position.
Definition: XListbox.c:371
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
void gslc_ElemXListboxSetMargin(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int8_t nMarginW, int8_t nMarginH)
Configure the margin inside the listbox.
Definition: XListbox.c:194
int16_t nItemCurSel
Currently selected item (XLISTBOX_SEL_NONE for none)
Definition: XListbox.h:89
int8_t nMarginW
Margin inside main listbox area (X offset)
Definition: XListbox.h:79
int8_t nItemGap
Gap between listbox items.
Definition: XListbox.h:83
int8_t nCols
Number of columns.
Definition: XListbox.h:76
void gslc_ElemXListboxSetSize(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int8_t nRows, int8_t nCols)
Configure the number of rows & columns to display in the listbox.
Definition: XListbox.c:180
Element reference structure.
Definition: GUIslice.h:578
gslc_tsElemRef * gslc_ElemXListboxCreate(gslc_tsGui *pGui, int16_t nElemId, int16_t nPage, gslc_tsXListbox *pXData, gslc_tsRect rElem, int16_t nFontId, uint8_t *pBufItems, uint16_t nBufItemsMax, int16_t nSelDefault)
Create a Listbox Element.
Definition: XListbox.c:476
int16_t nItemCurSelLast
Old selected item to redraw (XLISTBOX_SEL_NONE for none)
Definition: XListbox.h:90
bool gslc_ElemXListboxInsertItemAt(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, uint16_t nInsertPos, const char *pStrItem)
Insert an item in the listbox at a specific position.
Definition: XListbox.c:297
bool bGlowLast
Last glow state.
Definition: XListbox.h:93
void gslc_ElemXListboxItemsSetGap(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int8_t nGap, gslc_tsColor colGap)
Configure the gap between listbox items.
Definition: XListbox.c:223
uint16_t nBufItemsPos
Current buffer position.
Definition: XListbox.h:72
int16_t nItemCnt
Number of items in the list.
Definition: XListbox.h:73
gslc_teTouch
Processed event from input raw events and actions.
Definition: GUIslice.h:305
int16_t gslc_ElemXListboxGetSel(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef)
Get a Listbox element's current selection.
Definition: XListbox.c:941
GUI structure.
Definition: GUIslice.h:716
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534
bool gslc_ElemXListboxSetSel(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int16_t nItemCurSel)
Set a Listbox element's current selection.
Definition: XListbox.c:949
Extended data for Listbox element.
Definition: XListbox.h:67
bool bNeedRecalc
Determine if sizing may need recalc.
Definition: XListbox.h:78
bool bItemAutoSizeW
Enable auto-sizing of items (in width)
Definition: XListbox.h:85