#pragma once
#include "menu.hpp"
//! вывод цифровых значений и их изменение
template <typename T> class item_num_templ: public MenuItem {
protected:
  utf32 str = {};
  T* pVal = nullptr;
  void_callback pFunc = nullptr;
  T MIN_VAL = -1000;
  T MAX_VAL = 1000;
  T ADD_VAL = 1;
private:
  nocopy(item_num_templ);
public:
  explicit item_num_templ(CN(utf32) s, T* p, void_callback f = nullptr,
  T MIN = -1000, T MAX = 1000, T add_val = 1): str(s), pVal(p), pFunc(f), MIN_VAL(MIN),
  MAX_VAL(MAX), ADD_VAL(add_val) {
    IFERROR( !p, "item_num_templ(): num pointer is null");
    IFERROR(MAX_VAL <= MIN_VAL, "item_num_templ: bad min or max");
  }
  void print(Font* pFont, Image& dst, int XPos = 0, int YPos = 0) const override
    { pFont->print(dst, XPos, YPos, str + n2s<utf32>(*pVal)); }
  bool accept() override {
    if (pFunc)
      return pFunc();
    return true;
  }
  void plus() override {
    if (pVal)
      *pVal = std::clamp(*pVal + ADD_VAL, MIN_VAL, MAX_VAL);
  }
  void sub() override {
    if (pVal)
      *pVal = std::clamp(*pVal - ADD_VAL, MIN_VAL, MAX_VAL);
  }
};
using item_int = item_num_templ<int>;
using item_uint = item_num_templ<uint>;
using item_double = item_num_templ<double>;
using item_float = item_num_templ<float>;