This commit is contained in:
kraus 2022-01-09 19:53:04 +01:00
parent facda2a53f
commit 0cca3ac8ff
5 changed files with 118 additions and 66 deletions

View File

@ -621,11 +621,17 @@ static uint8_t mui_send_cursor_msg(mui_t *ui, uint8_t msg)
If the first selectable field has the focus, then 0 will be returned
Unselectable fields (for example labels) are skipped by this count.
If no fields are selectable, then 0 is returned
The return value can be used as last argument for mui_EnterForm or mui_GotoForm
WARNING: This function will destroy current fds and field information.
*/
uint8_t mui_GetCurrentCursorFocusPosition(mui_t *ui)
{
ui->tmp8 = 0;
//fds_t *fds = ui->fds;
ui->tmp8 = 0;
mui_loop_over_form(ui, mui_task_get_current_cursor_focus_position);
//ui->fds = fds;
return ui->tmp8;
}
@ -783,7 +789,7 @@ void mui_EnterForm(mui_t *ui, fds_t *fds, uint8_t initial_cursor_position)
ui->current_form_fds = fds;
/* inform all fields that we start a new form */
MUI_DEBUG("mui_EnterForm: form_start\n");
MUI_DEBUG("mui_EnterForm: form_start, initial_cursor_position=%d\n", initial_cursor_position);
mui_loop_over_form(ui, mui_task_form_start);
/* assign initional cursor focus */
@ -854,6 +860,40 @@ void mui_RestoreForm(mui_t *ui)
mui_GotoForm(ui, ui->last_form_id, ui->last_form_cursor_focus_position);
}
/*
Save a cursor position for mui_GotoFormAutoCursorPosition command
Only one such position is stored.
*/
void mui_SaveCursorPosition(mui_t *ui, uint8_t cursor_position)
{
uint8_t form_id = mui_get_fds_char(ui->current_form_fds+1);
MUI_DEBUG("mui_SaveCursorPosition form_id=%d cursor_position=%d\n", form_id, cursor_position);
if ( form_id == ui->menu_form_id[0] )
ui->menu_form_last_added = 0;
else if ( form_id == ui->menu_form_id[1] )
ui->menu_form_last_added = 1;
else
ui->menu_form_last_added ^= 1;
ui->menu_form_id[ui->menu_form_last_added] = form_id;
ui->menu_form_cursor_focus_position[ui->menu_form_last_added] = cursor_position;
MUI_DEBUG("mui_SaveCursorPosition ui->menu_form_last_added=%d \n", ui->menu_form_last_added);
}
/*
Similar to mui_GotoForm, but will jump to previously stored cursor location (mui_SaveCursorPosition) or 0 if the cursor position was not saved.
*/
uint8_t mui_GotoFormAutoCursorPosition(mui_t *ui, uint8_t form_id)
{
uint8_t cursor_position = 0;
if ( form_id == ui->menu_form_id[0] )
cursor_position = ui->menu_form_cursor_focus_position[0];
if ( form_id == ui->menu_form_id[1] )
cursor_position = ui->menu_form_cursor_focus_position[1];
MUI_DEBUG("mui_GotoFormAutoCursorPosition form_id=%d cursor_position=%d\n", form_id, cursor_position);
return mui_GotoForm(ui, form_id, cursor_position);
}
/*
return current form id or -1 if the menu system is inactive
*/

View File

