Browse Source

Fix byte-to-percent display

Fixes #16866
Scott Lahteine 4 years ago
parent
commit
efdaf940a5
1 changed files with 10 additions and 9 deletions
  1. 10
    9
      Marlin/src/lcd/menu/menu.h

+ 10
- 9
Marlin/src/lcd/menu/menu.h View File

@@ -234,10 +234,10 @@ template<typename NAME>
234 234
 class TMenuEditItem : MenuEditItemBase {
235 235
   private:
236 236
     typedef typename NAME::type_t type_t;
237
-    static inline float unscale(const float value)    { return value * (1.0f / NAME::scale);  }
238
-    static inline float scale(const float value)      { return value * NAME::scale;           }
239
-    static void load(void *ptr, const int32_t value)  { *((type_t*)ptr) = unscale(value);     }
237
+    static inline float scale(const float value)      { return NAME::scale(value);            }
238
+    static inline float unscale(const float value)    { return NAME::unscale(value);          }
240 239
     static const char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
240
+    static void load(void *ptr, const int32_t value)  { *((type_t*)ptr) = unscale(value);     }
241 241
   public:
242 242
     FORCE_INLINE static void draw(const bool sel, const uint8_t row, PGM_P const pstr, type_t * const data, ...) {
243 243
       MenuEditItemBase::draw(sel, row, pstr, NAME::strfunc(*(data)));
@@ -266,16 +266,17 @@ class TMenuEditItem : MenuEditItemBase {
266 266
 // Provide a set of Edit Item Types which encompass a primitive
267 267
 // type, a string function, and a scale factor for edit and display.
268 268
 // These items call the Edit Item draw method passing the prepared string.
269
-#define DEFINE_MENU_EDIT_ITEM_TYPE(TYPE, NAME, STRFUNC, SCALE) \
270
-  struct MenuEditItemInfo_##NAME { \
271
-    typedef TYPE type_t; \
272
-    static constexpr float scale = SCALE; \
269
+#define DEFINE_MENU_EDIT_ITEM_TYPE(TYPE, NAME, STRFUNC, SCALE, V...)                      \
270
+  struct MenuEditItemInfo_##NAME {                                                        \
271
+    typedef TYPE type_t;                                                                  \
272
+    static inline float scale(const float value)   { return value * (SCALE) + (V+0); }    \
273
+    static inline float unscale(const float value) { return value / (SCALE) + (V+0); }    \
273 274
     static inline const char* strfunc(const float value) { return STRFUNC((TYPE)value); } \
274
-  }; \
275
+  };                                                                                      \
275 276
   typedef TMenuEditItem<MenuEditItemInfo_##NAME> MenuItem_##NAME
276 277
 
277 278
 //                         TYPE      NAME         STRFUNC       SCALE
278
-DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t,  percent,     ui8tostr4pct, 100.0/255);   // 100%       right-justified
279
+DEFINE_MENU_EDIT_ITEM_TYPE(uint8_t,  percent,     ui8tostr4pct, 100.0/255, 0.5);  // 100%   right-justified
279 280
 DEFINE_MENU_EDIT_ITEM_TYPE(int16_t,  int3,        i16tostr3,       1     );   // 123, -12   right-justified
280 281
 DEFINE_MENU_EDIT_ITEM_TYPE(int16_t,  int4,        i16tostr4sign,   1     );   // 1234, -123 right-justified
281 282
 DEFINE_MENU_EDIT_ITEM_TYPE(int8_t,   int8,        i8tostr3,        1     );   // 123, -12   right-justified

Loading…
Cancel
Save