Simplify edit menu items

The `edit` part of menu items displaying values is not needed. Menu edit types can be modeled on sub-menus.
This commit is contained in:
Scott Lahteine
2019-10-02 19:04:16 -05:00
parent 273cbe931e
commit 719615a6b6
2 changed files with 48 additions and 39 deletions

View File

@ -68,11 +68,11 @@ uint8_t screen_history_depth = 0;
bool screen_changed;
// Value Editing
PGM_P MenuItemBase::editLabel;
void* MenuItemBase::editValue;
int32_t MenuItemBase::minEditValue, MenuItemBase::maxEditValue;
screenFunc_t MenuItemBase::callbackFunc;
bool MenuItemBase::liveEdit;
PGM_P MenuEditItemBase::editLabel;
void* MenuEditItemBase::editValue;
int32_t MenuEditItemBase::minEditValue, MenuEditItemBase::maxEditValue;
screenFunc_t MenuEditItemBase::callbackFunc;
bool MenuEditItemBase::liveEdit;
// Prevent recursion into screen handlers
bool no_reentry = false;
@ -131,18 +131,19 @@ void MenuItem_gcode::action(PGM_P const, PGM_P const pgcode) { queue.inject_P(pg
*
* bool MenuItem_int3::_edit();
* void MenuItem_int3::edit(); // edit int16_t (interactively)
* void MenuItem_int3::action_edit(PGM_P const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue, const screenFunc_t callback = null, const bool live = false);
* void MenuItem_int3::action(PGM_P const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue, const screenFunc_t callback = null, const bool live = false);
*
* You can then use one of the menu macros to present the edit interface:
* EDIT_ITEM(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
*
* This expands into a more primitive menu item:
* MENU_ITEM_VARIANT(int3, _edit, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
* _MENU_ITEM_P(int3, false, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
*
* ...which calls:
* MenuItem_int3::action_edit(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
* MenuItem_int3::action(plabel, &feedrate_percentage, 10, 999)
* draw_menu_item_int3(encoderLine == _thisItemNr, _lcdLineNr, plabel, &feedrate_percentage, 10, 999)
*/
void MenuItemBase::edit(strfunc_t strfunc, loadfunc_t loadfunc) {
void MenuEditItemBase::edit(strfunc_t strfunc, loadfunc_t loadfunc) {
#if ENABLED(TOUCH_BUTTONS)
ui.repeat_delay = BUTTON_DELAY_EDIT;
#endif
@ -157,7 +158,7 @@ void MenuItemBase::edit(strfunc_t strfunc, loadfunc_t loadfunc) {
}
}
void MenuItemBase::init(PGM_P const el, void * const ev, const int32_t minv, const int32_t maxv, const uint16_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le) {
void MenuEditItemBase::init(PGM_P const el, void * const ev, const int32_t minv, const int32_t maxv, const uint16_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le) {
ui.save_previous_screen();
ui.refresh();
editLabel = el;
@ -170,7 +171,7 @@ void MenuItemBase::init(PGM_P const el, void * const ev, const int32_t minv, con
liveEdit = le;
}
#define DEFINE_MENU_EDIT_ITEM(NAME) template class TMenuItem<MenuItemInfo_##NAME>
#define DEFINE_MENU_EDIT_ITEM(NAME) template class TMenuEditItem<MenuEditItemInfo_##NAME>
DEFINE_MENU_EDIT_ITEM(percent); // 100% right-justified
DEFINE_MENU_EDIT_ITEM(int3); // 123, -12 right-justified
@ -191,7 +192,7 @@ DEFINE_MENU_EDIT_ITEM(float52sign); // +123.45
DEFINE_MENU_EDIT_ITEM(long5); // 12345 right-justified
DEFINE_MENU_EDIT_ITEM(long5_25); // 12345 right-justified (25 increment)
void MenuItem_bool::action_edit(PGM_P pstr, bool *ptr, screenFunc_t callback) {
void MenuItem_bool::action(PGM_P pstr, bool *ptr, screenFunc_t callback) {
UNUSED(pstr); *ptr ^= true; ui.refresh();
if (callback) (*callback)();
}