@ -210,6 +210,8 @@ struct muif_struct
/* must be smaller than or equal to 255 */
#define MUI_MAX_TEXT_LEN 41
#define MUI_MENU_CACHE_CNT 2
struct mui_struct
{
void *graphics_data;
@ -258,6 +260,11 @@ struct mui_struct
uint8_t last_form_id;
uint8_t last_form_cursor_focus_position;
fds_t *last_form_fds; // not used by mui_RestoreForm, but can be used by field functions
/* menu cursor position backup */
uint8_t menu_form_id[MUI_MENU_CACHE_CNT];
uint8_t menu_form_cursor_focus_position[MUI_MENU_CACHE_CNT];
uint8_t menu_form_last_added;
} ;
#define mui_IsCursorFocus(mui) ((mui)->dflags & MUIF_DFLAG_IS_CURSOR_FOCUS)
@ -563,9 +570,12 @@ uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, fds_t *fds);
void mui_EnterForm(mui_t *ui, fds_t *fds, uint8_t initial_cursor_position);
void mui_LeaveForm(mui_t *ui);
uint8_t mui_GotoForm(mui_t *ui, uint8_t form_id, uint8_t initial_cursor_position);
void mui_SaveForm(mui_t *ui);
void mui_RestoreForm(mui_t *ui);
int mui_GetCurrentFormId(mui_t *ui);
void mui_SaveForm(mui_t *ui); /* Save current form+cursor position. Used together with mui_RestoreForm */
void mui_RestoreForm(mui_t *ui); /* Restore form and cursor position, previously saved with mui_SaveForm */
void mui_SaveCursorPosition(mui_t *ui, uint8_t cursor_position); /* stores a cursor position for use with mui_GotoFormAutoCursorPosition */
uint8_t mui_GotoFormAutoCursorPosition(mui_t *ui, uint8_t form_id);
int mui_GetCurrentFormId(mui_t *ui); /* form id or -1 if the menu system is inactive */
void mui_NextField(mui_t *ui);
void mui_PrevField(mui_t *ui);
void mui_SendSelect(mui_t *ui);

View File

@ -409,7 +409,8 @@ uint8_t mui_u8g2_btn_goto_wm_fi(mui_t *ui, uint8_t msg)
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
return mui_GotoForm(ui, ui->arg, 0);
//return mui_GotoForm(ui, ui->arg, 0);
return mui_GotoFormAutoCursorPosition(ui, ui->arg);
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
@ -435,8 +436,9 @@ uint8_t mui_u8g2_btn_goto_wm_if(mui_t *ui, uint8_t msg)
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
return mui_GotoForm(ui, ui->arg, 0);
case MUIF_MSG_CURSOR_LEAVE:
//return mui_GotoForm(ui, ui->arg, 0);
return mui_GotoFormAutoCursorPosition(ui, ui->arg);
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
break;
@ -462,7 +464,8 @@ uint8_t mui_u8g2_btn_goto_w2_fi(mui_t *ui, uint8_t msg)
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
return mui_GotoForm(ui, ui->arg, 0);
//return mui_GotoForm(ui, ui->arg, 0);
return mui_GotoFormAutoCursorPosition(ui, ui->arg);
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
@ -488,7 +491,8 @@ uint8_t mui_u8g2_btn_goto_w2_if(mui_t *ui, uint8_t msg)
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
return mui_GotoForm(ui, ui->arg, 0);
//return mui_GotoForm(ui, ui->arg, 0);
return mui_GotoFormAutoCursorPosition(ui, ui->arg);
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
@ -574,7 +578,8 @@ uint8_t mui_u8g2_btn_goto_w1_pi(mui_t *ui, uint8_t msg)
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
return mui_GotoForm(ui, ui->arg, 0);
//return mui_GotoForm(ui, ui->arg, 0);
return mui_GotoFormAutoCursorPosition(ui, ui->arg);
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
@ -602,7 +607,8 @@ uint8_t mui_u8g2_btn_goto_w1_fi(mui_t *ui, uint8_t msg)
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
return mui_GotoForm(ui, ui->arg, 0);
//return mui_GotoForm(ui, ui->arg, 0);
return mui_GotoFormAutoCursorPosition(ui, ui->arg);
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
@ -1703,6 +1709,8 @@ uint8_t mui_u8g2_u8_opt_child_wm_mse_pi(mui_t *ui, uint8_t msg)
mui_u8g2_goto_parent --> mui_u8g2_goto_data
Used together with mui_u8g2_goto_form_w1_mse_pi
*/
uint8_t mui_u8g2_goto_data(mui_t *ui, uint8_t msg)
{
@ -1747,7 +1755,10 @@ uint8_t mui_u8g2_goto_form_w1_mse_pi(mui_t *ui, uint8_t msg)
break;
case MUIF_MSG_CURSOR_SELECT:
if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, ui->arg + ui->form_scroll_top) )
return mui_GotoForm(ui, (uint8_t)ui->text[0], 0);
{
mui_SaveCursorPosition(ui, ui->arg + ui->form_scroll_top); // store the current cursor position, so that the user can jump back to the corresponding cursor position
return mui_GotoFormAutoCursorPosition(ui, (uint8_t)ui->text[0]);
}
break;
default:
return mui_u8g2_u8_opt_child_mse_common(ui, msg);
@ -1767,7 +1778,10 @@ uint8_t mui_u8g2_goto_form_w1_mse_pf(mui_t *ui, uint8_t msg)
break;
case MUIF_MSG_CURSOR_SELECT:
if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, ui->arg + ui->form_scroll_top) )
return mui_GotoForm(ui, (uint8_t)ui->text[0], 0);
{
mui_SaveCursorPosition(ui, ui->arg + ui->form_scroll_top); // store the current cursor position, so that the user can jump back to the corresponding cursor position
return mui_GotoFormAutoCursorPosition(ui, (uint8_t)ui->text[0]);
}
break;
default:
return mui_u8g2_u8_opt_child_mse_common(ui, msg);
@ -2014,7 +2028,8 @@ uint8_t mui_u8g2_u16_list_goto_w1_mse_pi(mui_t *ui, uint8_t msg)
case MUIF_MSG_CURSOR_SELECT:
if ( selection != NULL )
*selection = pos;
mui_GotoForm(ui, (uint8_t)element_cb(data, pos)[0], 0);
mui_SaveCursorPosition(ui, pos >= 255 ? 0 : pos); // store the current cursor position, so that the user can jump back to the corresponding cursor position
mui_GotoFormAutoCursorPosition(ui, (uint8_t)element_cb(data, pos)[0]);
break;
default:
return mui_u8g2_u16_list_child_mse_common(ui, msg);

