This commit is contained in:
kraus 2021-09-26 15:32:45 +02:00
parent 92e3c7b538
commit ae3c8d4cc4
5 changed files with 293 additions and 60 deletions

View File

@ -101,24 +101,22 @@ static size_t mui_fds_get_cmd_size_without_text(fds_t *s)
c &= 0xdf; /* consider upper and lower case */
switch(c)
{
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)
case 'A': return 6; // CMD, ID (2 Bytes), X, Y, Arg, Text
case 'L': return 3;
//case 'M': return 4;
//case 'X': return 3;
//case 'J': return 4;
case 'G': return 4;
case 'U': return 2; // User Form: CMD (1 Byte), Form-Id (1 Byte)
case 'S': return 2; // Style: CMD (1 Byte), Style Id (1 Byte)
case 'D': return 3; // Data within Text: CMD (1 Byte), ID (2 Bytes), Text (does not count here)
case 'F': return 5; // Field without arg & text: CMD (1 Byte), ID (2 Bytes), X, Y
case 'B': return 5; // Field with text: CMD (1 Byte), ID (2 Bytes), X, Y, Text (does not count here)
case 'T': return 6; // Field with arg & text: CMD (1 Byte), ID (2 Bytes), X, Y, Arg, Text (does not count here)
case 'A': return 6; // Field with arg (no text): CMD (1 Byte), ID (2 Bytes), X, Y, Arg, Text
case 'L': return 3; // Text Label: CMD (1 Byte), X, Y (same as 'B' but with fixed ID '.L', MUIF_LABEL, MUI_LABEL)
case 'G': return 4; // Goto Btutton: CMD (1Byte), X, Y, Arg, Text (same as 'T' but with fixed ID '.G', MUIF_GOTO, MUI_GOTO)
case 0: return 0;
}
return 1;
}
/*
s must point to the string delimiter start: first '/' for "B00ab/ok/"
- '/' actually is 0xff
@ -677,19 +675,21 @@ void mui_GetSelectableFieldTextOptionByCursorPosition(mui_t *ui, uint8_t form_id
}
#endif
void mui_GetSelectableFieldTextOption(mui_t *ui, fds_t *fds, uint8_t nth_token)
uint8_t 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
uint8_t is_found;
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
is_found = 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
return is_found;
}
/*
@ -742,10 +742,10 @@ uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, fds_t *fds)
//static void mui_send_cursor_enter_msg(mui_t *ui) MUI_NOINLINE;
static void mui_send_cursor_enter_msg(mui_t *ui)
static uint8_t mui_send_cursor_enter_msg(mui_t *ui)
{
ui->is_mud = 0;
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_ENTER);
return mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_ENTER);
}
/*
@ -785,7 +785,10 @@ void mui_EnterForm(mui_t *ui, fds_t *fds, uint8_t initial_cursor_position)
initial_cursor_position--;
}
mui_send_cursor_enter_msg(ui);
while( mui_send_cursor_enter_msg(ui) == 255 )
{
mui_NextField(ui); // mui_next_field(ui) is not sufficient in case of scrolling
}
}
/* input: current_form_fds */
@ -846,11 +849,13 @@ void mui_RestoreForm(mui_t *ui)
*/
void mui_NextField(mui_t *ui)
{
if ( mui_send_cursor_msg(ui, MUIF_MSG_EVENT_NEXT) )
return;
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
mui_next_field(ui);
mui_send_cursor_enter_msg(ui);
do
{
if ( mui_send_cursor_msg(ui, MUIF_MSG_EVENT_NEXT) )
return;
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
mui_next_field(ui);
} while ( mui_send_cursor_enter_msg(ui) == 255 );
}
/*
@ -861,21 +866,21 @@ void mui_NextField(mui_t *ui)
*/
void mui_PrevField(mui_t *ui)
{
if ( mui_send_cursor_msg(ui, MUIF_MSG_EVENT_PREV) )
return;
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
mui_loop_over_form(ui, mui_task_find_prev_cursor_uif);
//ui->cursor_focus_position--;
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
if ( ui->target_fds == NULL )
do
{
//ui->cursor_focus_position = 0;
mui_loop_over_form(ui, mui_task_find_last_cursor_uif);
if ( mui_send_cursor_msg(ui, MUIF_MSG_EVENT_PREV) )
return;
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
mui_loop_over_form(ui, mui_task_find_prev_cursor_uif);
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
}
mui_send_cursor_enter_msg(ui);
if ( ui->target_fds == NULL )
{
//ui->cursor_focus_position = 0;
mui_loop_over_form(ui, mui_task_find_last_cursor_uif);
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
}
} while( mui_send_cursor_enter_msg(ui) == 255 );
}

View File

@ -151,12 +151,15 @@ struct muif_struct
#define MUIF_MSG_DRAW 1
#define MUIF_MSG_FORM_START 2
#define MUIF_MSG_FORM_END 3
/* MUIF_MSG_CURSOR_ENTER return values: 255=skip this field, <255, continue*/
#define MUIF_MSG_CURSOR_ENTER 4
#define MUIF_MSG_CURSOR_SELECT 5
#define MUIF_MSG_CURSOR_LEAVE 6
#define MUIF_MSG_TOUCH_DOWN 7
#define MUIF_MSG_TOUCH_UP 8
/* MUIF_MSG_EVENT_NEXT return values: 0=not handled, 1=handled, do nothing */
#define MUIF_MSG_EVENT_NEXT 9
/* MUIF_MSG_EVENT_PREV return values: 0=not handled, 1=handled, do nothing */
#define MUIF_MSG_EVENT_PREV 10
/* dynamic flags */
@ -169,7 +172,7 @@ struct muif_struct
/* must be smaller than or equal to 255 */
#define MUI_MAX_TEXT_LEN 31
#define MUI_MAX_TEXT_LEN 41
struct mui_struct
{
@ -516,7 +519,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);
/* 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);
uint8_t 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);

View File

@ -1082,6 +1082,8 @@ uint8_t mui_u8g2_u8_opt_child_mse_common(mui_t *ui, uint8_t msg)
case MUIF_MSG_FORM_END:
break;
case MUIF_MSG_CURSOR_ENTER:
if ( ui->form_scroll_top + arg >= ui->form_scroll_total )
return 255;
break;
case MUIF_MSG_CURSOR_SELECT:
if ( value != NULL )
@ -1289,6 +1291,7 @@ uint8_t mui_u8g2_goto_parent(mui_t *ui, uint8_t msg)
}
uint8_t mui_u8g2_goto_child_w1_mse_pi(mui_t *ui, uint8_t msg)
{
u8g2_t *u8g2 = mui_get_U8g2(ui);
@ -1296,12 +1299,13 @@ uint8_t mui_u8g2_goto_child_w1_mse_pi(mui_t *ui, uint8_t msg)
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);
if ( 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);
if ( mui_GetSelectableFieldTextOption(ui, ui->last_form_fds, ui->arg + ui->form_scroll_top) )
return mui_GotoForm(ui, (uint8_t)ui->text[0], 0);
break;
default:
return mui_u8g2_u8_opt_child_mse_common(ui, msg);
}

View File

@ -96,8 +96,6 @@ typedef const struct mui_u8g2_u8_min_max_struct mui_u8g2_u8_min_max_t;
#endif
/* helper functions */
u8g2_uint_t mui_get_x(mui_t *ui);

View File

