Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
olikraus committed Aug 22, 2021
1 parent d90eef5 commit 50110df
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 34 deletions.
29 changes: 22 additions & 7 deletions sys/sdl/ui/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ui_t ui;
uint8_t my_value = 2;
uint8_t my_value2 = 2;
uint8_t my_value3 = 0;
uint8_t my_color = 0;

uint8_t touchscreen_selection = 255;

Expand All @@ -23,7 +24,11 @@ UIF("B0",UIF_CFLAG_IS_CURSOR_SELECTABLE,0,uif_half_width_frame_button_invers_sel
UIF("B1",UIF_CFLAG_IS_CURSOR_SELECTABLE,0,uif_half_width_frame_button_invers_select_u8g2),
UIF("I1",UIF_CFLAG_IS_CURSOR_SELECTABLE,&my_value,uif_input_uint8_invers_select_u8g2),
UIF("I2",UIF_CFLAG_IS_CURSOR_SELECTABLE,&my_value2,uif_single_line_option_invers_select_u8g2),
UIF("I3",UIF_CFLAG_IS_CURSOR_SELECTABLE,&my_value3,uif_checkbox_u8g2),
UIF("I3",UIF_CFLAG_IS_CURSOR_SELECTABLE,&my_value3,uif_checkbox_invers_select_u8g2),
UIF("I4",UIF_CFLAG_IS_CURSOR_SELECTABLE,&my_color,uif_show_option_goto_form_invers_select_u8g2),

UIF("O4",UIF_CFLAG_IS_CURSOR_SELECTABLE,&my_color,uif_assign_arg_go_back_invers_select_u8g2),

UIF("TS",UIF_CFLAG_IS_CURSOR_SELECTABLE,&touchscreen_selection,uif_single_line_option_invers_select_u8g2),
UIF(".G",UIF_CFLAG_IS_CURSOR_SELECTABLE,0,uif_goto_half_width_frame_button_invers_select_u8g2), /* UI_GOTO has the id FG */
UIF(".g",UIF_CFLAG_IS_CURSOR_SELECTABLE,0,uif_goto_line_button_invers_select_u8g2), /* UI_goto has the id Fg */
Expand All @@ -38,20 +43,30 @@ UI_goto(12,22,10, "Button Test")
UI_goto(12,34,101, "Story")

UI_FORM(2)
UI_LABEL(0,12, "Number:")
UI_F("I1",50, 12)
UI_LABEL(0,28, "Fruit:")
UI_A("I2",50, 28, 60, "Banana|Apple|Peach")
UI_LABEL(0,44, "Check:")
UI_LABEL(0,10, "Number:")
UI_F("I1",50, 10)
UI_LABEL(0,22, "Fruit:")
UI_A("I2",50, 22, 60, "Banana|Apple|Peach")
UI_LABEL(0,34, "Check:")
//UI_B("I3",50, 44, "ABCxyz")
UI_F("I3",50, 44)
UI_F("I3",50, 34)

UI_LABEL(0,46, "Color:")
UI_A("I4",50, 46, 4, "red|green|blue")


//UI_BUTTON("B1",32,50, "Ok")
UI_GOTO(32,60,3, "Goto 2")
UI_GOTO(96,60,1, "Home")

UI_FORM(3)
UI_goto(32,50,2, "Goto 1")

UI_FORM(4)
UI_A("O4", 2, 10, 0, "red")
UI_A("O4", 2, 22, 1, "green")
UI_A("O4", 2, 34, 2, "blue")

UI_FORM(10)
UI_goto(10,11,11, "Btn 1")
UI_goto(10,21,12, "Btn 2")
Expand Down
1 change: 1 addition & 0 deletions sys/sdl/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct ui_struct

fds_t token; // current token position

uint8_t selected_value; // This variable is not used by the user interface but can be used by any field function
uint8_t tmp8;
/* current field/style variables */
//uint8_t cursor_focus_position; // the index of the field which has focus, can be used as last argument for ui_EnterForm
Expand Down
240 changes: 214 additions & 26 deletions sys/sdl/ui/ui_u8g2.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,46 @@ void u8g2_DrawButtonUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t
}


void u8g2_DrawCheckbox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t is_checked)
{
u8g2_DrawFrame(u8g2, x, y-w, w, w);
if ( is_checked )
{
w-=4;
u8g2_DrawBox(u8g2, x+2, y-w-2, w, w);
}
}

void u8g2_DrawValueMark(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w)
{
u8g2_DrawBox(u8g2, x, y-w, w, w);
}


#ifdef NOT_USED
void u8g2_Draw4Pixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w)
{
u8g2_DrawPixel(u8g2, x,y-1);
u8g2_DrawPixel(u8g2, x+w-1,y-1);
u8g2_DrawPixel(u8g2, x+w-1,y-w);
u8g2_DrawPixel(u8g2, x,y-w);
}

void u8g2_DrawRadio(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t is_checked)
{
uint8_t color_backup = u8g2->draw_color;
u8g2_DrawCheckbox(u8g2, x,y,w,is_checked);
u8g2_SetDrawColor(u8g2, 2);
u8g2_Draw4Pixel(u8g2, x,y,w);
if ( is_checked )
{
//u8g2_Draw4Pixel(u8g2, x+2,y-2,w-4);
}

u8g2_SetDrawColor(u8g2, color_backup );
}
#endif



/*
Expand Down Expand Up @@ -445,6 +485,58 @@ uint8_t uif_line_button_invers_select_u8g2(ui_t *ui, uint8_t msg)
}


uint8_t uif_radio_mark_invers_select_u8g2(ui_t *ui, uint8_t msg)
{
u8g2_t *u8g2 = ui_get_U8g2(ui);
u8g2_uint_t flags = 0;
uint8_t *value = (uint8_t *)uif_get_data(ui->uif);
if ( value == NULL )
value = &(ui->selected_value);
switch(msg)
{
case UIF_MSG_DRAW:
if ( ui_IsCursorFocus(ui) )
{
flags |= U8G2_BTN_INV;
}

{
u8g2_uint_t w = 0;
u8g2_uint_t a = u8g2_GetAscent(u8g2) - 2;
if ( *value == ui->arg )
u8g2_DrawValueMark(u8g2, ui_get_x(ui), ui_get_y(ui), a);

if ( ui->text[0] != '\0' )
{
w = u8g2_GetUTF8Width(u8g2, ui->text);
u8g2_SetFontMode(u8g2, 1);
a += 2; /* add gap between the checkbox and the text area */
u8g2_DrawUTF8(u8g2, ui_get_x(ui)+a, ui_get_y(ui), ui->text);
}

u8g2_DrawButtonFrame(u8g2, ui_get_x(ui), ui_get_y(ui), flags, w+a, 1, 1);
}
break;
case UIF_MSG_FORM_START:
break;
case UIF_MSG_FORM_END:
break;
case UIF_MSG_CURSOR_ENTER:
break;
case UIF_MSG_CURSOR_SELECT:
*value = ui->arg;
break;
case UIF_MSG_CURSOR_LEAVE:
break;
case UIF_MSG_TOUCH_DOWN:
break;
case UIF_MSG_TOUCH_UP:
break;
}
return 0;

}

/*=========================================================================*/
/* ready to use field functions */

Expand Down Expand Up @@ -686,39 +778,77 @@ uint8_t uif_single_line_option_invers_select_u8g2(ui_t *ui, uint8_t msg)
return 0;
}

void u8g2_DrawCheckbox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t is_checked)


uint8_t uif_show_option_goto_form_invers_select_u8g2(ui_t *ui, uint8_t msg)
{
u8g2_DrawFrame(u8g2, x, y-w, w, w);
if ( is_checked )
//ui->dflags UIF_DFLAG_IS_CURSOR_FOCUS UIF_DFLAG_IS_TOUCH_FOCUS
//uif_get_cflags(ui->uif) UIF_CFLAG_IS_CURSOR_SELECTABLE
u8g2_t *u8g2 = ui_get_U8g2(ui);
u8g2_uint_t flags = 0;
//u8g2_uint_t flags = 0;
uint8_t *value = (uint8_t *)uif_get_data(ui->uif);
switch(msg)
{
w-=4;
u8g2_DrawBox(u8g2, x+2, y-w-2, w, w);
case UIF_MSG_DRAW:
if ( ui_fds_get_nth_token(ui, *value) == 0 )
{
*value = 0;
ui_fds_get_nth_token(ui, *value);
}
if ( ui_IsCursorFocus(ui) )
{
flags |= U8G2_BTN_INV;
}
u8g2_DrawButtonUTF8(u8g2, ui_get_x(ui), ui_get_y(ui), flags, 0, 1, 1, ui->text);

break;
case UIF_MSG_FORM_START:
break;
case UIF_MSG_FORM_END:
break;
case UIF_MSG_CURSOR_ENTER:
break;
case UIF_MSG_CURSOR_SELECT:
ui_SaveForm(ui); // store the current form and position so that the child can jump back
ui_GotoForm(ui, ui->arg, *value); // assumes that the selectable values are at the top of the form
break;
case UIF_MSG_CURSOR_LEAVE:
break;
case UIF_MSG_TOUCH_DOWN:
break;
case UIF_MSG_TOUCH_UP:
break;
}
return 0;
}

void u8g2_Draw4Pixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w)
{
u8g2_DrawPixel(u8g2, x,y-1);
u8g2_DrawPixel(u8g2, x+w-1,y-1);
u8g2_DrawPixel(u8g2, x+w-1,y-w);
u8g2_DrawPixel(u8g2, x,y-w);
}

void u8g2_DrawRadio(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t is_checked)
{
uint8_t color_backup = u8g2->draw_color;
u8g2_DrawCheckbox(u8g2, x,y,w,is_checked);
u8g2_SetDrawColor(u8g2, 2);
u8g2_Draw4Pixel(u8g2, x,y,w);
if ( is_checked )
{
//u8g2_Draw4Pixel(u8g2, x+2,y-2,w-4);
}
/*
uint8_t uif_checkbox_invers_select_u8g2(ui_t *ui, uint8_t msg)
u8g2_SetDrawColor(u8g2, color_backup );
}

uint8_t uif_checkbox_u8g2(ui_t *ui, uint8_t msg)
Description:
Checkbox with the values 0 (not selected) and 1 (selected).
Message Handling: DRAW, SELECT
Style
No Selection: Plain checkbox and text
Cursor Selection: Checkbox and text is inverted
User interface field list (uif):
flags: UIF_CFLAG_IS_CURSOR_SELECTABLE
data: uint8_t *, pointer to a uint8_t variable, which contains the values 0 or 1
Field definition string (fds):
xy: Left position of the text (required)
arg: not used
text: Optional: Text will be printed after the checkbox with a small gap
*/

uint8_t uif_checkbox_invers_select_u8g2(ui_t *ui, uint8_t msg)
{
u8g2_t *u8g2 = ui_get_U8g2(ui);
u8g2_uint_t flags = 0;
Expand Down Expand Up @@ -772,3 +902,61 @@ uint8_t uif_checkbox_u8g2(ui_t *ui, uint8_t msg)

}

uint8_t uif_assign_arg_invers_select_u8g2(ui_t *ui, uint8_t msg)
{
uint8_t *value = (uint8_t *)uif_get_data(ui->uif);
if ( value == NULL )
value = &(ui->selected_value);
switch(msg)
{
case UIF_MSG_DRAW:
return uif_radio_mark_invers_select_u8g2(ui, msg);
case UIF_MSG_FORM_START:
break;
case UIF_MSG_FORM_END:
break;
case UIF_MSG_CURSOR_ENTER:
break;
case UIF_MSG_CURSOR_SELECT:
*value = ui->arg;
break;
case UIF_MSG_CURSOR_LEAVE:
break;
case UIF_MSG_TOUCH_DOWN:
break;
case UIF_MSG_TOUCH_UP:
break;
}
return 0;

}

uint8_t uif_assign_arg_go_back_invers_select_u8g2(ui_t *ui, uint8_t msg)
{
uint8_t *value = (uint8_t *)uif_get_data(ui->uif);
if ( value == NULL )
value = &(ui->selected_value);
switch(msg)
{
case UIF_MSG_DRAW:
return uif_radio_mark_invers_select_u8g2(ui, msg);
case UIF_MSG_FORM_START:
break;
case UIF_MSG_FORM_END:
break;
case UIF_MSG_CURSOR_ENTER:
break;
case UIF_MSG_CURSOR_SELECT:
*value = ui->arg;
ui_RestoreForm(ui);
break;
case UIF_MSG_CURSOR_LEAVE:
break;
case UIF_MSG_TOUCH_DOWN:
break;
case UIF_MSG_TOUCH_UP:
break;
}
return 0;

}
4 changes: 3 additions & 1 deletion sys/sdl/ui/ui_u8g2.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ uint8_t uif_goto_half_width_frame_button_invers_select_u8g2(ui_t *ui, uint8_t ms
uint8_t uif_goto_line_button_invers_select_u8g2(ui_t *ui, uint8_t msg);
uint8_t uif_input_uint8_invers_select_u8g2(ui_t *ui, uint8_t msg);
uint8_t uif_single_line_option_invers_select_u8g2(ui_t *ui, uint8_t msg);
uint8_t uif_show_option_goto_form_invers_select_u8g2(ui_t *ui, uint8_t msg);

uint8_t uif_checkbox_u8g2(ui_t *ui, uint8_t msg);
uint8_t uif_checkbox_invers_select_u8g2(ui_t *ui, uint8_t msg);
uint8_t uif_assign_arg_go_back_invers_select_u8g2(ui_t *ui, uint8_t msg);


#endif /* ui_u8g2_h */
Expand Down

0 comments on commit 50110df

Please sign in to comment.