diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2013-02-12 20:35:11 +1100 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2013-02-12 21:01:13 +1100 |
commit | 69228f92dbddc9940166c0d7af2b4c79d55f85e7 (patch) | |
tree | 20ce322d2eea9dc1f1d35364ec7bf137a74ab03f /apps/gui | |
parent | e41aed633f6d76b670c4808413e6633b50a654f8 (diff) | |
download | rockbox-69228f92dbddc9940166c0d7af2b4c79d55f85e7.tar.gz rockbox-69228f92dbddc9940166c0d7af2b4c79d55f85e7.zip |
simplelist: Make better use of the static buffer and simplify API
Change-Id: I1327fcd01d6f817be6c7018d30d33446c9b57287
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/list.c | 30 | ||||
-rw-r--r-- | apps/gui/list.h | 6 |
2 files changed, 18 insertions, 18 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c index 26b6ae30e6..cc43843e46 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c | |||
@@ -831,17 +831,20 @@ bool list_do_action(int context, int timeout, | |||
831 | } | 831 | } |
832 | 832 | ||
833 | /* Simple use list implementation */ | 833 | /* Simple use list implementation */ |
834 | static int simplelist_line_count = 0; | 834 | static int simplelist_line_count = 0, simplelist_line_remaining; |
835 | static char simplelist_text[SIMPLELIST_MAX_LINES][SIMPLELIST_MAX_LINELENGTH]; | 835 | static int simplelist_line_pos; |
836 | static char simplelist_buffer[SIMPLELIST_MAX_LINES * SIMPLELIST_MAX_LINELENGTH]; | ||
837 | static char *simplelist_text[SIMPLELIST_MAX_LINES]; | ||
836 | /* set the amount of lines shown in the list */ | 838 | /* set the amount of lines shown in the list */ |
837 | void simplelist_set_line_count(int lines) | 839 | void simplelist_set_line_count(int lines) |
838 | { | 840 | { |
839 | if (lines < 0) | 841 | if (lines <= 0) { |
842 | simplelist_line_pos = 0; | ||
843 | simplelist_line_remaining = sizeof(simplelist_buffer); | ||
840 | simplelist_line_count = 0; | 844 | simplelist_line_count = 0; |
845 | } | ||
841 | else if (lines >= SIMPLELIST_MAX_LINES) | 846 | else if (lines >= SIMPLELIST_MAX_LINES) |
842 | simplelist_line_count = SIMPLELIST_MAX_LINES; | 847 | simplelist_line_count = SIMPLELIST_MAX_LINES; |
843 | else | ||
844 | simplelist_line_count = lines; | ||
845 | } | 848 | } |
846 | /* get the current amount of lines shown */ | 849 | /* get the current amount of lines shown */ |
847 | int simplelist_get_line_count(void) | 850 | int simplelist_get_line_count(void) |
@@ -851,20 +854,19 @@ int simplelist_get_line_count(void) | |||
851 | /* add/edit a line in the list. | 854 | /* add/edit a line in the list. |
852 | if line_number > number of lines shown it adds the line, | 855 | if line_number > number of lines shown it adds the line, |
853 | else it edits the line */ | 856 | else it edits the line */ |
854 | void simplelist_addline(int line_number, const char *fmt, ...) | 857 | void simplelist_addline(const char *fmt, ...) |
855 | { | 858 | { |
856 | va_list ap; | 859 | va_list ap; |
860 | size_t len = simplelist_line_remaining; | ||
861 | int line_number = simplelist_line_count++; | ||
857 | 862 | ||
858 | if (line_number > simplelist_line_count) | 863 | simplelist_text[line_number] = &simplelist_buffer[simplelist_line_pos]; |
859 | { | ||
860 | if (simplelist_line_count < SIMPLELIST_MAX_LINES) | ||
861 | line_number = simplelist_line_count++; | ||
862 | else | ||
863 | return; | ||
864 | } | ||
865 | va_start(ap, fmt); | 864 | va_start(ap, fmt); |
866 | vsnprintf(simplelist_text[line_number], SIMPLELIST_MAX_LINELENGTH, fmt, ap); | 865 | len = vsnprintf(simplelist_text[line_number], simplelist_line_remaining, fmt, ap); |
867 | va_end(ap); | 866 | va_end(ap); |
867 | len++; | ||
868 | simplelist_line_remaining -= len; | ||
869 | simplelist_line_pos += len; | ||
868 | } | 870 | } |
869 | 871 | ||
870 | static const char* simplelist_static_getname(int item, | 872 | static const char* simplelist_static_getname(int item, |
diff --git a/apps/gui/list.h b/apps/gui/list.h index 162bb38e1a..8980573aa3 100644 --- a/apps/gui/list.h +++ b/apps/gui/list.h | |||
@@ -265,10 +265,8 @@ struct simplelist_info { | |||
265 | void simplelist_set_line_count(int lines); | 265 | void simplelist_set_line_count(int lines); |
266 | /* get the current amount of lines shown */ | 266 | /* get the current amount of lines shown */ |
267 | int simplelist_get_line_count(void); | 267 | int simplelist_get_line_count(void); |
268 | /* add/edit a line in the list. | 268 | /* add a line in the list. */ |
269 | if line_number > number of lines shown it adds the line, else it edits the line */ | 269 | void simplelist_addline(const char *fmt, ...); |
270 | #define SIMPLELIST_ADD_LINE (SIMPLELIST_MAX_LINES+1) | ||
271 | void simplelist_addline(int line_number, const char *fmt, ...); | ||
272 | 270 | ||
273 | /* setup the info struct. members not setup in this function need to be assigned manually | 271 | /* setup the info struct. members not setup in this function need to be assigned manually |
274 | members set in this function: | 272 | members set in this function: |