tcMenu
ScrollChoiceMenuItem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 https://www.thecoderscorner.com (Nutricherry LTD).
3  * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4  */
5 
10 #ifndef SCROLL_CHOICE_ENUM_MENU_ITEM_H
11 #define SCROLL_CHOICE_ENUM_MENU_ITEM_H
12 
13 #include <PlatformDetermination.h>
14 #include "RuntimeMenuItem.h"
15 #include <EepromAbstraction.h>
16 
18 int enumItemRenderFn(RuntimeMenuItem *item, uint8_t row, RenderFnMode mode, char *buffer, int bufferSize);
19 
34 public:
35  enum EnumMemMode : uint8_t {
36  MEMORY_ONLY, EEPROM_BASED, CUSTOM
37  };
38 private:
39  EepromPosition eepromStart;
40  const char *rangeValues;
41  uint8_t itemSize;
42  uint8_t lastCacheSize;
43  EnumMemMode memMode;
44 public:
56  ScrollChoiceMenuItem(int id, RuntimeRenderingFn renderFn, uint8_t currentSel, const char *enumItemsInRam,
57  int itemSize, int numberOfItems, MenuItem *next = nullptr);
58 
74  ScrollChoiceMenuItem(uint16_t id, RuntimeRenderingFn renderFn, uint8_t currentSel, EepromPosition eepromStart,
75  int itemSize, int numberOfItems, MenuItem *next = nullptr);
76 
87  ScrollChoiceMenuItem(uint16_t id, RuntimeRenderingFn renderFn, uint8_t currentSel, int numberOfItems, MenuItem *next = nullptr);
88 
92  void cacheEepromValues();
93 
100  void valueAtPosition(char *buffer, size_t bufferSize, int idx);
101 
107  void setCurrentValue(int val, bool silent = false);
108 
109  int getEepromStart() const { return eepromStart; }
110 
111  int getItemWidth() const { return itemSize; }
112 
113  EnumMemMode getMemMode() const { return memMode; }
114 
118  int getCurrentValue() { return itemPosition; }
119 
120  void copyTransportText(char *string, size_t i);
121 
122  void setFromRemote(const char* buffer);
123 };
124 
130 uint8_t hexValueOf(char val);
131 
137 struct RgbColor32 {
138 public:
139  uint8_t red;
140  uint8_t green;
141  uint8_t blue;
142  uint8_t alpha;
143 
144  RgbColor32() {
145  red = green = blue = alpha = 0;
146  }
147 
148  RgbColor32(int r, int g, int b, int a = 255) {
149  red = r;
150  green = g;
151  blue = b;
152  alpha = a;
153  }
154 
155  RgbColor32(const RgbColor32& other) {
156  red = other.red;
157  green = other.green;
158  blue = other.blue;
159  alpha = other.alpha;
160  }
161 
162  RgbColor32& operator = (const RgbColor32& other) = default;
163 
164  explicit RgbColor32(const char* htmlColor);
165 
166  void asHtmlString(char *buffer, size_t bufferSize, bool withAlpha) const;
167 };
168 
170 int rgbAlphaItemRenderFn(RuntimeMenuItem *item, uint8_t row, RenderFnMode mode, char *buffer, int bufferSize);
171 
177 private:
178  RgbColor32 data;
179  bool alphaChannel;
180 public:
181 
189  Rgb32MenuItem(uint16_t id, RuntimeRenderingFn renderFn, bool includeAlpha, MenuItem* next = nullptr);
190 
194  RgbColor32* getUnderlying() { return &data; }
195 
199  RgbColor32 getColorData() { return data; }
204  void setColorData(const RgbColor32& other) {
205  data = other;
206  changeOccurred(false);
207  }
208 
212  bool isAlphaInUse() const { return alphaChannel; }
213 };
214 
215 #endif //SCROLL_CHOICE_ENUM_MENU_ITEM_H
RenderFnMode
Definition: MenuItems.h:287
Definition: MenuItems.h:329
bool isAlphaInUse() const
Definition: ScrollChoiceMenuItem.h:212
void cacheEepromValues()
Definition: ScrollChoiceMenuItem.cpp:41
void setCurrentValue(int val, bool silent=false)
Definition: ScrollChoiceMenuItem.cpp:52
void valueAtPosition(char *buffer, size_t bufferSize, int idx)
Definition: ScrollChoiceMenuItem.cpp:60
Definition: ScrollChoiceMenuItem.h:33
int getCurrentValue()
Definition: ScrollChoiceMenuItem.h:118
int rgbAlphaItemRenderFn(RuntimeMenuItem *item, uint8_t row, RenderFnMode mode, char *buffer, int bufferSize)
Definition: ScrollChoiceMenuItem.cpp:189
void changeOccurred(bool silent)
Definition: MenuItems.cpp:92
Definition: ScrollChoiceMenuItem.h:137
Definition: RuntimeMenuItem.h:201
ScrollChoiceMenuItem(int id, RuntimeRenderingFn renderFn, uint8_t currentSel, const char *enumItemsInRam, int itemSize, int numberOfItems, MenuItem *next=nullptr)
Definition: ScrollChoiceMenuItem.cpp:10
Definition: RuntimeMenuItem.h:73
RgbColor32 * getUnderlying()
Definition: ScrollChoiceMenuItem.h:194
void setColorData(const RgbColor32 &other)
Definition: ScrollChoiceMenuItem.h:204
int enumItemRenderFn(RuntimeMenuItem *item, uint8_t row, RenderFnMode mode, char *buffer, int bufferSize)
Definition: ScrollChoiceMenuItem.cpp:107
uint8_t hexValueOf(char val)
Definition: ScrollChoiceMenuItem.cpp:131
int(* RuntimeRenderingFn)(RuntimeMenuItem *item, uint8_t row, RenderFnMode mode, char *buffer, int bufferSize)
Definition: MenuItems.h:318
Definition: ScrollChoiceMenuItem.h:176
RgbColor32 getColorData()
Definition: ScrollChoiceMenuItem.h:199