New Arduino library: MenuSystem

Hi fellow duinists,

I am doing a project which includes a tft display, and at startup it is supposed to have some menu items where the user can select some startup options.
I have successfully made a sketch that will display some menu-items, a sub-menu (level 2 items) and am able to navigate it with some buttons.

After many failed attempts i have even been able to show and modify a NumericMenuItem. (select first time allows editing the number, then selecting again lets me go back to navigate the menu.

What i have not been able to do, but i think it must be possible, is to display that number as an integer, rather than as it is implemented in the library, a float.
As far as i understand, I should be able to define a ' format_value_fn ' that formats the float value into any String in a specific way.
But here i run into a problem. I get :

error: invalid conversion from 'String ()(float)' to 'NumericMenuItem::FormatValueFnPtr {aka const String ()(float)}' [-fpermissive]

It seems that the function i created is correct in that it returns a String from the input of a float, but the IDE complains that my function is not a member function of the NumericMenuItem class??

Does anyone have an example of using this format_value_fn, either adding it while defining the NumericMenuItem, or somewhere in the sketch by using the 'set_number_formatter' member function of the class?

Thanks for just reading :slight_smile:

edit Wednesday 2017/8/23

I have found a way that works.

  • defined a type (variable that points to a function..) , and named the type 'MyPtr_type' .
    specifically it points to a function that takes a const float as argument and returns a 'const String'
    typedef const String (*MyPtr_type) (const float val);

  • declared an instance of that variable named My_pointer
    MyPtr_type My_pointer;

  • created a function that is conforming to this, so that My_pointer can point to it
    const String My_Function (const float value){ .. insert function code here .. }

  • Then let My_pointer actually point to My_function
    My_pointer = My_function;

Now I can instantiate (define) the NumericMenuItem with 'My_pointer' as the 7th argument (instead of NullPtr) .. if you know what I mean.

Feeling a little smug now.. LoL
(Ah, dont forget THANKS So much to Nick Gammon for his very clear page on pointers to functions)

Still don't understand why a return value can be / should be defined as const. ??
But it seems to make a load of difference.
I understand that in this case it is required to be a const because the function in the MenuSystem library is also defined that way.
But in my (very limited) understanding, the keyword const in a function is used to tell the compiler that the source value should not be modified. (and if you try, it would give an error/warning)
But here even the return String is defined as const String.