From efdaf940a557e38a0446421309c862c8d7fccd3e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 15 Feb 2020 02:35:36 -0600 Subject: [PATCH] Fix byte-to-percent display Fixes #16866 --- Marlin/src/lcd/menu/menu.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Marlin/src/lcd/menu/menu.h b/Marlin/src/lcd/menu/menu.h index 4020385a15..de531e5a32 100644 --- a/Marlin/src/lcd/menu/menu.h +++ b/Marlin/src/lcd/menu/menu.h @@ -234,10 +234,10 @@ template class TMenuEditItem : MenuEditItemBase { private: 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 int32_t value) { *((type_t*)ptr) = unscale(value); } + static inline float scale(const float value) { return NAME::scale(value); } + static inline float unscale(const float value) { return NAME::unscale(value); } static const char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); } + static void load(void *ptr, const int32_t value) { *((type_t*)ptr) = unscale(value); } public: FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, type_t * const data, ...) { MenuEditItemBase::draw(sel, row, pstr, NAME::strfunc(*(data))); @@ -266,16 +266,17 @@ class TMenuEditItem : MenuEditItemBase { // Provide a set of Edit Item Types which encompass a primitive // type, a string function, and a scale factor for edit and display. // These items call the Edit Item draw method passing the prepared string. -#define DEFINE_MENU_EDIT_ITEM_TYPE(TYPE, NAME, STRFUNC, SCALE) \ - struct MenuEditItemInfo_##NAME { \ - typedef TYPE type_t; \ - static constexpr float scale = SCALE; \ +#define DEFINE_MENU_EDIT_ITEM_TYPE(TYPE, NAME, STRFUNC, SCALE, V...) \ + struct MenuEditItemInfo_##NAME { \ + typedef TYPE type_t; \ + static inline float scale(const float value) { return value * (SCALE) + (V+0); } \ + static inline float unscale(const float value) { return value / (SCALE) + (V+0); } \ static inline const char* strfunc(const float value) { return STRFUNC((TYPE)value); } \ - }; \ + }; \ typedef TMenuEditItem MenuItem_##NAME // TYPE NAME STRFUNC SCALE -DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t, percent, ui8tostr4pct, 100.0/255); // 100% right-justified +DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t, percent, ui8tostr4pct, 100.0/255, 0.5); // 100% right-justified DEFINE_MENU_EDIT_ITEM_TYPE(int16_t, int3, i16tostr3, 1 ); // 123, -12 right-justified DEFINE_MENU_EDIT_ITEM_TYPE(int16_t, int4, i16tostr4sign, 1 ); // 1234, -123 right-justified DEFINE_MENU_EDIT_ITEM_TYPE(int8_t, int8, i8tostr3, 1 ); // 123, -12 right-justified