jonblack / arduino-menusystem

Arduino library for implementing a menu system
MIT License
194 stars 85 forks source link

Add render callbacks to individual MenuItem instances #77

Open qbit- opened 6 years ago

qbit- commented 6 years ago

Thanks for the great job implementing this library! I've easily ported it to MBED framework.

I would like to discuss if having individual rendering callbacks for each MenuItem, instead of subclassing MenuItem each time is a worthy idea. My use case is as follows. I would like to have a menu where the user can set time with hours, minutes and seconds. Each time interval has its own NumericMenuItem. As the user changes the value I would like to draw it but in different places of the LCD screen. It is problematic to do as all NumericMenuItems call the same rendering function. Ideally I would like to set individual rendering functions for each menuitem, and fallback to default if no callback was provided. What should be a clean solution?

Similar (but limited) functionality is implemented by the formatvaluefnptr argument in NumericMenuItem.

In general, providing the user an option to set callbacks would eliminate the need of a compicated renderer class. Getting rid of the renderer class altogether will eliminate a circular dependence of the custom menu item classes and a renderer class (which is seen in the serial_nav example)