Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
olikraus committed Sep 12, 2021
1 parent 5ae8215 commit 4486047
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 7 deletions.
45 changes: 45 additions & 0 deletions csrc/mui_u8g2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,3 +1191,48 @@ uint8_t mui_u8g2_u8_opt_child_w1_mse_pi(mui_t *ui, uint8_t msg)
return 0;
}


uint8_t mui_u8g2_u16_list_line_wa_mse_pi(mui_t *ui, uint8_t msg)
{
u8g2_t *u8g2 = mui_get_U8g2(ui);
mui_u8g2_list_t *list = (mui_u8g2_list_t *)muif_get_data(ui->uif);
uint16_t *selection = mui_u8g2_list_get_selection_ptr(list);
uint16_t *top_element = mui_u8g2_list_get_top_element_ptr(list);
void *data = mui_u8g2_list_get_data_ptr(list);
mui_u8g2_get_list_element_cb element_cb = mui_u8g2_list_get_element_cb(list);
mui_u8g2_get_list_count_cb count_cb = mui_u8g2_list_get_count_cb(list);
const char *s;

switch(msg)
{
case MUIF_MSG_DRAW:
s = element_cb(data, *selection);
if ( s == NULL )
{
*selection = 0;
s = element_cb(data, *selection);
if ( s == NULL )
s = "";
}
mui_u8g2_draw_button_utf(ui, mui_u8g2_get_draw_button_pi_flags(ui), ui->arg, 1, MUI_U8G2_V_PADDING, s);
break;
case MUIF_MSG_FORM_START:
break;
case MUIF_MSG_FORM_END:
break;
case MUIF_MSG_CURSOR_ENTER:
break;
case MUIF_MSG_CURSOR_SELECT:
(*selection)++;
if ( *selection >= count_cb(data) )
*selection = 0;
break;
case MUIF_MSG_CURSOR_LEAVE:
break;
case MUIF_MSG_TOUCH_DOWN:
break;
case MUIF_MSG_TOUCH_UP:
break;
}
return 0;
}
46 changes: 43 additions & 3 deletions csrc/mui_u8g2.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#ifndef MUI_U8G2_H
#define MUI_U8G2_H

#include <mui.h>

/*==========================================*/
/* C++ compatible */

Expand All @@ -46,13 +48,43 @@ extern "C" {
#endif


#define MUI_U8G2_COMMA ,

typedef const char * (*mui_u8g2_get_list_element_cb)(void *data, uint16_t index);
typedef uint16_t (*mui_u8g2_get_list_count_cb)(void *data);

struct mui_u8g2_list_struct
{
uint16_t *selection;
uint16_t *top_element;
void *data;
mui_u8g2_get_list_element_cb get_list_element;
mui_u8g2_get_list_count_cb get_list_count;
} MUI_PROGMEM;

typedef const struct mui_u8g2_list_struct mui_u8g2_list_t;

#if defined(__GNUC__) && defined(__AVR__)
# define mui_u8g2_list_get_selection_ptr(list) ((uint16_t *)mui_pgm_wread(&((list)->selection)))
# define mui_u8g2_list_get_top_element_ptr(list) ((uint16_t *)mui_pgm_wread(&((list)->top_element)))
# define mui_u8g2_list_get_data_ptr(list) ((void *)mui_pgm_wread(&((list)->data)))
# define mui_u8g2_list_get_element_cb(list) ((mui_u8g2_get_list_element_cb)mui_pgm_wread(&((list)->get_list_element)))
# define mui_u8g2_list_get_count_cb(list) ((mui_u8g2_get_list_count_cb)mui_pgm_wread(&((list)->get_list_count)))
#else
# define mui_u8g2_list_get_selection_ptr(list) ((list)->selection)
# define mui_u8g2_list_get_top_element_ptr(list) ((list)->top_element)
# define mui_u8g2_list_get_data_ptr(list) ((list)->data)
# define mui_u8g2_list_get_element_cb(list) ((list)->get_list_element)
# define mui_u8g2_list_get_count_cb(list) ((list)->get_list_count)
#endif


struct mui_u8g2_u8_min_max_struct
{
uint8_t *value;
uint8_t min;
uint8_t max;
}
MUI_PROGMEM ;
} MUI_PROGMEM;

typedef const struct mui_u8g2_u8_min_max_struct mui_u8g2_u8_min_max_t;

