|
@@ -42,7 +42,7 @@ bool printer_busy();
|
42
|
42
|
////////////////////////////////////////////
|
43
|
43
|
|
44
|
44
|
#define DECLARE_MENU_EDIT_TYPE(TYPE, NAME, STRFUNC, SCALE) \
|
45
|
|
- struct MenuItemInfo_##NAME { \
|
|
45
|
+ struct MenuEditItemInfo_##NAME { \
|
46
|
46
|
typedef TYPE type_t; \
|
47
|
47
|
static constexpr float scale = SCALE; \
|
48
|
48
|
static inline char* strfunc(const float value) { return STRFUNC((TYPE) value); } \
|
|
@@ -111,14 +111,14 @@ FORCE_INLINE void draw_menu_item_edit_P(const bool sel, const uint8_t row, PGM_P
|
111
|
111
|
////////////////////////////////////////////
|
112
|
112
|
|
113
|
113
|
#define _DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(TYPE, NAME, STRFUNC) \
|
114
|
|
- FORCE_INLINE void draw_menu_item_edit_##NAME (const bool sel, const uint8_t row, PGM_P const pstr, TYPE * const data, ...) { \
|
|
114
|
+ FORCE_INLINE void draw_menu_item_##NAME (const bool sel, const uint8_t row, PGM_P const pstr, TYPE * const data, ...) { \
|
115
|
115
|
DRAW_MENU_ITEM_SETTING_EDIT_GENERIC(STRFUNC(*(data))); \
|
116
|
116
|
} \
|
117
|
|
- FORCE_INLINE void draw_menu_item_edit_accessor_##NAME (const bool sel, const uint8_t row, PGM_P const pstr, PGM_P const, TYPE (*pget)(), void (*)(TYPE), ...) { \
|
|
117
|
+ FORCE_INLINE void draw_menu_item_accessor_##NAME (const bool sel, const uint8_t row, PGM_P const pstr, PGM_P const, TYPE (*pget)(), void (*)(TYPE), ...) { \
|
118
|
118
|
DRAW_MENU_ITEM_SETTING_EDIT_GENERIC(STRFUNC(pget())); \
|
119
|
119
|
} \
|
120
|
120
|
typedef void NAME##_void
|
121
|
|
-#define DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(NAME) _DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(MenuItemInfo_##NAME::type_t, NAME, MenuItemInfo_##NAME::strfunc)
|
|
121
|
+#define DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(NAME) _DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(MenuEditItemInfo_##NAME::type_t, NAME, MenuEditItemInfo_##NAME::strfunc)
|
122
|
122
|
|
123
|
123
|
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(percent); // 100% right-justified
|
124
|
124
|
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int3); // 123, -12 right-justified
|
|
@@ -139,8 +139,8 @@ DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52sign); // +123.45
|
139
|
139
|
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5); // 12345 right-justified
|
140
|
140
|
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5_25); // 12345 right-justified (25 increment)
|
141
|
141
|
|
142
|
|
-#define draw_menu_item_edit_bool(sel, row, pstr, data, ...) DRAW_BOOL_SETTING(sel, row, pstr, data)
|
143
|
|
-#define draw_menu_item_edit_accessor_bool(sel, row, pstr, pget, pset) DRAW_BOOL_SETTING(sel, row, pstr, data)
|
|
142
|
+#define draw_menu_item_bool(sel, row, pstr, data, ...) DRAW_BOOL_SETTING(sel, row, pstr, data)
|
|
143
|
+#define draw_menu_item_accessor_bool(sel, row, pstr, pget, pset) DRAW_BOOL_SETTING(sel, row, pstr, data)
|
144
|
144
|
|
145
|
145
|
////////////////////////////////////////////
|
146
|
146
|
/////////////// Menu Actions ///////////////
|
|
@@ -176,11 +176,12 @@ class MenuItem_function {
|
176
|
176
|
/////////// Menu Editing Actions ///////////
|
177
|
177
|
////////////////////////////////////////////
|
178
|
178
|
|
179
|
|
-class MenuItemBase {
|
|
179
|
+// Edit items use long integer encoder units
|
|
180
|
+class MenuEditItemBase {
|
180
|
181
|
private:
|
181
|
182
|
static PGM_P editLabel;
|
182
|
183
|
static void *editValue;
|
183
|
|
- static int32_t minEditValue, maxEditValue;
|
|
184
|
+ static int32_t minEditValue, maxEditValue; // Encoder value range
|
184
|
185
|
static screenFunc_t callbackFunc;
|
185
|
186
|
static bool liveEdit;
|
186
|
187
|
protected:
|
|
@@ -191,7 +192,7 @@ class MenuItemBase {
|
191
|
192
|
};
|
192
|
193
|
|
193
|
194
|
template<typename NAME>
|
194
|
|
-class TMenuItem : MenuItemBase {
|
|
195
|
+class TMenuEditItem : MenuEditItemBase {
|
195
|
196
|
private:
|
196
|
197
|
typedef typename NAME::type_t type_t;
|
197
|
198
|
static inline float unscale(const float value) { return value * (1.0f / NAME::scale); }
|
|
@@ -199,16 +200,23 @@ class TMenuItem : MenuItemBase {
|
199
|
200
|
static void load(void *ptr, const int32_t value) { *((type_t*)ptr) = unscale(value); }
|
200
|
201
|
static char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
|
201
|
202
|
public:
|
202
|
|
- static void action_edit(PGM_P const pstr, type_t * const ptr, const type_t minValue, const type_t maxValue, const screenFunc_t callback=nullptr, const bool live=false) {
|
203
|
|
- // Make sure minv and maxv fit within int16_t
|
204
|
|
- const int32_t minv = _MAX(scale(minValue), INT16_MIN),
|
205
|
|
- maxv = _MIN(scale(maxValue), INT16_MAX);
|
|
203
|
+ static void action(
|
|
204
|
+ PGM_P const pstr, // Edit label
|
|
205
|
+ type_t * const ptr, // Value pointer
|
|
206
|
+ const type_t minValue, // Value range
|
|
207
|
+ const type_t maxValue,
|
|
208
|
+ const screenFunc_t callback=nullptr, // Value update callback
|
|
209
|
+ const bool live=false // Callback during editing
|
|
210
|
+ ) {
|
|
211
|
+ // Make sure minv and maxv fit within int32_t
|
|
212
|
+ const int32_t minv = _MAX(scale(minValue), INT32_MIN),
|
|
213
|
+ maxv = _MIN(scale(maxValue), INT32_MAX);
|
206
|
214
|
init(pstr, ptr, minv, maxv - minv, scale(*ptr) - minv, edit, callback, live);
|
207
|
215
|
}
|
208
|
|
- static void edit() { MenuItemBase::edit(to_string, load); }
|
|
216
|
+ static void edit() { MenuEditItemBase::edit(to_string, load); }
|
209
|
217
|
};
|
210
|
218
|
|
211
|
|
-#define DECLARE_MENU_EDIT_ITEM(NAME) typedef TMenuItem<MenuItemInfo_##NAME> MenuItem_##NAME;
|
|
219
|
+#define DECLARE_MENU_EDIT_ITEM(NAME) typedef TMenuEditItem<MenuEditItemInfo_##NAME> MenuItem_##NAME;
|
212
|
220
|
|
213
|
221
|
DECLARE_MENU_EDIT_ITEM(percent);
|
214
|
222
|
DECLARE_MENU_EDIT_ITEM(int3);
|
|
@@ -231,7 +239,7 @@ DECLARE_MENU_EDIT_ITEM(long5_25);
|
231
|
239
|
|
232
|
240
|
class MenuItem_bool {
|
233
|
241
|
public:
|
234
|
|
- static void action_edit(PGM_P const pstr, bool* ptr, const screenFunc_t callbackFunc=nullptr);
|
|
242
|
+ static void action(PGM_P const pstr, bool* ptr, const screenFunc_t callbackFunc=nullptr);
|
235
|
243
|
};
|
236
|
244
|
|
237
|
245
|
////////////////////////////////////////////
|
|
@@ -289,8 +297,8 @@ class MenuItem_bool {
|
289
|
297
|
/**
|
290
|
298
|
* MENU_ITEM generates draw & handler code for a menu item, potentially calling:
|
291
|
299
|
*
|
292
|
|
- * draw_menu_item_<type>[_variant](sel, row, label, arg3...)
|
293
|
|
- * MenuItem_<type>::action[_variant](arg3...)
|
|
300
|
+ * draw_menu_item_<type>(sel, row, label, arg3...)
|
|
301
|
+ * MenuItem_<type>::action(arg3...)
|
294
|
302
|
*
|
295
|
303
|
* Examples:
|
296
|
304
|
* BACK_ITEM(MSG_WATCH)
|
|
@@ -304,21 +312,21 @@ class MenuItem_bool {
|
304
|
312
|
* MenuItem_function::action(lcd_sdcard_pause)
|
305
|
313
|
*
|
306
|
314
|
* EDIT_ITEM(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
|
307
|
|
- * draw_menu_item_edit_int3(sel, row, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
|
308
|
|
- * MenuItem_int3::action_edit(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
|
|
315
|
+ * draw_menu_item_int3(sel, row, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
|
|
316
|
+ * MenuItem_int3::action(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
|
309
|
317
|
*
|
310
|
318
|
*/
|
311
|
|
-#define _MENU_ITEM_VARIANT_P(TYPE, VARIANT, USE_MULTIPLIER, PLABEL, V...) do { \
|
|
319
|
+#define _MENU_ITEM_P(TYPE, USE_MULTIPLIER, PLABEL, V...) do { \
|
312
|
320
|
_skipStatic = false; \
|
313
|
321
|
if (_menuLineNr == _thisItemNr) { \
|
314
|
322
|
PGM_P const plabel = PLABEL; \
|
315
|
323
|
if (encoderLine == _thisItemNr && ui.use_click()) { \
|
316
|
324
|
_MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
|
317
|
|
- MenuItem_##TYPE ::action ## VARIANT(plabel, ##V); \
|
|
325
|
+ MenuItem_##TYPE ::action(plabel, ##V); \
|
318
|
326
|
if (screen_changed) return; \
|
319
|
327
|
} \
|
320
|
328
|
if (ui.should_draw()) \
|
321
|
|
- draw_menu_item ## VARIANT ## _ ## TYPE \
|
|
329
|
+ draw_menu_item_ ## TYPE \
|
322
|
330
|
(encoderLine == _thisItemNr, _lcdLineNr, plabel, ##V); \
|
323
|
331
|
} \
|
324
|
332
|
++_thisItemNr; \
|
|
@@ -346,10 +354,10 @@ class MenuItem_bool {
|
346
|
354
|
|
347
|
355
|
#define STATIC_ITEM(LABEL, V...) STATIC_ITEM_P(PSTR(LABEL), ##V)
|
348
|
356
|
|
349
|
|
-#define MENU_ITEM_P(TYPE, PLABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, , false, PLABEL, ##V)
|
350
|
|
-#define MENU_ITEM(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, , false, PSTR(LABEL), ##V)
|
351
|
|
-#define EDIT_ITEM(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), ##V)
|
352
|
|
-#define EDIT_ITEM_FAST(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, _edit, true, PSTR(LABEL), ##V)
|
|
357
|
+#define MENU_ITEM_P(TYPE, PLABEL, V...) _MENU_ITEM_P(TYPE, false, PLABEL, ##V)
|
|
358
|
+#define MENU_ITEM(TYPE, LABEL, V...) _MENU_ITEM_P(TYPE, false, PSTR(LABEL), ##V)
|
|
359
|
+#define EDIT_ITEM(TYPE, LABEL, V...) _MENU_ITEM_P(TYPE, false, PSTR(LABEL), ##V)
|
|
360
|
+#define EDIT_ITEM_FAST(TYPE, LABEL, V...) _MENU_ITEM_P(TYPE, true, PSTR(LABEL), ##V)
|
353
|
361
|
|
354
|
362
|
#define SKIP_ITEM() (_thisItemNr++)
|
355
|
363
|
#define BACK_ITEM(LABEL) MENU_ITEM(back,LABEL)
|