tcMenu
ScrollChoiceMenuItem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3  * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4  */
5 
11 #ifndef SCROLL_CHOICE_ENUM_MENU_ITEM_H
12 #define SCROLL_CHOICE_ENUM_MENU_ITEM_H
13 
14 #include <PlatformDetermination.h>
15 #include "RuntimeMenuItem.h"
16 #include <EepromAbstraction.h>
17 
19 int enumItemRenderFn(RuntimeMenuItem *item, uint8_t row, RenderFnMode mode, char *buffer, int bufferSize);
20 
35 public:
36  enum EnumMemMode : uint8_t {
37  MEMORY_ONLY, EEPROM_BASED, CUSTOM
38  };
39 private:
40  EepromPosition eepromStart;
41  const char *rangeValues;
42  uint8_t itemSize;
43  uint8_t lastCacheSize;
44  EnumMemMode memMode;
45 public:
57  ScrollChoiceMenuItem(int id, RuntimeRenderingFn renderFn, uint8_t currentSel, const char *enumItemsInRam,
58  int itemSize, int numberOfItems, MenuItem *next = nullptr);
59 
75  ScrollChoiceMenuItem(uint16_t id, RuntimeRenderingFn renderFn, uint8_t currentSel, EepromPosition eepromStart,
76  int itemSize, int numberOfItems, MenuItem *next = nullptr);
77 
88  ScrollChoiceMenuItem(uint16_t id, RuntimeRenderingFn renderFn, uint8_t currentSel, int numberOfItems, MenuItem *next = nullptr);
89 
101  ScrollChoiceMenuItem(const AnyMenuInfo* info, uint8_t currentSel, const char *enumItemsInRam,
102  int itemSize, int numberOfItems, MenuItem *next = nullptr, bool isPgm = INFO_LOCATION_PGM);
103 
119  ScrollChoiceMenuItem(const AnyMenuInfo* info, uint8_t currentSel, EepromPosition eepromStart,
120  int itemSize, int numberOfItems, MenuItem *next = nullptr, bool isPgm = INFO_LOCATION_PGM);
121 
133  ScrollChoiceMenuItem(const AnyMenuInfo* info, RuntimeRenderingFn renderFn, uint8_t currentSel, int numberOfItems, MenuItem *next = nullptr, bool isPgm = INFO_LOCATION_PGM);
134 
138  void cacheEepromValues();
139 
146  void valueAtPosition(char *buffer, size_t bufferSize, int idx);
147 
153  void setCurrentValue(int val, bool silent = false);
154 
155  int getEepromStart() const { return eepromStart; }
156 
157  int getItemWidth() const { return itemSize; }
158 
159  EnumMemMode getMemMode() const { return memMode; }
160 
164  int getCurrentValue() { return itemPosition; }
165 
166  void copyTransportText(char *string, size_t i);
167 
168  void setFromRemote(const char* buffer);
169 };
170 
176 uint8_t hexValueOf(char val);
177 
183 struct RgbColor32 {
184 public:
185  uint8_t red;
186  uint8_t green;
187  uint8_t blue;
188  uint8_t alpha;
189 
190  RgbColor32() {
191  red = green = blue = alpha = 0;
192  }
193 
194  RgbColor32(int r, int g, int b, int a = 255) {
195  red = r;
196  green = g;
197  blue = b;
198  alpha = a;
199  }
200 
201  RgbColor32(const RgbColor32& other) {
202  red = other.red;
203  green = other.green;
204  blue = other.blue;
205  alpha = other.alpha;
206  }
207 
208  RgbColor32& operator = (const RgbColor32& other) = default;
209 
210  explicit RgbColor32(const char* htmlColor);
211 
212  void asHtmlString(char *buffer, size_t bufferSize, bool withAlpha) const;
213 };
214 
216 int rgbAlphaItemRenderFn(RuntimeMenuItem *item, uint8_t row, RenderFnMode mode, char *buffer, int bufferSize);
217 
222 enum RgbPrintMode { DECIMAL, HEX_HTML };
223 
230  RgbColor32 data;
231  bool alphaChannel;
232  static RgbPrintMode printMode;
233 public:
234 
243  Rgb32MenuItem(RuntimeRenderingFn renderFn, const RgbColor32& col, uint16_t id, bool includeAlpha, MenuItem *next = nullptr);
244 
252  Rgb32MenuItem(uint16_t id, RuntimeRenderingFn renderFn, bool includeAlpha, MenuItem* next = nullptr);
253 
254 
265  Rgb32MenuItem(const AnyMenuInfo* info, RuntimeRenderingFn renderFn, const RgbColor32& col, bool includeAlpha, MenuItem *next = nullptr, bool isPgm = INFO_LOCATION_PGM);
266 
276  Rgb32MenuItem(const AnyMenuInfo* info, const RgbColor32& col, bool includeAlpha, MenuItem *next = nullptr, bool isPgm = INFO_LOCATION_PGM);
277 
278 
282  RgbColor32* getUnderlying() { return &data; }
283 
287  RgbColor32 getColorData() { return data; }
292  void setColorData(const RgbColor32& other) {
293  data = other;
294  changeOccurred(false);
295  }
296 
300  bool isAlphaInUse() const { return alphaChannel; }
301 
302  static void setRgbPrintMode(RgbPrintMode mode) { printMode = mode; }
303  static RgbPrintMode getRgbPrintMode() { return printMode; }
304 };
305 
306 #endif //SCROLL_CHOICE_ENUM_MENU_ITEM_H
RenderFnMode
Definition: MenuItems.h:283
int(* RuntimeRenderingFn)(RuntimeMenuItem *item, uint8_t row, RenderFnMode mode, char *buffer, int bufferSize)
Definition: MenuItems.h:318
Definition: MenuItems.h:51
Contains definitions of menu items that can be fully defined at runtime with no need for prog mem str...
uint8_t hexValueOf(char val)
int enumItemRenderFn(RuntimeMenuItem *item, uint8_t row, RenderFnMode mode, char *buffer, int bufferSize)
Definition: ScrollChoiceMenuItem.cpp:137
RgbPrintMode
Definition: ScrollChoiceMenuItem.h:222
int rgbAlphaItemRenderFn(RuntimeMenuItem *item, uint8_t row, RenderFnMode mode, char *buffer, int bufferSize)
Definition: ScrollChoiceMenuItem.cpp:256
Definition: RuntimeMenuItem.h:228
Definition: MenuItems.h:329
void changeOccurred(bool silent)
Definition: MenuItems.cpp:99
const AnyMenuInfo * info
Definition: MenuItems.h:334
Definition: ScrollChoiceMenuItem.h:229
void setColorData(const RgbColor32 &other)
Definition: ScrollChoiceMenuItem.h:292
bool isAlphaInUse() const
Definition: ScrollChoiceMenuItem.h:300
RgbColor32 * getUnderlying()
Definition: ScrollChoiceMenuItem.h:282
RgbColor32 getColorData()
Definition: ScrollChoiceMenuItem.h:287
Rgb32MenuItem(RuntimeRenderingFn renderFn, const RgbColor32 &col, uint16_t id, bool includeAlpha, MenuItem *next=nullptr)
Definition: ScrollChoiceMenuItem.cpp:161
Definition: RuntimeMenuItem.h:73
Definition: ScrollChoiceMenuItem.h:34
void valueAtPosition(char *buffer, size_t bufferSize, int idx)
Definition: ScrollChoiceMenuItem.cpp:92
void cacheEepromValues()
Definition: ScrollChoiceMenuItem.cpp:73
void setCurrentValue(int val, bool silent=false)
Definition: ScrollChoiceMenuItem.cpp:84
ScrollChoiceMenuItem(int id, RuntimeRenderingFn renderFn, uint8_t currentSel, const char *enumItemsInRam, int itemSize, int numberOfItems, MenuItem *next=nullptr)
Definition: ScrollChoiceMenuItem.cpp:11
int getCurrentValue()
Definition: ScrollChoiceMenuItem.h:164
Definition: ScrollChoiceMenuItem.h:183