Expand All @@ -66,7 +98,7 @@ typedef const struct mui_u8g2_u8_min_max_struct mui_u8g2_u8_min_max_t;
# define mui_u8g2_u8mm_get_valptr(u8mm) ((u8mm)->value)
#endif

#define MUI_U8G2_COMMA ,



/* helper functions */
Expand Down Expand Up @@ -125,6 +157,14 @@ uint8_t mui_u8g2_u8_radio_wm_pi(mui_t *ui, uint8_t msg);

uint8_t mui_u8g2_u8_char_wm_mud_pi(mui_t *ui, uint8_t msg);

uint8_t mui_u8g2_u16_list_line_wa_mse_pi(mui_t *ui, uint8_t msg);
#define MUIF_U8G2_U16_LIST_LINE_WM_MUD_PI(id, valptr, topptr, dataptr, getcb, cntcb) \
MUIF(id, MUIF_CFLAG_IS_CURSOR_SELECTABLE, \
(void *)((mui_u8g2_list_t [] ) {{ (valptr) MUI_U8G2_COMMA (topptr) MUI_U8G2_COMMA (dataptr) MUI_U8G2_COMMA (getcb) MUI_U8G2_COMMA (cntcb)}}), \
mui_u8g2_u16_list_line_wa_mse_pi)



#ifdef __cplusplus
}
#endif
Expand Down
38 changes: 34 additions & 4 deletions sys/sdl/mui/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ uint8_t mui_hrule(mui_t *ui, uint8_t msg)
return 0;
}


u8g2_t u8g2;
mui_t ui;

Expand All @@ -75,7 +76,18 @@ uint8_t checkbox_input = 0;
uint8_t direction_input = 0;
uint8_t text_input[4] = { ' ',' ',' ',' '} ;
uint8_t exit_code = 0;
uint16_t list_selection = 0;

uint16_t list_get_cnt(void *data)
{
return 17; /* number of animals */
}

const char *list_get_str(void *data, uint16_t index)
{
static const char *animals[] = { "Bird", "Bison", "Cat", "Crow", "Dog", "Elephant", "Fish", "Gnu", "Horse", "Koala", "Lion", "Mouse", "Owl", "Rabbit", "Spider", "Turtle", "Zebra" };
return animals[index];
}

/*
Expand Down Expand Up @@ -150,6 +162,9 @@ muif_t muif_list[] MUI_PROGMEM = {
/* 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_LINE_WM_MUD_PI("L1", &list_selection, NULL, NULL, list_get_str, list_get_cnt),


/* 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_jmp_w1_pi),
Expand Down Expand Up @@ -190,7 +205,7 @@ fds_t fds[] =
/* top level main menu */
MUI_FORM(0)
MUI_STYLE(1)
MUI_LABEL(5,10, "Main Menu 1/2")
MUI_LABEL(5,10, "Main Menu 1/3")
MUI_XY("HR", 0,13)
MUI_STYLE(0)
MUI_GOTO(5,25,10, "Enter a number")
Expand All @@ -200,12 +215,20 @@ MUI_GOTO(5,61,1, "More...")

MUI_FORM(1)
MUI_STYLE(1)
MUI_LABEL(5,10, "Main Menu 2/2")
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_FORM(2)
MUI_STYLE(1)
MUI_LABEL(5,10, "Main Menu 2/3")
MUI_XY("HR", 0,13)
MUI_STYLE(0)
MUI_GOTO(5,25,17, "List Line Selection")
MUI_GOTO(5,61,0, "Back...")

/* number entry demo */
Expand Down Expand Up @@ -294,8 +317,6 @@ MUI_STYLE(0)

MUI_XYAT("G1",64, 59, 1, " OK ")



/* single line selection */
MUI_FORM(16)
MUI_STYLE(1)
Expand All @@ -311,8 +332,17 @@ MUI_XYAT("IG",60, 43, 60, "Banana|Apple|Melon|Cranberry")

MUI_XYAT("G1",64, 59, 1, " OK ")

/* long list example with list callback functions */
MUI_FORM(17)
MUI_STYLE(1)
MUI_LABEL(5,10, "List Line Selection")
MUI_XY("HR", 0,13)
MUI_STYLE(0)

MUI_LABEL(5,29, "List [mse]:")
MUI_XYA("L1",60, 29, 60)

MUI_XYAT("G1",64, 59, 2, " OK ")


/* minimal example */
Expand Down

0 comments on commit 4486047

Please sign in to comment.