FabGL
ESP32 Display Controller and Graphics Library
inputbox.h
Go to the documentation of this file.
1 /*
2  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3  Copyright (c) 2019-2021 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6 
7 * Please contact fdivitto2013@gmail.com if you need a commercial license.
8 
9 
10 * This library and related software is available under GPL v3. Feel free to use FabGL in free software and hardware:
11 
12  FabGL is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  FabGL is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 
27 #pragma once
28 
29 
38 #include <stdint.h>
39 #include <stddef.h>
40 
41 #include "fabglconf.h"
42 #include "fabui.h"
43 #include "fabutils.h"
46 
47 
48 
49 namespace fabgl {
50 
51 
52 
56 enum class InputResult {
57  None,
58  Cancel,
59  Enter,
60 };
61 
62 
63 
65 // InputApp
66 
67 
68 struct InputApp : public uiApp {
69  virtual void init();
70  virtual void addControls() = 0;
71  virtual void calcRequiredSize() = 0;
72  virtual void finalize() = 0;
73 
74  RGB888 backgroundColor;
75  char const * titleText;
76  char const * buttonCancelText;
77  char const * buttonOKText;
78  InputResult retval;
79  int autoOK;
80 
81  FontInfo const * font;
82  int requiredWidth;
83  int requiredHeight;
84 
85  uiFrame * mainFrame;
86  uiPanel * panel;
87  uiLabel * autoOKLabel;
88 };
89 
90 
91 
93 // TextInputApp
94 
95 
96 struct TextInputApp : public InputApp {
97  void addControls();
98  void calcRequiredSize();
99  void finalize();
100 
101  char const * labelText;
102  char * inOutString;
103  int maxLength;
104  bool passwordMode;
105 
106  int editExtent;
107  int labelExtent;
108 
109  uiTextEdit * edit;
110 };
111 
112 
113 
115 // MessageApp
116 
117 
118 struct MessageApp : public InputApp {
119  void addControls();
120  void calcRequiredSize();
121  void finalize();
122 
123  char const * messageText;
124 
125  int messageExtent;
126 };
127 
128 
129 
131 // SelectApp
132 
133 
134 struct SelectApp : public InputApp {
135  void addControls();
136  void calcRequiredSize();
137  void finalize();
138 
139  int countItems(size_t * maxLength);
140 
141  char const * messageText;
142  char const * items; // "separator" separated items (zero ends the list)
143  char separator;
144  StringList * itemsList;
145  bool menuMode;
146 
147  int listBoxHeight;
148  int outSelected;
149 
150  uiListBox * listBox;
151 };
152 
153 
154 
156 // ProgressApp
157 
158 
159 struct ProgressApp : public InputApp {
160  void addControls();
161  void calcRequiredSize();
162  void finalize();
163 
164  bool update(int percentage, char const * format, ...);
165 
166  static const int progressBarHeight = 16;
167 
168  bool hasProgressBar;
169  Delegate<ProgressApp*> execFunc;
170  int width;
171 
172  uiLabel * label;
173  uiProgressBar * progressBar;
174 };
175 
176 
177 
179 // InputBox
180 
181 
183 class InputBox {
184 
185 public:
186 
190  InputBox();
191 
192  ~InputBox();
193 
201  void begin(char const * modeline = nullptr, int viewPortWidth = -1, int viewPortHeight = -1);
202 
208  void begin(BitmappedDisplayController * displayController);
209 
213  void end();
214 
220  void setBackgroundColor(RGB888 const & value) { m_backgroundColor = value; }
221 
247  InputResult textInput(char const * titleText, char const * labelText, char * inOutString, int maxLength, char const * buttonCancelText = "Cancel", char const * buttonOKText = "OK", bool passwordMode = false);
248 
271  InputResult message(char const * titleText, char const * messageText, char const * buttonCancelText = nullptr, char const * buttonOKText = "OK");
272 
293  InputResult messageFmt(char const * titleText, char const * buttonCancelText, char const * buttonOKText, const char *format, ...);
294 
316  int select(char const * titleText, char const * messageText, char const * itemsText, char separator = ';', char const * buttonCancelText = "Cancel", char const * buttonOKText = "OK", int OKAfter = 0);
317 
347  InputResult select(char const * titleText, char const * messageText, StringList * items, char const * buttonCancelText = "Cancel", char const * buttonOKText = "OK", int OKAfter = 0);
348 
367  int menu(char const * titleText, char const * messageText, char const * itemsText, char separator = ';');
368 
391  int menu(char const * titleText, char const * messageText, StringList * items);
392 
419  template <typename Func> InputResult progressBox(char const * titleText, char const * buttonCancelText, bool hasProgressBar, int width, Func execFunc) {
420  ProgressApp app;
421  app.execFunc = execFunc;
422  return progressBoxImpl(app, titleText, buttonCancelText, hasProgressBar, width);
423  }
424 
425 private:
426 
427  InputResult progressBoxImpl(ProgressApp & app, char const * titleText, char const * buttonCancelText, bool hasProgressBar, int width);
428 
429  BitmappedDisplayController * m_dispCtrl;
430  VGA16Controller * m_vga16Ctrl;
431  RGB888 m_backgroundColor;
432 };
433 
434 
435 
436 } // namespace fabgl
Represents a 24 bit RGB color.
void begin(char const *modeline=nullptr, int viewPortWidth=-1, int viewPortHeight=-1)
Initializes InputBox from VGA modeline, using a VGA16Controller.
Definition: inputbox.cpp:55
This file contains fabgl::PS2Controller definition.
void setBackgroundColor(RGB888 const &value)
Sets the background color.
Definition: inputbox.h:220
This file contains fabgl::VGA16Controller definition.
This file contains all classes related to FabGL Graphical User Interface.
int select(char const *titleText, char const *messageText, char const *itemsText, char separator=';', char const *buttonCancelText="Cancel", char const *buttonOKText="OK", int OKAfter=0)
Shows a dialog with a label and a list box.
Definition: inputbox.cpp:138
void end()
Cleanup resources and eventually disable VGA output.
Definition: inputbox.cpp:75
InputBox()
Creates a new InputBox instance.
Definition: inputbox.cpp:42
Represents the base abstract class for bitmapped display controllers.
InputBox is an helper class which allows to create simple UI interfaces, like wizards or simple input...
Definition: inputbox.h:183
InputResult
Result of InputBox dialogs helper class.
Definition: inputbox.h:56
This file contains some utility classes and functions.
Definition: canvas.cpp:36
Represents the VGA 16 colors bitmapped controller.
InputResult progressBox(char const *titleText, char const *buttonCancelText, bool hasProgressBar, int width, Func execFunc)
Shows a dialog with a label and a progress bar, updated dynamically by a user function.
Definition: inputbox.h:419
This file contains FabGL library configuration settings, like number of supported colors...
InputResult textInput(char const *titleText, char const *labelText, char *inOutString, int maxLength, char const *buttonCancelText="Cancel", char const *buttonOKText="OK", bool passwordMode=false)
Shows a dialog with a label and a text edit box.
Definition: inputbox.cpp:85
int menu(char const *titleText, char const *messageText, char const *itemsText, char separator=';')
Shows a dialog with a label and a list box. The dialog exits when an item is selected, just like a menu.
Definition: inputbox.cpp:178
InputResult message(char const *titleText, char const *messageText, char const *buttonCancelText=nullptr, char const *buttonOKText="OK")
Shows a dialog with just a label.
Definition: inputbox.cpp:104
uint8_t width
InputResult messageFmt(char const *titleText, char const *buttonCancelText, char const *buttonOKText, const char *format,...)
Shows a dialog with a just a label. Allows printf like formatted text.
Definition: inputbox.cpp:120