MUI_DATA
This commit is contained in:
parent
1dc24f2b08
commit
aee6247168
49
csrc/mui.c
49
csrc/mui.c
|
@ -103,6 +103,7 @@ static size_t mui_fds_get_cmd_size_without_text(fds_t *s)
|
|||
{
|
||||
case 'U': return 2;
|
||||
case 'S': return 2;
|
||||
case 'D': return 3; // CMD, ID (2 Bytes), Text (does not count here)
|
||||
case 'F': return 5; // CMD, ID (2 Bytes), X, Y
|
||||
case 'B': return 5; // CMD, ID (2 Bytes), X, Y, Text (does not count here)
|
||||
case 'T': return 6; // CMD, ID (2 Bytes), X, Y, Arg, Text (does not count here)
|
||||
|
@ -371,6 +372,11 @@ static uint8_t mui_prepare_current_field(mui_t *ui)
|
|||
ui->arg = mui_get_fds_char(ui->fds+5);
|
||||
}
|
||||
}
|
||||
else if ( ui->cmd == 'D' )
|
||||
{
|
||||
ui->id0 = mui_get_fds_char(ui->fds+1);
|
||||
ui->id1 = mui_get_fds_char(ui->fds+2);
|
||||
}
|
||||
else if ( ui->cmd == 'S' )
|
||||
{
|
||||
ui->id0 = 'S';
|
||||
|
@ -646,7 +652,9 @@ void mui_next_field(mui_t *ui)
|
|||
nth_token can be 0 if the fiel text is not a option list
|
||||
the result is stored in ui->text
|
||||
*/
|
||||
void mui_GetSelectableFieldTextOption(mui_t *ui, uint8_t form_id, uint8_t cursor_position, uint8_t nth_token)
|
||||
/* OBSOLETE */
|
||||
#ifdef OBSOLETE
|
||||
void mui_GetSelectableFieldTextOptionByCursorPosition(mui_t *ui, uint8_t form_id, uint8_t cursor_position, uint8_t nth_token)
|
||||
{
|
||||
fds_t *fds = ui->fds; // backup the current fds, so that this function can be called inside a task loop
|
||||
int len = ui->len; // backup length of the current command
|
||||
|
@ -667,12 +675,30 @@ void mui_GetSelectableFieldTextOption(mui_t *ui, uint8_t form_id, uint8_t cursor
|
|||
ui->len = len;
|
||||
// result is stored in ui->text
|
||||
}
|
||||
#endif
|
||||
|
||||
void mui_GetSelectableFieldTextOption(mui_t *ui, fds_t *fds, uint8_t nth_token)
|
||||
{
|
||||
fds_t *fds_backup = ui->fds; // backup the current fds, so that this function can be called inside a task loop
|
||||
int len = ui->len; // backup length of the current command, 26 sep 2021: probably this is not required any more
|
||||
|
||||
ui->fds = fds;
|
||||
// at this point ui->fds contains the field which contains the tokens
|
||||
// now get the opion string out of the text field. nth_token can be 0 if this is no opion string
|
||||
mui_fds_get_nth_token(ui, nth_token); // return value is ignored here
|
||||
|
||||
ui->fds = fds_backup; // restore the previous fds position
|
||||
ui->len = len;
|
||||
// result is stored in ui->text
|
||||
}
|
||||
|
||||
/*
|
||||
this function will overwrite the ui field related member variables
|
||||
return the number of options in the referenced field
|
||||
*/
|
||||
uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, uint8_t form_id, uint8_t cursor_position)
|
||||
/* OBSOLETE */
|
||||
#ifdef OBSOLETE
|
||||
uint8_t mui_GetSelectableFieldOptionCntByCursorPosition(mui_t *ui, uint8_t form_id, uint8_t cursor_position)
|
||||
{
|
||||
fds_t *fds = ui->fds; // backup the current fds, so that this function can be called inside a task loop
|
||||
int len = ui->len; // backup length of the current command
|
||||
|
@ -694,6 +720,24 @@ uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, uint8_t form_id, uint8_t curs
|
|||
// result is stored in ui->text
|
||||
return cnt;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, fds_t *fds)
|
||||
{
|
||||
fds_t *fds_backup = ui->fds; // backup the current fds, so that this function can be called inside a task loop
|
||||
int len = ui->len; // backup length of the current command 26 sep 2021: probably this is not required any more
|
||||
uint8_t cnt = 0;
|
||||
|
||||
ui->fds = fds;
|
||||
// at this point ui->fds contains the field which contains the tokens
|
||||
// now get the opion string out of the text field. nth_token can be 0 if this is no opion string
|
||||
cnt = mui_fds_get_token_cnt(ui);
|
||||
|
||||
ui->fds = fds_backup; // restore the previous fds position
|
||||
ui->len = len;
|
||||
// result is stored in ui->text
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -781,6 +825,7 @@ void mui_SaveForm(mui_t *ui)
|
|||
if ( mui_IsFormActive(ui) == 0 )
|
||||
return;
|
||||
|
||||
ui->last_form_fds = ui->cursor_focus_fds;
|
||||
ui->last_form_id = mui_get_fds_char(ui->current_form_fds+1);
|
||||
ui->last_form_cursor_focus_position = mui_GetCurrentCursorFocusPosition(ui);
|
||||
}
|
||||
|
|
14
csrc/mui.h
14
csrc/mui.h
|
@ -215,9 +215,10 @@ struct mui_struct
|
|||
fds_t *tmp_fds;
|
||||
fds_t *target_fds; // used by several task functions as a return / result value
|
||||
|
||||
/* last form and field */
|
||||
/* last form and field, used by mui_SaveForm and mui_RestoreForm */
|
||||
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
|
||||
} ;
|
||||
|
||||
#define mui_IsCursorFocus(mui) ((mui)->dflags & MUIF_DFLAG_IS_CURSOR_FOCUS)
|
||||
|
@ -491,6 +492,7 @@ struct mui_struct
|
|||
/* style: one id only */
|
||||
#define MUI_STYLE(n) "S" #n
|
||||
|
||||
#define MUI_DATA(id, text) "D" id "\xff" text "\xff"
|
||||
|
||||
#define MUI_XY(id, x, y) "F" id MUI_##x MUI_##y
|
||||
/* button id must be two chars, but must be unique everywhere */
|
||||
|
@ -513,10 +515,10 @@ uint8_t mui_fds_get_token_cnt(mui_t *ui) MUI_NOINLINE;
|
|||
void mui_Init(mui_t *ui, void *graphics_data, fds_t *fds, muif_t *muif_tlist, size_t muif_tcnt);
|
||||
uint8_t mui_GetCurrentCursorFocusPosition(mui_t *ui) ;
|
||||
void mui_Draw(mui_t *ui);
|
||||
/* warning: The next function will overwrite the ui field variables like ui->arg, etc */
|
||||
void mui_GetSelectableFieldTextOption(mui_t *ui, uint8_t form_id, uint8_t cursor_position, uint8_t nth_token);
|
||||
/* warning: The next function will overwrite the ui field variables like ui->arg, etc */
|
||||
uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, uint8_t form_id, uint8_t cursor_position);
|
||||
/* warning: The next function will overwrite the ui field variables like ui->arg, etc. 26 sep 2021: only ui->text is modified */
|
||||
void mui_GetSelectableFieldTextOption(mui_t *ui, fds_t *fds, uint8_t nth_token);
|
||||
/* warning: The next function will overwrite the ui field variables like ui->arg, etc 26 sep 2021: only ui->text is modified*/
|
||||
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);
|
||||
|
@ -526,6 +528,8 @@ 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
|
||||
|
|
|
@ -1059,6 +1059,7 @@ uint8_t mui_u8g2_u8_opt_parent_wm_mse_pi(mui_t *ui, uint8_t msg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint8_t mui_u8g2_u8_opt_child_mse_common(mui_t *ui, uint8_t msg)
|
||||
{
|
||||
uint8_t *value = (uint8_t *)muif_get_data(ui->uif);
|
||||
|
@ -1075,7 +1076,7 @@ uint8_t mui_u8g2_u8_opt_child_mse_common(mui_t *ui, uint8_t msg)
|
|||
if ( ui->form_scroll_visible <= arg )
|
||||
ui->form_scroll_visible = arg+1;
|
||||
if ( ui->form_scroll_total == 0 )
|
||||
ui->form_scroll_total = mui_GetSelectableFieldOptionCnt(ui, ui->last_form_id, ui->last_form_cursor_focus_position);
|
||||
ui->form_scroll_total = mui_GetSelectableFieldOptionCnt(ui, ui->last_form_fds);
|
||||
//printf("MUIF_MSG_FORM_START: arg=%d visible=%d top=%d total=%d\n", arg, ui->form_scroll_visible, ui->form_scroll_top, ui->form_scroll_total);
|
||||
break;
|
||||
case MUIF_MSG_FORM_END:
|
||||
|
@ -1083,7 +1084,8 @@ uint8_t mui_u8g2_u8_opt_child_mse_common(mui_t *ui, uint8_t msg)
|
|||
case MUIF_MSG_CURSOR_ENTER:
|
||||
break;
|
||||
case MUIF_MSG_CURSOR_SELECT:
|
||||
*value = ui->form_scroll_top + arg;
|
||||
if ( value != NULL )
|
||||
*value = ui->form_scroll_top + arg;
|
||||
mui_RestoreForm(ui);
|
||||
break;
|
||||
case MUIF_MSG_CURSOR_LEAVE:
|
||||
|
@ -1148,7 +1150,7 @@ uint8_t mui_u8g2_u8_opt_radio_child_wm_mse_pi(mui_t *ui, uint8_t msg)
|
|||
{
|
||||
/* if the text is not provided, then try to get the text from the previous (saved) element, assuming that this contains the selection */
|
||||
/* this will overwrite all ui member functions, so we must not access any ui members (except ui->text) any more */
|
||||
mui_GetSelectableFieldTextOption(ui, ui->last_form_id, ui->last_form_cursor_focus_position, arg + ui->form_scroll_top);
|
||||
mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top);
|
||||
}
|
||||
|
||||
if ( ui->text[0] != '\0' )
|
||||
|
@ -1194,7 +1196,7 @@ uint8_t mui_u8g2_u8_opt_radio_child_w1_mse_pi(mui_t *ui, uint8_t msg)
|
|||
{
|
||||
/* if the text is not provided, then try to get the text from the previous (saved) element, assuming that this contains the selection */
|
||||
/* this will overwrite all ui member functions, so we must not access any ui members (except ui->text) any more */
|
||||
mui_GetSelectableFieldTextOption(ui, ui->last_form_id, ui->last_form_cursor_focus_position, arg + ui->form_scroll_top);
|
||||
mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top);
|
||||
}
|
||||
|
||||
if ( ui->text[0] != '\0' )
|
||||
|
@ -1240,7 +1242,7 @@ uint8_t mui_u8g2_u8_opt_child_wm_mse_pi(mui_t *ui, uint8_t msg)
|
|||
{
|
||||
/* if the text is not provided, then try to get the text from the previous (saved) element, assuming that this contains the selection */
|
||||
/* this will overwrite all ui member functions, so we must not access any ui members (except ui->text) any more */
|
||||
mui_GetSelectableFieldTextOption(ui, ui->last_form_id, ui->last_form_cursor_focus_position, arg + ui->form_scroll_top);
|
||||
mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top);
|
||||
}
|
||||
if ( ui->text[0] != '\0' )
|
||||
{
|
||||
|
@ -1254,6 +1256,58 @@ uint8_t mui_u8g2_u8_opt_child_wm_mse_pi(mui_t *ui, uint8_t msg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
an invisible field (which will not show anything). It should also not be selectable
|
||||
it just provides the menu entries, see "mui_u8g2_u8_opt_child_mse_common" and friends
|
||||
as a consequence it does not have width, input mode and style
|
||||
*/
|
||||
uint8_t mui_u8g2_goto_parent(mui_t *ui, uint8_t msg)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case MUIF_MSG_DRAW:
|
||||
break;
|
||||
case MUIF_MSG_FORM_START:
|
||||
// store the field (and the corresponding elements) in the last_form_fds variable.
|
||||
// last_form_fds is later used to access the elements (see mui_u8g2_u8_opt_child_mse_common and friends)
|
||||
ui->last_form_fds = ui->fds;
|
||||
break;
|
||||
case MUIF_MSG_FORM_END:
|
||||
break;
|
||||
case MUIF_MSG_CURSOR_ENTER:
|
||||
break;
|
||||
case MUIF_MSG_CURSOR_SELECT:
|
||||
break;
|
||||
case MUIF_MSG_CURSOR_LEAVE:
|
||||
break;
|
||||
case MUIF_MSG_TOUCH_DOWN:
|
||||
break;
|
||||
case MUIF_MSG_TOUCH_UP:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint8_t mui_u8g2_goto_child_w1_mse_pi(mui_t *ui, uint8_t msg)
|
||||
{
|
||||
u8g2_t *u8g2 = mui_get_U8g2(ui);
|
||||
uint8_t arg = ui->arg; // remember the arg value, because it might be overwritten
|
||||
switch(msg)
|
||||
{
|
||||
case MUIF_MSG_DRAW:
|
||||
mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, arg + ui->form_scroll_top);
|
||||
mui_u8g2_draw_button_pi(ui, u8g2_GetDisplayWidth(u8g2)-mui_get_x(ui)*2, mui_get_x(ui), ui->text+1);
|
||||
break;
|
||||
case MUIF_MSG_CURSOR_SELECT:
|
||||
mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, ui->arg + ui->form_scroll_top);
|
||||
return mui_GotoForm(ui, (uint8_t)ui->text[0], 0);
|
||||
default:
|
||||
return mui_u8g2_u8_opt_child_mse_common(ui, msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
data: mui_u8g2_list_t *
|
||||
|
@ -1414,7 +1468,8 @@ static uint8_t mui_u8g2_u16_list_child_mse_common(mui_t *ui, uint8_t msg)
|
|||
case MUIF_MSG_CURSOR_ENTER:
|
||||
break;
|
||||
case MUIF_MSG_CURSOR_SELECT:
|
||||
*selection = ui->form_scroll_top + arg;
|
||||
if ( selection != NULL )
|
||||
*selection = ui->form_scroll_top + arg;
|
||||
mui_RestoreForm(ui);
|
||||
break;
|
||||
case MUIF_MSG_CURSOR_LEAVE:
|
||||
|
|
|
@ -135,7 +135,10 @@ uint8_t mui_u8g2_u8_opt_line_wa_mud_pi(mui_t *ui, uint8_t msg);
|
|||
uint8_t mui_u8g2_u8_opt_parent_wm_mse_pi(mui_t *ui, uint8_t msg);
|
||||
uint8_t mui_u8g2_u8_opt_radio_child_wm_mse_pi(mui_t *ui, uint8_t msg);
|
||||
uint8_t mui_u8g2_u8_opt_radio_child_w1_mse_pi(mui_t *ui, uint8_t msg);
|
||||
uint8_t mui_u8g2_u8_opt_child_wm_mse_pi(mui_t *ui, uint8_t msg);
|
||||
uint8_t mui_u8g2_u8_opt_child_wm_mse_pi(mui_t *ui, uint8_t msg); /* like mui_u8g2_u8_opt_radio_child_wm_mse_pi, but without radio button */
|
||||
|
||||
uint8_t mui_u8g2_goto_parent(mui_t *ui, uint8_t msg); /* MUIF_RO */
|
||||
uint8_t mui_u8g2_goto_child_w1_mse_pi(mui_t *ui, uint8_t msg); /* MUIF_BUTTON, MUI_XYA */
|
||||
|
||||
uint8_t mui_u8g2_u8_chkbox_wm_pi(mui_t *ui, uint8_t msg);
|
||||
uint8_t mui_u8g2_u8_radio_wm_pi(mui_t *ui, uint8_t msg);
|
||||
|
|
Loading…
Reference in New Issue