Restore menu edit to 32bit value (#13976)

This commit is contained in:
InsanityAutomation
2019-05-11 19:44:35 -04:00
committed by Scott Lahteine
parent 3eee880967
commit 991ee7552b
6 changed files with 27 additions and 27 deletions

View File

@ -53,11 +53,11 @@ DECLARE_MENU_EDIT_TYPE(uint8_t, uint8, ui8tostr3, 1 ); // 123
DECLARE_MENU_EDIT_TYPE(uint16_t, uint16_3, ui16tostr3, 1 ); // 123, -12 right-justified
DECLARE_MENU_EDIT_TYPE(uint16_t, uint16_4, ui16tostr4, 0.1 ); // 1234, -123 right-justified
DECLARE_MENU_EDIT_TYPE(float, float3, ftostr3, 1 ); // 123 right-justified
DECLARE_MENU_EDIT_TYPE(float, float52, ftostr52, 100 ); // 123.45
DECLARE_MENU_EDIT_TYPE(float, float52, ftostr52, 100 ); // 123.45, -23.45
DECLARE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000 ); // 1.234
DECLARE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01f ); // 12345 right-justified
DECLARE_MENU_EDIT_TYPE(float, float5_25, ftostr5rj, 0.04f ); // 12345 right-justified (25 increment)
DECLARE_MENU_EDIT_TYPE(float, float51, ftostr51rj, 10 ); // 1234.5 right-justified
DECLARE_MENU_EDIT_TYPE(float, float51, ftostr51rj, 10 ); // _1234.5 right-justified
DECLARE_MENU_EDIT_TYPE(float, float51sign, ftostr51sign, 10 ); // +1234.5
DECLARE_MENU_EDIT_TYPE(float, float52sign, ftostr52sign, 100 ); // +123.45
DECLARE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01f ); // 12345 right-justified
@ -123,11 +123,11 @@ DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(uint8); // 123 right-justif
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(uint16_3); // 123, -12 right-justified
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(uint16_4); // 1234, -123 right-justified
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float3); // 123 right-justified
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52); // 123.45
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52); // 123.45, -23.45
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float43); // 1.234
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float5); // 12345 right-justified
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float5_25); // 12345 right-justified (25 increment)
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float51); // 1234.5 right-justified
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float51); // _1234.5 right-justified
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float51sign); // +1234.5
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(float52sign); // +123.45
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(long5); // 12345 right-justified
@ -168,13 +168,13 @@ class MenuItemBase {
private:
static PGM_P editLabel;
static void *editValue;
static int16_t minEditValue, maxEditValue;
static int32_t minEditValue, maxEditValue;
static screenFunc_t callbackFunc;
static bool liveEdit;
protected:
typedef char* (*strfunc_t)(const int16_t);
typedef void (*loadfunc_t)(void *, const int16_t);
static void init(PGM_P const el, void * const ev, const int16_t minv, const int16_t maxv, const uint16_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le);
typedef char* (*strfunc_t)(const int32_t);
typedef void (*loadfunc_t)(void *, const int32_t);
static void init(PGM_P const el, void * const ev, const int32_t minv, const int32_t maxv, const uint16_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le);
static void edit(strfunc_t, loadfunc_t);
};
@ -184,13 +184,13 @@ class TMenuItem : MenuItemBase {
typedef typename NAME::type_t type_t;
static inline float unscale(const float value) { return value * (1.0f / NAME::scale); }
static inline float scale(const float value) { return value * NAME::scale; }
static void load(void *ptr, const int16_t value) { *((type_t*)ptr) = unscale(value); }
static char* to_string(const int16_t value) { return NAME::strfunc(unscale(value)); }
static void load(void *ptr, const int32_t value) { *((type_t*)ptr) = unscale(value); }
static char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
public:
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) {
// Make sure minv and maxv fit within int16_t
const int16_t minv = MAX(scale(minValue), INT16_MIN),
maxv = MIN(scale(maxValue), INT16_MAX);
const int32_t minv = MAX(scale(minValue), INT_MIN),
maxv = MIN(scale(maxValue), INT_MAX);
init(pstr, ptr, minv, maxv - minv, scale(*ptr) - minv, edit, callback, live);
}
static void edit() { MenuItemBase::edit(to_string, load); }