update
This commit is contained in:
parent
6979324d07
commit
69ae0ac215
31
csrc/mui.c
31
csrc/mui.c
|
@ -282,12 +282,15 @@ static size_t mui_fds_get_cmd_size(mui_t *ui, fds_t *s)
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
mui_Init() will setup the menu system but will not activate or display anything.
|
||||
Use mui_GotoForm() after this command, then use mui_Draw() to draw the menu on a display.
|
||||
*/
|
||||
void mui_Init(mui_t *ui, void *graphics_data, fds_t *fds, muif_t *muif_tlist, size_t muif_tcnt)
|
||||
{
|
||||
memset(ui, 0, sizeof(mui_t));
|
||||
ui->root_fds = fds;
|
||||
ui->current_form_fds = fds;
|
||||
//ui->current_form_fds = NULL; // not required, because there was a memset before
|
||||
ui->muif_tlist = muif_tlist;
|
||||
ui->muif_tcnt = muif_tcnt;
|
||||
ui->graphics_data = graphics_data;
|
||||
|
@ -424,7 +427,7 @@ void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
|
|||
|
||||
void mui_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
|
||||
{
|
||||
if ( ui->current_form_fds == NULL )
|
||||
if ( mui_IsFormActive(ui) == 0 )
|
||||
return;
|
||||
|
||||
ui->fds = ui->current_form_fds;
|
||||
|
@ -635,15 +638,21 @@ void mui_GetSelectableFieldTextOption(mui_t *ui, uint8_t form_id, uint8_t cursor
|
|||
}
|
||||
|
||||
/*
|
||||
input: current_form_fds
|
||||
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
||||
mui_EnterForm is similar to mui_GotoForm and differes only in the second argument (which is the form id instead of the fds pointer)
|
||||
*/
|
||||
void mui_EnterForm(mui_t *ui, uint8_t initial_cursor_position)
|
||||
void mui_EnterForm(mui_t *ui, fds_t *fds, uint8_t initial_cursor_position)
|
||||
{
|
||||
/* exit any previous form, will not do anything if there is no current form */
|
||||
mui_LeaveForm(ui);
|
||||
|
||||
/* clean focus fields */
|
||||
ui->touch_focus_fds = NULL;
|
||||
ui->cursor_focus_fds = NULL;
|
||||
|
||||
/* assign the form, which should be entered */
|
||||
ui->current_form_fds = fds;
|
||||
|
||||
/* inform all fields that we start a new form */
|
||||
mui_loop_over_form(ui, mui_task_form_start);
|
||||
|
||||
|
@ -666,6 +675,9 @@ void mui_EnterForm(mui_t *ui, uint8_t initial_cursor_position)
|
|||
*/
|
||||
void mui_LeaveForm(mui_t *ui)
|
||||
{
|
||||
if ( mui_IsFormActive(ui) == 0 )
|
||||
return;
|
||||
|
||||
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
|
||||
ui->cursor_focus_fds = NULL;
|
||||
|
||||
|
@ -683,17 +695,16 @@ uint8_t mui_GotoForm(mui_t *ui, uint8_t form_id, uint8_t initial_cursor_position
|
|||
fds_t *fds = mui_find_form(ui, form_id);
|
||||
if ( fds == NULL )
|
||||
return 0;
|
||||
mui_LeaveForm(ui);
|
||||
ui->current_form_fds = fds;
|
||||
mui_EnterForm(ui, initial_cursor_position);
|
||||
/* EnterForm will also leave any previous form */
|
||||
mui_EnterForm(ui, fds, initial_cursor_position);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void mui_SaveForm(mui_t *ui)
|
||||
{
|
||||
if ( ui->current_form_fds == NULL )
|
||||
if ( mui_IsFormActive(ui) == 0 )
|
||||
return;
|
||||
|
||||
|
||||
ui->last_form_id = mui_get_fds_char(ui->current_form_fds+1);
|
||||
ui->last_form_cursor_focus_position = mui_GetCurrentCursorFocusPosition(ui);
|
||||
}
|
||||
|
|
|
@ -501,7 +501,7 @@ void mui_Init(mui_t *ui, void *graphics_data, fds_t *fds, muif_t *muif_tlist, si
|
|||
uint8_t mui_GetCurrentCursorFocusPosition(mui_t *ui);
|
||||
void mui_Draw(mui_t *ui);
|
||||
void mui_GetSelectableFieldTextOption(mui_t *ui, uint8_t form_id, uint8_t cursor_position, uint8_t nth_token);
|
||||
void mui_EnterForm(mui_t *ui, uint8_t initial_cursor_position);
|
||||
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);
|
||||
|
@ -510,6 +510,7 @@ void mui_NextField(mui_t *ui);
|
|||
void mui_PrevField(mui_t *ui);
|
||||
void mui_SendSelect(mui_t *ui);
|
||||
|
||||
#define mui_IsFormActive(ui) ((ui)->current_form_fds != NULL)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -520,7 +520,7 @@ void setup(void) {
|
|||
//u8g2.begin(/*Select=*/ 7, /*Right/Next=*/ A1, /*Left/Prev=*/ A2, /*Up=*/ A0, /*Down=*/ A3, /*Home/Cancel=*/ 8); // Arduboy 10 (Production)
|
||||
|
||||
mui_Init(&ui, u8g2.getU8g2(), fds_data, muif_list, sizeof(muif_list)/sizeof(muif_t));
|
||||
mui_EnterForm(&ui, 0);
|
||||
mui_GotoForm(&ui, /* form_id= */ 1, /* initial_cursor_position= */ 0);
|
||||
|
||||
}
|
||||
|
||||
|
@ -528,31 +528,41 @@ uint8_t is_redraw = 1;
|
|||
|
||||
void loop(void) {
|
||||
|
||||
/* draw the menu */
|
||||
/* check whether the menu is active */
|
||||
if ( mui_IsFormActive(&ui) )
|
||||
{
|
||||
|
||||
if ( is_redraw ) {
|
||||
u8g2.firstPage();
|
||||
do {
|
||||
mui_Draw(&ui);
|
||||
} while( u8g2.nextPage() );
|
||||
is_redraw = 0;
|
||||
/* if so, then draw the menu */
|
||||
|
||||
if ( is_redraw ) {
|
||||
u8g2.firstPage();
|
||||
do {
|
||||
mui_Draw(&ui);
|
||||
} while( u8g2.nextPage() );
|
||||
is_redraw = 0;
|
||||
}
|
||||
|
||||
/* handle events */
|
||||
|
||||
switch(u8g2.getMenuEvent()) {
|
||||
case U8X8_MSG_GPIO_MENU_SELECT:
|
||||
mui_SendSelect(&ui);
|
||||
is_redraw = 1;
|
||||
break;
|
||||
case U8X8_MSG_GPIO_MENU_NEXT:
|
||||
mui_NextField(&ui);
|
||||
is_redraw = 1;
|
||||
break;
|
||||
case U8X8_MSG_GPIO_MENU_PREV:
|
||||
mui_PrevField(&ui);
|
||||
is_redraw = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* handle events */
|
||||
|
||||
switch(u8g2.getMenuEvent()) {
|
||||
case U8X8_MSG_GPIO_MENU_SELECT:
|
||||
mui_SendSelect(&ui);
|
||||
is_redraw = 1;
|
||||
break;
|
||||
case U8X8_MSG_GPIO_MENU_NEXT:
|
||||
mui_NextField(&ui);
|
||||
is_redraw = 1;
|
||||
break;
|
||||
case U8X8_MSG_GPIO_MENU_PREV:
|
||||
mui_PrevField(&ui);
|
||||
is_redraw = 1;
|
||||
break;
|
||||
else
|
||||
{
|
||||
/* do something else, maybe clear the screen */
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue