GUIslice  0.16.0
Embedded GUI in C
XTextbox.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_EX_XTEXTBOX_H_
2 #define _GUISLICE_EX_XTEXTBOX_H_
3 
4 #include "GUIslice.h"
5 
6 
7 // =======================================================================
8 // GUIslice library extension: Textbox 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 // ============================================================================
46 // Extended Element: Textbox
47 // ============================================================================
48 
49 // Define unique identifier for extended element type
50 // - Select any number above GSLC_TYPE_BASE_EXTEND
51 #define GSLC_TYPEX_TEXTBOX GSLC_TYPE_BASE_EXTEND + 4
52 
54 #define GSLC_XTEXTBOX_CODE_COL_SET 187
55 #define GSLC_XTEXTBOX_CODE_COL_RESET 188
56 
57 #define XTEXTBOX_REDRAW_NONE -1
58 #define XTEXTBOX_REDRAW_ALL -2
59 
60 // Extended element data structures
61 // - These data structures are maintained in the gslc_tsElem
62 // structure via the pXData pointer
63 
65 typedef struct {
66  // Config
67  char* pBuf;
68  int8_t nMarginX;
69  int8_t nMarginY;
70  bool bWrapEn;
71 
72  uint16_t nBufRows;
73  uint16_t nBufCols;
74  bool bScrollEn;
75  uint16_t nScrollPos;
76 
77  // Precalculated params
78  uint8_t nChSizeX;
79  uint8_t nChSizeY;
80  uint8_t nWndCols;
81  uint8_t nWndRows;
82  // Current status
83  uint8_t nCurPosX;
84  uint8_t nCurPosY;
85  uint8_t nBufPosX;
86  uint8_t nBufPosY;
87  uint8_t nWndRowStart;
88  // Redraw
89  int16_t nRedrawRow;
90 
92 
93 
94 
117 gslc_tsElemRef* gslc_ElemXTextboxCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t nPage,
118  gslc_tsXTextbox* pXData,gslc_tsRect rElem,int16_t nFontId,char* pBuf,
119  uint16_t nBufRows,uint16_t nBufCols);
120 
121 
130 void gslc_ElemXTextboxReset(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef);
131 
132 
143 bool gslc_ElemXTextboxDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
144 
157 void gslc_ElemXTextboxAdd(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,char* pTxt);
158 
169 
179 
189 void gslc_ElemXTextboxWrapSet(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,bool bWrapEn);
190 
191 
203 void gslc_ElemXTextboxScrollSet(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,uint8_t nScrollPos,uint8_t nScrollMax);
204 
205 
206 
207 
208 // ============================================================================
209 
210 // ------------------------------------------------------------------------
211 // Read-only element macros
212 // ------------------------------------------------------------------------
213 
214 // Macro initializers for Read-Only Elements in Flash/PROGMEM
215 //
216 
217 #ifdef __cplusplus
218 }
219 #endif // __cplusplus
220 #endif // _GUISLICE_EX_XTEXTBOX_H_
221 
int8_t nMarginX
Margin for text area within element rect (X)
Definition: XTextbox.h:68
uint8_t nChSizeY
Height of characters (pixels)
Definition: XTextbox.h:79
int8_t nMarginY
Margin for text area within element rect (Y)
Definition: XTextbox.h:69
gslc_teRedrawType
Redraw types.
Definition: GUIslice.h:370
gslc_tsElemRef * gslc_ElemXTextboxCreate(gslc_tsGui *pGui, int16_t nElemId, int16_t nPage, gslc_tsXTextbox *pXData, gslc_tsRect rElem, int16_t nFontId, char *pBuf, uint16_t nBufRows, uint16_t nBufCols)
Create a Textbox Element.
Definition: XTextbox.c:71
bool bWrapEn
Enable for line wrapping.
Definition: XTextbox.h:70
Extended data for Textbox element.
Definition: XTextbox.h:65
void gslc_ElemXTextboxAdd(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, char *pTxt)
Add a text string to the textbox.
Definition: XTextbox.c:383
uint8_t nBufPosY
Buffer Y position.
Definition: XTextbox.h:86
bool bScrollEn
Enable for scrollbar.
Definition: XTextbox.h:74
bool gslc_ElemXTextboxDraw(void *pvGui, void *pvElemRef, gslc_teRedrawType eRedraw)
Draw a Textbox element on the screen.
Definition: XTextbox.c:441
void gslc_ElemXTextboxScrollSet(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, uint8_t nScrollPos, uint8_t nScrollMax)
Set the textbox scroll position (nScrollPos) as a fraction of nScrollMax.
Definition: XTextbox.c:228
void gslc_ElemXTextboxReset(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef)
Reset the contents of the textbox.
Definition: XTextbox.c:171
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
uint8_t nChSizeX
Width of characters (pixels)
Definition: XTextbox.h:78
void gslc_ElemXTextboxWrapSet(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, bool bWrapEn)
Enable or disable line wrap within textbox.
Definition: XTextbox.c:374
uint16_t nBufCols
Number of columns in buffer.
Definition: XTextbox.h:73
uint8_t nCurPosY
Cursor Y position.
Definition: XTextbox.h:84
char * pBuf
Ptr to the text buffer (circular buffer))
Definition: XTextbox.h:67
Element reference structure.
Definition: GUIslice.h:578
uint8_t nBufPosX
Buffer X position.
Definition: XTextbox.h:85
uint8_t nWndRowStart
First row of current window.
Definition: XTextbox.h:87
void gslc_ElemXTextboxColReset(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef)
Insert a color reset code into the current buffer position.
Definition: XTextbox.c:358
void gslc_ElemXTextboxColSet(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, gslc_tsColor nCol)
Insert a color set code into the current buffer position.
Definition: XTextbox.c:330
uint8_t nCurPosX
Cursor X position.
Definition: XTextbox.h:83
GUI structure.
Definition: GUIslice.h:716
uint8_t nWndRows
Window Y size.
Definition: XTextbox.h:81
uint8_t nWndCols
Window X size.
Definition: XTextbox.h:80
uint16_t nScrollPos
Current scrollbar position.
Definition: XTextbox.h:75
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534
uint16_t nBufRows
Number of rows in buffer.
Definition: XTextbox.h:72
int16_t nRedrawRow
Specific row to update in redraw (if not -1)
Definition: XTextbox.h:89