@ -16,6 +16,13 @@ mui_t ui;
/*
global variables which form the communication gateway between the user interface and the rest of the code
*/
uint8_t number_input9 = 2; // variable where the user can input a number between 0 and 9
uint8_t number_input99 = 95; // variable where the user can input a number between 0 and 99
uint8_t chkbox1_input = 0;
uint8_t chkbox2_input = 0;
uint8_t radio_input = 0;
uint8_t number_input = 2; // variable where the user can input a number between 0 and 9
uint8_t number_input2 = 100; // variable where the user can input a number between 0 and 9
uint8_t fruit_input = 2;
@ -95,6 +102,35 @@ uint8_t mui_style_streamline_food_drink(mui_t *ui, uint8_t msg)
return 0;
}
uint8_t mui_style_small(mui_t *ui, uint8_t msg)
{
u8g2_t *u8g2 = mui_get_U8g2(ui);
switch(msg)
{
case MUIF_MSG_DRAW:
u8g2_SetFont(u8g2, u8g2_font_blipfest_07_tr );
//u8g2_SetFont(u8g2, u8g2_font_u8glib_4_tr );
break;
}
return 0;
}
uint8_t mui_style_streamline_interface_essential_login(mui_t *ui, uint8_t msg)
{
u8g2_t *u8g2 = mui_get_U8g2(ui);
switch(msg)
{
case MUIF_MSG_DRAW:
u8g2_SetFont(u8g2, u8g2_font_streamline_interface_essential_login_t);
//u8g2_SetFont(u8g2, u8g2_font_6x10_tr);
break;
}
return 0;
}
/*=================================================*/
/* local mui functions */
@ -192,22 +228,44 @@ muif_t muif_list[] MUI_PROGMEM = {
/* bold text style */
MUIF_STYLE(1, mui_style_helv_b_08),
/* very small font */
MUIF_STYLE(2, mui_style_small),
MUIF_STYLE(3, mui_style_streamline_interface_essential_login),
/* monospaced font */
MUIF_STYLE(2, mui_style_monospaced),
//MUIF_STYLE(3, mui_style_monospaced),
/* food and drink */
MUIF_STYLE(3, mui_style_streamline_food_drink),
//MUIF_STYLE(4, mui_style_streamline_food_drink),
/* horizontal line (hrule) */
MUIF_RO("HR", mui_hrule),
MUIF_LABEL(mui_u8g2_draw_text),
MUIF_U8G2_U16_LIST("LG", &list_selection4, NULL, menu_get_str, menu_get_cnt, mui_u8g2_u16_list_goto_w1_mse_pi),
MUIF_RO("GP",mui_u8g2_goto_parent),
MUIF_BUTTON("GC", mui_u8g2_goto_child_w1_mse_pi),
/* Form 10 */
MUIF_GOTO(mui_u8g2_btn_goto_wm_fi),
MUIF_BUTTON("G0", mui_u8g2_btn_goto_wm_fi),
MUIF_BUTTON("G1", mui_u8g2_btn_goto_w1_pi),
MUIF_BUTTON("G2", mui_u8g2_btn_goto_w2_fi),
/* Form 20 */
MUIF_U8G2_U8_MIN_MAX("N0", &number_input9, 0, 9, mui_u8g2_u8_min_max_wm_mse_pi),
MUIF_U8G2_U8_MIN_MAX("N1", &number_input99, 0, 99, mui_u8g2_u8_min_max_wm_mud_pi),
MUIF_U8G2_U8_MIN_MAX("N2", &number_input9, 0, 9, mui_u8g2_u8_min_max_wm_mse_pf),
MUIF_U8G2_U8_MIN_MAX("N3", &number_input99, 0, 99, mui_u8g2_u8_min_max_wm_mud_pf),
/* Form 30 */
MUIF_VARIABLE("C1",&chkbox1_input,mui_u8g2_u8_chkbox_wm_pi),
MUIF_VARIABLE("C2",&chkbox2_input,mui_u8g2_u8_chkbox_wm_pi),
MUIF_VARIABLE("RB",&radio_input,mui_u8g2_u8_radio_wm_pi),
};
@ -218,25 +276,190 @@ MUI_STYLE(1)
MUI_LABEL(5,10, "MUI Elements")
MUI_XY("HR", 0,13)
MUI_STYLE(0)
MUI_XYA("LG", 5, 25, 0)
MUI_XYA("LG", 5, 37, 1)
MUI_XYA("LG", 5, 49, 2)
MUI_XYA("LG", 5, 61, 3)
MUI_FORM(10)
MUI_STYLE(1)
MUI_LABEL(5,10, "U8 Input")
MUI_XY("HR", 0,13)
MUI_STYLE(0)
MUI_DATA("GP", MUI_1 "aaa|" MUI_1 "bbb|" MUI_1 "ccc|" MUI_1 "ddd|" MUI_1 "eee" )
MUI_DATA("GP",
MUI_10 "Goto Buttons|"
MUI_20 "uint8 Input|"
MUI_30 "Checkbox/Radiobutton|"
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_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(10)
MUI_STYLE(1)
MUI_LABEL(5,10, "Goto Buttons")
MUI_XY("HR", 0,13)
MUI_STYLE(0)
MUI_DATA("GP",
MUI_11 "btn_goto_wm_fi|"
MUI_12 "btn_goto_w1_pi|"
MUI_13 "btn_goto_w2_fi|"
MUI_1 "Back to Main 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(11)
MUI_STYLE(2)
MUI_LABEL(1,5, "mui_u8g2_btn_goto_wm_fi")
MUI_LABEL(1,12, "MUIF_GOTO, MUIF_BUTTON")
MUI_LABEL(1,19, "MUI_GOTO, MUI_XYAT")
MUI_LABEL(1,25, "Centered button, jumps to form")
MUI_XY("HR", 0,26)
MUI_STYLE(0)
MUI_GOTO(64, 42, 10, "Button")
MUI_GOTO(64, 59, 10, " Ok ")
MUI_FORM(12)
MUI_STYLE(2)
MUI_LABEL(1,5, "mui_u8g2_btn_goto_w1_pi")
MUI_LABEL(1,12, "MUIF_GOTO, MUIF_BUTTON")
MUI_LABEL(1,19, "MUI_GOTO, MUI_XYAT")
MUI_LABEL(1,25, "Full width button without frame")
MUI_XY("HR", 0,26)
MUI_STYLE(0)
MUI_XYAT("G1", 1, 42, 10, "Button")
MUI_GOTO(64, 59, 10, " Ok ")
MUI_FORM(13)
MUI_STYLE(2)
MUI_LABEL(1,5, "mui_u8g2_btn_goto_w2_fi")
MUI_LABEL(1,12, "MUIF_GOTO, MUIF_BUTTON")
MUI_LABEL(1,19, "MUI_GOTO, MUI_XYAT")
MUI_LABEL(1,25, "Centered half display width button")
MUI_XY("HR", 0,26)
MUI_STYLE(0)
MUI_XYAT("G2", 32, 42, 10, "Btn 1")
MUI_XYAT("G2", 96, 42, 10, "Btn 2")
MUI_GOTO(64, 59, 10, " Ok ")
MUI_FORM(20)
MUI_STYLE(1)
MUI_LABEL(5,10, "uint8 Input")
MUI_XY("HR", 0,13)
MUI_STYLE(0)
MUI_DATA("GP",
MUI_21 "u8_min_max_wm_mse_pi|"
MUI_22 "u8_min_max_wm_mud_pi|"
MUI_23 "u8_min_max_wm_mse_pf|"
MUI_24 "u8_min_max_wm_mud_pf|"
MUI_1 "Back to Main 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(21)
MUI_STYLE(2)
MUI_LABEL(1,5, "mui_u8g2_u8_min_max_wm_mse_pi")
MUI_LABEL(1,12, "MUIF_U8G2_U8_MIN_MAX")
MUI_LABEL(1,19, "MUI_XY")
MUI_LABEL(1,25, "Input for uint8_t number")
MUI_XY("HR", 0,26)
MUI_STYLE(0)
MUI_LABEL(1,40, "Number: ")
MUI_XY("N0",70, 40)
MUI_GOTO(64, 59, 20, " Ok ")
MUI_FORM(22)
MUI_STYLE(2)
MUI_LABEL(1,5, "mui_u8g2_u8_min_max_wm_mud_pi")
MUI_LABEL(1,12, "MUIF_U8G2_U8_MIN_MAX")
MUI_LABEL(1,19, "MUI_XY")
MUI_LABEL(1,25, "Input for uint8_t number")
MUI_XY("HR", 0,26)
MUI_STYLE(0)
MUI_LABEL(1,40, "Number: ")
MUI_XY("N1",70, 40)
MUI_GOTO(64, 59, 20, " Ok ")
MUI_FORM(23)
MUI_STYLE(2)
MUI_LABEL(1,5, "mui_u8g2_u8_min_max_wm_mse_pf")
MUI_LABEL(1,12, "MUIF_U8G2_U8_MIN_MAX")
MUI_LABEL(1,19, "MUI_XY")
MUI_LABEL(1,25, "Input for uint8_t number")
MUI_XY("HR", 0,26)
MUI_STYLE(0)
MUI_LABEL(1,40, "Number: ")
MUI_XY("N2",70, 40)
MUI_GOTO(64, 59, 20, " Ok ")
MUI_FORM(24)
MUI_STYLE(2)
MUI_LABEL(1,5, "mui_u8g2_u8_min_max_wm_mud_pf")
MUI_LABEL(1,12, "MUIF_U8G2_U8_MIN_MAX")
MUI_LABEL(1,19, "MUI_XY")
MUI_LABEL(1,25, "Input for uint8_t number")
MUI_XY("HR", 0,26)
MUI_STYLE(0)
MUI_LABEL(1,40, "Number: ")
MUI_XY("N3",70, 40)
MUI_GOTO(64, 59, 20, " Ok ")
MUI_FORM(30)
MUI_STYLE(1)
MUI_LABEL(5,10, "uint8 Input")
MUI_XY("HR", 0,13)
MUI_STYLE(0)
MUI_DATA("GP",
MUI_31 "u8_chkbox_wm_pi|"
MUI_32 "u8_radio_wm_pi|"
MUI_1 "Back to Main 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(31)
MUI_STYLE(2)
MUI_LABEL(1,5, "mui_u8g2_u8_chkbox_wm_pi")
MUI_LABEL(1,12, "MUIF_VARIABLE")
MUI_LABEL(1,19, "MUI_XY")
MUI_LABEL(1,25, "Checkbox, values 0 and 1, uint8_t)")
MUI_XY("HR", 0,26)
MUI_STYLE(0)
MUI_LABEL(1,40, "Checkbox 1: ")
MUI_XY("C1",66, 40)
MUI_LABEL(1,55, "Checkbox 2: ")
MUI_XY("C2",66, 55)
MUI_STYLE(3)
MUI_GOTO(110, 54, 30, "\x31")
MUI_FORM(32)
MUI_STYLE(2)
MUI_LABEL(1,5, "mui_u8g2_u8_radio_wm_pi")
MUI_LABEL(1,12, "MUIF_VARIABLE")
MUI_LABEL(1,19, "MUI_XYA, MUI_XYAT")
MUI_LABEL(1,25, "Radio buttons, assign arg to variable")
MUI_XY("HR", 0,26)
MUI_STYLE(0)
MUI_XYAT("RB", 1, 40, 1, "Radio 1")
MUI_XYAT("RB", 1, 55, 2, "Radio 2")
MUI_STYLE(3)
MUI_GOTO(110, 54, 30, "\x31")
//MUIF_VARIABLE("C1",&chkbox1_input,mui_u8g2_u8_chkbox_wm_pi),
//MUIF_VARIABLE("C2",&chkbox2_input,mui_u8g2_u8_chkbox_wm_pi),
//MUIF_VARIABLE("RB",&radio_input,mui_u8g2_u8_radio_wm_pi),
;
muif_t muif_list_old[] MUI_PROGMEM = {
/* normal text style */
MUIF_STYLE(0, mui_style_helv_r_08),