View File

@ -450,26 +450,21 @@ muif_t muif_list[] = {
/* horizontal line (hrule) */
MUIF_RO("HR", mui_hrule),
/* main menu */
MUIF_RO("GP",mui_u8g2_goto_data),
MUIF_BUTTON("GC", mui_u8g2_goto_form_w1_mse_pi),
/* Goto Form Button where the width is equal to the size of the text, spaces can be used to extend the size */
//MUIF("G1",MUIF_CFLAG_IS_CURSOR_SELECTABLE,0,mui_u8g2_btn_goto_wm_fi),
MUIF_BUTTON("G1", mui_u8g2_btn_goto_wm_fi),
/* input for a number between 0 to 9 */
//MUIF("IN",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&number_input,mui_u8g2_u8_value_0_9_wm_mse_pi),
//MUIF("IN",MUIF_CFLAG_IS_CURSOR_SELECTABLE, (void *)((mui_u8g2_u8_min_max_t [] ) {{ &number_input COMMA 1 COMMA 8 } } ) , mui_u8g2_u8_min_max_wm_mse_pi),
MUIF_U8G2_U8_MIN_MAX("IN", &number_input, 0, 9, mui_u8g2_u8_min_max_wm_mse_pi),
/* input for a number between 0 to 100 */
//MUIF("IH",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&number_input2,mui_u8g2_u8_value_0_100_wm_mud_pi),
MUIF_U8G2_U8_MIN_MAX("IH", &number_input2, 0, 100, mui_u8g2_u8_min_max_wm_mud_pi),
/* input for text with four chars */
/*
MUIF("T0",MUIF_CFLAG_IS_CURSOR_SELECTABLE,text_input+0,mui_u8g2_u8_char_wm_mud_pi),
MUIF("T1",MUIF_CFLAG_IS_CURSOR_SELECTABLE,text_input+1,mui_u8g2_u8_char_wm_mud_pi),
MUIF("T2",MUIF_CFLAG_IS_CURSOR_SELECTABLE,text_input+2,mui_u8g2_u8_char_wm_mud_pi),
MUIF("T3",MUIF_CFLAG_IS_CURSOR_SELECTABLE,text_input+3,mui_u8g2_u8_char_wm_mud_pi),
*/
MUIF_VARIABLE("T0", text_input+0, mui_u8g2_u8_char_wm_mud_pi),
MUIF_VARIABLE("T1", text_input+1, mui_u8g2_u8_char_wm_mud_pi),
MUIF_VARIABLE("T2", text_input+2, mui_u8g2_u8_char_wm_mud_pi),
@ -480,23 +475,16 @@ muif_t muif_list[] = {
MUIF_VARIABLE("IG",&fruit_input2,mui_u8g2_u8_opt_line_wa_mud_pi),
/* checkbox */
//MUIF("CB",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&checkbox_input,mui_u8g2_u8_chkbox_wm_pi),
MUIF_VARIABLE("CB",&checkbox_input,mui_u8g2_u8_chkbox_wm_pi),
/* the following two fields belong together and implement a single selection combo box to select a color */
//MUIF("IC",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&color_input,mui_u8g2_u8_opt_parent_wa_mse_pi),
MUIF_VARIABLE("IC",&color_input,mui_u8g2_u8_opt_parent_wm_mse_pi),
//MUIF("OC",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&color_input,mui_u8g2_u8_opt_child_w1_mse_pi),
//MUIF("OC",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&color_input,mui_u8g2_u8_opt_child_w1_mse_pi),
//MUIF("OC",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&color_input,mui_u8g2_u8_opt_child_w1_mse_pi),
//MUIF("OC",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&color_input,mui_u8g2_u8_opt_child_w1_mse_pi),
MUIF_VARIABLE("OC",&color_input,mui_u8g2_u8_opt_radio_child_w1_mse_pi),
MUIF_VARIABLE("ID",&food_input,mui_u8g2_u8_opt_parent_wm_mse_pi),
MUIF_VARIABLE("OD",&food_input,mui_u8g2_u8_opt_child_wm_mse_pi),
/* radio button style */
//MUIF("RS",MUIF_CFLAG_IS_CURSOR_SELECTABLE,&direction_input,mui_u8g2_u8_radio_wm_pi),
MUIF_VARIABLE("RS",&direction_input,mui_u8g2_u8_radio_wm_pi),
MUIF_U8G2_U16_LIST("L1", &list_selection, NULL, list_get_str, list_get_cnt, mui_u8g2_u16_list_line_wa_mse_pi),
@ -510,9 +498,8 @@ muif_t muif_list[] = {
/* MUI_GOTO uses the fixed ".G" id and is intended for goto buttons. This is a full display width style button */
MUIF_GOTO(mui_u8g2_btn_goto_w1_pi),
/* MUI_LABEL uses the fixed ".L" id and is used to place read only text on a form */
//MUIF(".L",0,0,mui_u8g2_draw_text),
MUIF_LABEL(mui_u8g2_draw_text),
/* register MUI_LABEL, which is used to place read only text on a form */
MUIF_U8G2_LABEL(),
/* array example */
MUIF_U8G2_U8_MIN_MAX("AP", &array_pos, 0, 3, muif_array_pos_selection),
@ -540,39 +527,34 @@ muif_t muif_list[] = {
*/
fds_t fds_data[] =
/* top level main menu */
MUI_FORM(0)
MUI_STYLE(1)
MUI_LABEL(5,10, "Main Menu 1/3")
MUI_LABEL(5,10, "Main Menu")
MUI_XY("HR", 0,13)
MUI_STYLE(0)
MUI_GOTO(5,25,10, "Enter a number")
MUI_GOTO(5,37,11, "Parent/Child Selection")
MUI_GOTO(5,49,13, "Checkbox")
MUI_GOTO(5,61,1, "More...")
MUI_FORM(1)
MUI_STYLE(1)
MUI_LABEL(5,10, "Main Menu 2/3")
MUI_XY("HR", 0,13)
MUI_STYLE(0)
MUI_GOTO(5,25,14, "Radio Selection")
MUI_GOTO(5,37,15, "Text Input")
MUI_GOTO(5,49,16, "Single Line Selection")
MUI_GOTO(5,61,2, "More...")
MUI_DATA("GP",
MUI_10 "Enter a number|"
MUI_11 "Parent/Child Selection|"
MUI_13 "Checkbox|"
MUI_14 "Radio Selection|"
MUI_15 "Text Input|"
MUI_16 "Single Line Selection|"
MUI_17 "List Line Selection|"
MUI_18 "Parent/Child List|"
MUI_20 "Array Edit|"
MUI_3 "Alternative Menu"
)
MUI_XYA("GC", 5, 25, 0)
MUI_XYA("GC", 5, 37, 1)
MUI_XYA("GC", 5, 49, 2)
MUI_XYA("GC", 5, 61, 3)
MUI_FORM(2)
MUI_STYLE(1)
MUI_LABEL(5,10, "Main Menu 3/3")
MUI_XY("HR", 0,13)
MUI_STYLE(0)
MUI_GOTO(5,25,17, "List Line Selection")
MUI_GOTO(5,37,18, "Parent/Child List")
MUI_GOTO(5,49,20, "Array Edit")
MUI_GOTO(5,61,3, "Alternative Menu")
MUI_FORM(3)
MUI_STYLE(1)
@ -653,7 +635,7 @@ MUI_XYAT("RS",10, 40,1,"South")
MUI_XYAT("RS",65, 28,2,"East")
MUI_XYAT("RS",65, 40,3,"West")
MUI_XYAT("G1",64, 59, 1, " OK ")
MUI_XYAT("G1",64, 59, 0, " OK ")
/* text demo */
MUI_FORM(15)
@ -670,7 +652,7 @@ MUI_XY("T2",56, 30)
MUI_XY("T3",64, 30)
MUI_STYLE(0)
MUI_XYAT("G1",64, 59, 1, " OK ")
MUI_XYAT("G1",64, 59, 0, " OK ")
/* single line selection */
MUI_FORM(16)
@ -685,7 +667,7 @@ MUI_XYAT("IF",60, 29, 60, "Banana|Apple|Melon|Cranberry")
MUI_LABEL(5,43, "Fruit [mud]:")
MUI_XYAT("IG",60, 43, 60, "Banana|Apple|Melon|Cranberry")
MUI_XYAT("G1",64, 59, 1, " OK ")
MUI_XYAT("G1",64, 59, 0, " OK ")
/* long list example with list callback functions */
MUI_FORM(17)
@ -700,7 +682,7 @@ MUI_LABEL(5,43, "List [mud]:")
MUI_XYA("L2",60, 43, 60)
MUI_XYAT("G1",64, 59, 2, " OK ")
MUI_XYAT("G1",64, 59, 0, " OK ")
/* parent / child selection */
MUI_FORM(18)
@ -711,7 +693,7 @@ MUI_STYLE(0)
MUI_LABEL(5,29, "Animal:")
MUI_XYA("LP",50, 29, 19) /* jump to sub form 19 */
MUI_XYAT("G1",64, 59, 2, " OK ")
MUI_XYAT("G1",64, 59, 0, " OK ")
/* combo box color selection */
MUI_FORM(19)
@ -736,7 +718,7 @@ MUI_LABEL(5,35, "LED off:")
MUI_XY("AF",76, 35)
MUI_LABEL(5,46, "LED on:")
MUI_XY("AN",76, 46)
MUI_XYAT("G1",64, 59, 2, " OK ")
MUI_XYAT("G1",64, 59, 0, " OK ")
/* combo box Food & Drink Selection, called from form 11 */

View File

@ -267,7 +267,8 @@ muif_t muif_list[] MUI_PROGMEM = {
/* horizontal line (hrule) */
MUIF_RO("HR", mui_hrule),
MUIF_LABEL(mui_u8g2_draw_text),
/* read only fixed text */
MUIF_U8G2_LABEL(),
MUIF_RO("GP",mui_u8g2_goto_data),
MUIF_BUTTON("GC", mui_u8g2_goto_form_w1_mse_pi),
@ -348,7 +349,8 @@ MUI_DATA("GP",
MUI_80 "uint16 ParentChild Select|"
MUI_90 "uint8 Bar Graph|"
MUI_18 "Parent/Child List|"
MUI_20 "Array Edit")
MUI_20 "Array Edit|"
MUI_16 "Goto Test")
MUI_XYA("GC", 5, 25, 0)
MUI_XYA("GC", 5, 37, 1)
MUI_XYA("GC", 5, 49, 2)
@ -416,6 +418,9 @@ MUI_XYAT("G3", 96, 42, 10, "Btn 2")
MUI_GOTO(64, 59, 10, " Ok ")
MUI_FORM(16)
MUI_STYLE(0)
MUI_GOTO(64, 59, 1, " Back ")