summaryrefslogtreecommitdiff
path: root/apps/gui
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui')
-rw-r--r--apps/gui/list.c103
-rw-r--r--apps/gui/list.h42
2 files changed, 145 insertions, 0 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c
index 41bde5802b..52c1e4a3b9 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -1028,3 +1028,106 @@ bool gui_synclist_do_button(struct gui_synclist * lists,
1028 } 1028 }
1029 return false; 1029 return false;
1030} 1030}
1031
1032/* Simple use list implementation */
1033static int simplelist_line_count = 0;
1034static char simplelist_text[SIMPLELIST_MAX_LINES][SIMPLELIST_MAX_LINELENGTH];
1035/* set the amount of lines shown in the list */
1036void simplelist_set_line_count(int lines)
1037{
1038 if (lines < 0)
1039 lines = 0;
1040 else if (lines > SIMPLELIST_MAX_LINES)
1041 lines = SIMPLELIST_MAX_LINES;
1042 simplelist_line_count = 0;
1043}
1044/* get the current amount of lines shown */
1045int simplelist_get_line_count(void)
1046{
1047 return simplelist_line_count;
1048}
1049/* add/edit a line in the list.
1050 if line_number > number of lines shown it adds the line, else it edits the line */
1051void simplelist_addline(int line_number, const char *fmt, ...)
1052{
1053 va_list ap;
1054
1055 if (line_number > simplelist_line_count)
1056 {
1057 if (simplelist_line_count < SIMPLELIST_MAX_LINES)
1058 line_number = simplelist_line_count++;
1059 else
1060 return;
1061 }
1062 va_start(ap, fmt);
1063 vsnprintf(simplelist_text[line_number], SIMPLELIST_MAX_LINELENGTH, fmt, ap);
1064 va_end(ap);
1065}
1066
1067static char* simplelist_static_getname(int item, void * data, char *buffer)
1068{
1069 (void)data; (void)buffer;
1070 return simplelist_text[item];
1071}
1072bool simplelist_show_list(struct simplelist_info *info)
1073{
1074 struct gui_synclist lists;
1075 int action, old_line_count = simplelist_line_count;
1076 char* (*getname)(int item, void * data, char *buffer);
1077 if (info->get_name)
1078 getname = info->get_name;
1079 else
1080 getname = simplelist_static_getname;
1081 gui_synclist_init(&lists, getname, info->callback_data,
1082 info->scroll_all, info->selection_size);
1083 if (info->title)
1084 gui_synclist_set_title(&lists, info->title, NOICON);
1085 if (info->get_icon)
1086 gui_synclist_set_icon_callback(&lists, info->get_icon);
1087
1088 gui_synclist_hide_selection_marker(&lists, info->hide_selection);
1089
1090 if (info->action_callback)
1091 info->action_callback(ACTION_REDRAW, &lists);
1092
1093 if (info->get_name == NULL)
1094 gui_synclist_set_nb_items(&lists, simplelist_line_count*info->selection_size);
1095 else
1096 gui_synclist_set_nb_items(&lists, info->count*info->selection_size);
1097
1098 gui_synclist_draw(&lists);
1099
1100 while(1)
1101 {
1102 gui_syncstatusbar_draw(&statusbars, true);
1103 action = get_action(CONTEXT_STD, HZ/5);
1104 if (gui_synclist_do_button(&lists, &action, LIST_WRAP_UNLESS_HELD))
1105 continue;
1106 if (info->action_callback)
1107 {
1108 action = info->action_callback(action, &lists);
1109 if (info->get_name == NULL)
1110 gui_synclist_set_nb_items(&lists, simplelist_line_count*info->selection_size);
1111 }
1112 if (action == ACTION_STD_CANCEL)
1113 break;
1114 else if ((action == ACTION_REDRAW) || (old_line_count == simplelist_line_count))
1115 {
1116 if (info->get_name == NULL)
1117 gui_synclist_set_nb_items(&lists, simplelist_line_count*info->selection_size);
1118 gui_synclist_draw(&lists);
1119 }
1120 else if(default_event_handler(action) == SYS_USB_CONNECTED)
1121 return true;
1122 }
1123 return false;
1124}
1125
1126
1127
1128
1129
1130
1131
1132
1133
diff --git a/apps/gui/list.h b/apps/gui/list.h
index 9aaa18ed08..2de67f5219 100644
--- a/apps/gui/list.h
+++ b/apps/gui/list.h
@@ -223,5 +223,47 @@ extern void gui_synclist_hide_selection_marker(struct gui_synclist *lists,
223extern bool gui_synclist_do_button(struct gui_synclist * lists, 223extern bool gui_synclist_do_button(struct gui_synclist * lists,
224 unsigned *action, 224 unsigned *action,
225 enum list_wrap); 225 enum list_wrap);
226
227/** Simplelist implementation.
228 USe this if you dont need to reimplement the list code,
229 and just need to show a list
230 **/
231
232struct simplelist_info {
233 char *title; /* title to show on the list */
234 int count; /* number of items in the list, each item is selection_size high */
235 char selection_size; /* list selection size, usually 1 */
236 bool hide_selection;
237 bool scroll_all;
238 int (*action_callback)(int action, struct gui_synclist *lists); /* can be NULL */
239 /* action_callback notes:
240 action == the action pressed by the user
241 _after_ gui_synclist_do_button returns.
242 lists == the lists sturct so the callack can get selection and count etc. */
243 list_get_icon *get_icon; /* can be NULL */
244 list_get_name *get_name; /* NULL if you're using simplelist_addline() */
245 void *callback_data; /* data for callbacks */
246};
247
248#define SIMPLELIST_MAX_LINES 32
249#define SIMPLELIST_MAX_LINELENGTH 32
250
251/** The next three functions are used if the text is mostly static.
252 These should be called in the action callback for the list.
253 **/
254/* set the amount of lines shown in the list
255 Only needed if simplelist_info.get_name == NULL */
256void simplelist_set_line_count(int lines);
257/* get the current amount of lines shown */
258int simplelist_get_line_count(void);
259/* add/edit a line in the list.
260 if line_number > number of lines shown it adds the line, else it edits the line */
261#define SIMPLELIST_ADD_LINE (SIMPLELIST_MAX_LINES+1)
262void simplelist_addline(int line_number, const char *fmt, ...);
263
264/* show a list.
265 if list->action_callback != NULL it is called with the action ACTION_REDRAW
266 before the list is dislplayed for the first time */
267bool simplelist_show_list(struct simplelist_info *info);
226 268
227#endif /* _GUI_LIST_H_ */ 269#endif /* _GUI_LIST_H_ */