Navigation code shared and improved (#6923)
This commit is contained in:
@@ -280,8 +280,6 @@ void menuChannelsView(event_t event);
|
||||
#endif
|
||||
|
||||
#define REPEAT_LAST_CURSOR_MOVE() { if (CURSOR_MOVED_LEFT(event) || CURSOR_MOVED_RIGHT(event)) putEvent(event); else menuHorizontalPosition = 0; }
|
||||
|
||||
#define MENU_FIRST_LINE_EDIT (menuTab ? (MAXCOL((uint16_t)0) >= HIDDEN_ROW ? (MAXCOL((uint16_t)1) >= HIDDEN_ROW ? 2 : 1) : 0) : 0)
|
||||
#define POS_HORZ_INIT(posVert) ((COLATTR(posVert) & NAVIGATION_LINE_BY_LINE) ? -1 : 0)
|
||||
#define EDIT_MODE_INIT 0 // TODO enum
|
||||
|
||||
|
||||
@@ -605,8 +605,6 @@ void readModelNotes();
|
||||
#define CURSOR_MOVED_LEFT(event) (event==EVT_ROTARY_LEFT || EVT_KEY_MASK(event) == KEY_LEFT)
|
||||
#define CURSOR_MOVED_RIGHT(event) (event==EVT_ROTARY_RIGHT || EVT_KEY_MASK(event) == KEY_RIGHT)
|
||||
#define REPEAT_LAST_CURSOR_MOVE(last, refresh) { if (CURSOR_MOVED_RIGHT(event)) menuHorizontalPosition = (menuHorizontalPosition >= (last) ? 0 : menuHorizontalPosition + 1); else menuHorizontalPosition = (menuHorizontalPosition <= (0) ? last : menuHorizontalPosition - 1); if (refresh) putEvent(EVT_REFRESH); }
|
||||
|
||||
#define MENU_FIRST_LINE_EDIT (MAXCOL((uint16_t)0) >= HIDDEN_ROW ? (MAXCOL((uint16_t)1) >= HIDDEN_ROW ? 2 : 1) : 0)
|
||||
#define POS_HORZ_INIT(posVert) ((COLATTR(posVert) & NAVIGATION_LINE_BY_LINE) ? -1 : 0)
|
||||
#define EDIT_MODE_INIT 0 // TODO enum
|
||||
|
||||
|
||||
@@ -38,6 +38,21 @@
|
||||
#define CASE_EVT_ROTARY_RIGHT
|
||||
#endif
|
||||
|
||||
#if defined(NAVIGATION_X7) || defined(NAVIGATION_X9D) || defined(NAVIGATION_HORUS)
|
||||
inline uint8_t MENU_FIRST_LINE_EDIT(const uint8_t * horTab, uint8_t horTabMax)
|
||||
{
|
||||
if (horTab) {
|
||||
uint8_t result = 0;
|
||||
while (result < horTabMax && horTab[result] >= HIDDEN_ROW)
|
||||
++result;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef bool (*IsValueAvailable)(int);
|
||||
|
||||
int circularIncDec(int current, int inc, int min, int max, IsValueAvailable isValueAvailable=nullptr);
|
||||
|
||||
@@ -353,7 +353,7 @@ bool check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
s_editMode = EDIT_MODE_INIT;
|
||||
menuVerticalPosition = MENU_FIRST_LINE_EDIT;
|
||||
menuVerticalPosition = MENU_FIRST_LINE_EDIT(horTab, horTabMax);
|
||||
menuHorizontalPosition = POS_HORZ_INIT(menuVerticalPosition);
|
||||
break;
|
||||
|
||||
@@ -390,7 +390,7 @@ bool check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
else {
|
||||
uint8_t posVertInit = MENU_FIRST_LINE_EDIT;
|
||||
uint8_t posVertInit = MENU_FIRST_LINE_EDIT(horTab, horTabMax);
|
||||
if (menuVerticalOffset != 0 || menuVerticalPosition != posVertInit) {
|
||||
menuVerticalOffset = 0;
|
||||
menuVerticalPosition = posVertInit;
|
||||
@@ -435,7 +435,7 @@ bool check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
|
||||
break;
|
||||
}
|
||||
do {
|
||||
INC(menuVerticalPosition, MENU_FIRST_LINE_EDIT, rowcount-1);
|
||||
INC(menuVerticalPosition, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount-1);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(menuVerticalPosition));
|
||||
menuHorizontalPosition = POS_HORZ_INIT(menuVerticalPosition);
|
||||
break;
|
||||
@@ -454,7 +454,7 @@ bool check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
|
||||
break;
|
||||
}
|
||||
do {
|
||||
DEC(menuVerticalPosition, MENU_FIRST_LINE_EDIT, rowcount-1);
|
||||
DEC(menuVerticalPosition, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount-1);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(menuVerticalPosition));
|
||||
if (COLATTR(menuVerticalPosition) & NAVIGATION_LINE_BY_LINE)
|
||||
menuHorizontalPosition = -1;
|
||||
@@ -465,7 +465,7 @@ bool check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
|
||||
|
||||
linesCount = rowcount;
|
||||
|
||||
if (menuVerticalPosition <= MENU_FIRST_LINE_EDIT) {
|
||||
if (menuVerticalPosition <= MENU_FIRST_LINE_EDIT(horTab, horTabMax)) {
|
||||
menuVerticalOffset = 0;
|
||||
if (horTab) {
|
||||
linesCount = 0;
|
||||
|
||||
@@ -205,7 +205,6 @@ tmr10ms_t menuEntryTime;
|
||||
#define MAXCOL_RAW(row) (horTab ? *(horTab+min(row, (vertpos_t)horTabMax)) : (const uint8_t)0)
|
||||
#define MAXCOL(row) (MAXCOL_RAW(row) >= HIDDEN_ROW ? MAXCOL_RAW(row) : (const uint8_t)(MAXCOL_RAW(row) & (~NAVIGATION_LINE_BY_LINE)))
|
||||
#define COLATTR(row) (MAXCOL_RAW(row) == (uint8_t)-1 ? (const uint8_t)0 : (const uint8_t)(MAXCOL_RAW(row) & NAVIGATION_LINE_BY_LINE))
|
||||
#define MENU_FIRST_LINE_EDIT (menuTab ? (MAXCOL((uint16_t)0) >= HIDDEN_ROW ? (MAXCOL((uint16_t)1) >= HIDDEN_ROW ? 2 : 1) : 0) : 0)
|
||||
#define POS_HORZ_INIT(posVert) ((COLATTR(posVert) & NAVIGATION_LINE_BY_LINE) ? -1 : 0)
|
||||
|
||||
void check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t menuTabSize, const uint8_t * horTab, uint8_t horTabMax, vertpos_t rowcount)
|
||||
@@ -251,7 +250,7 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
|
||||
case EVT_ENTRY:
|
||||
menuEntryTime = get_tmr10ms();
|
||||
s_editMode = EDIT_MODE_INIT;
|
||||
l_posVert = MENU_FIRST_LINE_EDIT;
|
||||
l_posVert = MENU_FIRST_LINE_EDIT(horTab, horTabMax);
|
||||
l_posHorz = POS_HORZ_INIT(l_posVert);
|
||||
break;
|
||||
|
||||
@@ -291,7 +290,7 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
else {
|
||||
uint8_t posVertInit = MENU_FIRST_LINE_EDIT;
|
||||
uint8_t posVertInit = MENU_FIRST_LINE_EDIT(horTab, horTabMax);
|
||||
if (menuVerticalOffset != 0 || l_posVert != posVertInit) {
|
||||
menuVerticalOffset = 0;
|
||||
l_posVert = posVertInit;
|
||||
@@ -327,7 +326,7 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
|
||||
}
|
||||
|
||||
do {
|
||||
INC(l_posVert, MENU_FIRST_LINE_EDIT, rowcount-1);
|
||||
INC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount-1);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
|
||||
s_editMode = 0; // if we go down, we must be in this mode
|
||||
@@ -356,7 +355,7 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t
|
||||
}
|
||||
|
||||
do {
|
||||
DEC(l_posVert, MENU_FIRST_LINE_EDIT, rowcount-1);
|
||||
DEC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount-1);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
|
||||
s_editMode = 0; // if we go up, we must be in this mode
|
||||
|
||||
@@ -360,7 +360,7 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
|
||||
case EVT_ENTRY:
|
||||
menuEntryTime = get_tmr10ms();
|
||||
s_editMode = EDIT_MODE_INIT;
|
||||
l_posVert = MENU_FIRST_LINE_EDIT;
|
||||
l_posVert = MENU_FIRST_LINE_EDIT(horTab, horTabMax);
|
||||
l_posHorz = POS_HORZ_INIT(l_posVert);
|
||||
SET_SCROLLBAR_X(LCD_W-1);
|
||||
break;
|
||||
@@ -402,7 +402,7 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
else {
|
||||
uint8_t posVertInit = MENU_FIRST_LINE_EDIT;
|
||||
uint8_t posVertInit = MENU_FIRST_LINE_EDIT(horTab, horTabMax);
|
||||
if (menuVerticalOffset != 0 || l_posVert != posVertInit) {
|
||||
menuVerticalOffset = 0;
|
||||
l_posVert = posVertInit;
|
||||
@@ -438,7 +438,7 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
|
||||
}
|
||||
|
||||
do {
|
||||
INC(l_posVert, MENU_FIRST_LINE_EDIT, rowcount-1);
|
||||
INC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount-1);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
|
||||
s_editMode = 0; // if we go down, we must be in this mode
|
||||
@@ -467,7 +467,7 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
|
||||
}
|
||||
|
||||
do {
|
||||
DEC(l_posVert, MENU_FIRST_LINE_EDIT, rowcount-1);
|
||||
DEC(l_posVert, MENU_FIRST_LINE_EDIT(horTab, horTabMax), rowcount-1);
|
||||
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));
|
||||
|
||||
s_editMode = 0; // if we go up, we must be in this mode
|
||||
|
||||
Reference in New Issue
Block a user