Menüausrichtung verbessert: Bei Eintritt ins Menü Vorauswahl möglichst weit
authorWintermate <wintermute@hannover.ccc.de>
Thu, 24 Oct 2013 21:40:59 +0000 (23:40 +0200)
committerWintermate <wintermute@hannover.ccc.de>
Thu, 24 Oct 2013 21:40:59 +0000 (23:40 +0200)
vorne darstellen. Außerdem size_t wo geht durch uint8_t ersetzt, um ein paar
mehr Byte rauszuquetschen.

badge/fahrplan.c
badge/jumpnrun/starter.c
badge/main.c
badge/ui/browser.c
badge/ui/browser.h
badge/ui/menu.c
badge/ui/menu.h

index e6127be..604e2e6 100644 (file)
@@ -2,18 +2,19 @@
 #include "ui/browser.h"
 
 #include <drivers/fatfs/ff.h>
+#include <stdint.h>
 
 #define FAHRPLAN_PATH     "/fahrplan"
 #define FAHRPLAN_MENUFILE "fahrplan.lst"
 #define FAHRPLAN_POSFILE  "selected.dat"
 
-static size_t badge_load_fahrplan_pos(void) {
-  size_t pos = 0;
+static uint8_t badge_load_fahrplan_pos(void) {
+  uint8_t pos = 0;
   FIL fd;
 
   if(FR_OK == f_open(&fd, FAHRPLAN_POSFILE, FA_OPEN_EXISTING | FA_READ)) {
     UINT bytes;
-    size_t buf;
+    uint8_t buf;
     if(FR_OK == f_read(&fd, &buf, sizeof(buf), &bytes) && bytes == sizeof(buf)) {
       pos = buf;
     }
@@ -24,7 +25,7 @@ static size_t badge_load_fahrplan_pos(void) {
   return pos;
 }
 
-static void badge_save_fahrplan_pos(size_t pos) {
+static void badge_save_fahrplan_pos(uint8_t pos) {
   FIL fd;
 
   if(FR_OK == f_open(&fd, FAHRPLAN_POSFILE, FA_CREATE_ALWAYS | FA_WRITE)) {
@@ -37,8 +38,8 @@ static void badge_save_fahrplan_pos(size_t pos) {
 void badge_fahrplan(void) {
   f_chdir(FAHRPLAN_PATH);
 
-  size_t oldpos = badge_load_fahrplan_pos();
-  size_t pos = oldpos;
+  uint8_t oldpos = badge_load_fahrplan_pos();
+  uint8_t pos = oldpos;
 
   badge_browse_textfiles(FAHRPLAN_MENUFILE, &pos);
 
index 559ee29..bb69f2e 100644 (file)
@@ -52,7 +52,7 @@ static void    jumpnrun_save_selected(uint8_t selected) {        save_byte_to_fi
 static uint8_t jumpnrun_load_progress(void            ) { return read_byte_from_file(PROGRESS_FNAME          ); }
 static void    jumpnrun_save_progress(uint8_t progress) {        save_byte_to_file  (PROGRESS_FNAME, progress); }
 
-static uint8_t jumpnrun_pick_level_from_fd(char *buf, size_t *first_visible, size_t *selected, uint8_t progress, FIL *fd) {
+static uint8_t jumpnrun_pick_level_from_fd(char *buf, uint8_t *first_visible, uint8_t *selected, uint8_t progress, FIL *fd) {
   unsigned levelcount = 0;
 
   {
@@ -66,7 +66,7 @@ static uint8_t jumpnrun_pick_level_from_fd(char *buf, size_t *first_visible, siz
     return JUMPNRUN_ERROR;
   }
 
-  size_t menulen   = levelcount + (levelcount <= progress) + 1;
+  uint8_t menulen   = levelcount + (levelcount <= progress) + 1;
 
   char        menu_buf  [menulen][MENU_BUFLEN];
   char const *menu_index[menulen];
@@ -84,8 +84,8 @@ static uint8_t jumpnrun_pick_level_from_fd(char *buf, size_t *first_visible, siz
     fnames[i] = p;
   }
 
-  size_t creditspos = -1;
-  size_t exitpos   = i;
+  uint8_t creditspos = -1;
+  uint8_t exitpos   = i;
 
   if(levelcount <= progress) {
     creditspos = i;
@@ -98,7 +98,7 @@ static uint8_t jumpnrun_pick_level_from_fd(char *buf, size_t *first_visible, siz
   strcpy(menu_buf[exitpos], "Zurück");
   menu_index[exitpos] = menu_buf[exitpos];
 
-  size_t choice = badge_menu(menu_index, exitpos + 1, first_visible, *selected);
+  uint8_t choice = badge_menu(menu_index, exitpos + 1, first_visible, *selected);
 
   if(choice == exitpos) {
     return CHOICE_EXIT;
@@ -116,7 +116,7 @@ static uint8_t jumpnrun_pick_level_from_fd(char *buf, size_t *first_visible, siz
   return CHOICE_LEVEL;
 }
 
-static uint8_t jumpnrun_pick_level(char *buf, size_t *first_visible, size_t *selected, uint8_t progress) {
+static uint8_t jumpnrun_pick_level(char *buf, uint8_t *first_visible, uint8_t *selected, uint8_t progress) {
   FIL fd;
 
   if(FR_OK != f_chdir(JUMPNRUN_PATH) ||
@@ -133,11 +133,11 @@ static uint8_t jumpnrun_pick_level(char *buf, size_t *first_visible, size_t *sel
 
 void jumpnrun_play(void) {
   char    buf[LEVELFILE_MAX + 1];
-  size_t  first_visible = 0;
-  size_t  selected = jumpnrun_load_selected();
+  uint8_t selected = jumpnrun_load_selected();
   uint8_t progress = jumpnrun_load_progress();
+  uint8_t first_visible = selected;
   uint8_t choice;
-  size_t oldselected = selected;
+  uint8_t oldselected = selected;
 
   do {
     if(oldselected != selected) {
index 546c585..f092d36 100644 (file)
@@ -209,7 +209,7 @@ static void usbmode(void) {
 uint8_t main_menu_show(uint8_t selected) {
   // first_visible = 0, weil das Menü so kurz ist. Sollte es
   // größer werden: Parameter aus main_menu empfangen und merken.
-  size_t first_visible = 0;
+  uint8_t first_visible = 0;
   char const *const menu[] = {
     "Vanity-Screen",
     "Super Hackio",
index 493ce0f..a5abb1a 100644 (file)
@@ -35,8 +35,8 @@ static void badge_browse_textfile_fd(FIL *fd) {
   badge_scroll_text(lines, i);
 }
 
-static size_t badge_count_lines_in_file(FIL *fd) {
-  size_t count = 0;
+static uint8_t badge_count_lines_in_file(FIL *fd) {
+  uint8_t count = 0;
 
   if(FR_OK == f_lseek(fd, 0)) {
     char buf[BUFLEN];
@@ -48,7 +48,7 @@ static size_t badge_count_lines_in_file(FIL *fd) {
   return count;
 }
 
-static uint8_t badge_browse_pick_filename_from_fd(char *buf, size_t *first_visible, size_t *selected, FIL *fd) {
+static uint8_t badge_browse_pick_filename_from_fd(char *buf, uint8_t *first_visible, uint8_t *selected, FIL *fd) {
   unsigned linecount = badge_count_lines_in_file(fd);
 
   if(FR_OK != f_lseek(fd, 0)) {
@@ -73,7 +73,7 @@ static uint8_t badge_browse_pick_filename_from_fd(char *buf, size_t *first_visib
 
   strcpy(menu_buf[i], "Zurück");
   menu_index[i] = menu_buf[i];
-  size_t choice = badge_menu(menu_index, i + 1, first_visible, *selected);
+  uint8_t choice = badge_menu(menu_index, i + 1, first_visible, *selected);
 
   if(choice == linecount) {
     return 1; // exit
@@ -86,7 +86,7 @@ static uint8_t badge_browse_pick_filename_from_fd(char *buf, size_t *first_visib
   return 0;
 }
 
-static uint8_t badge_pick_filename(char *buf, char const *menufile, size_t *first_visible, size_t *selected) {
+static uint8_t badge_pick_filename(char *buf, char const *menufile, uint8_t *first_visible, uint8_t *selected) {
   FIL fd;
   uint8_t err = 1;
 
@@ -107,9 +107,9 @@ void badge_browse_textfile(char const *fname) {
   }
 }
 
-void badge_browse_textfiles(char const *menufile, size_t *selected) {
+void badge_browse_textfiles(char const *menufile, uint8_t *selected) {
   char buf[FNAME_MAX + 1];
-  size_t first_visible = 0;
+  uint8_t first_visible = *selected;
 
   while(0 == badge_pick_filename(buf, menufile, &first_visible, selected)) {
     badge_browse_textfile(buf);
index 3e9f433..e22cc00 100644 (file)
@@ -1,9 +1,9 @@
 #ifndef INCLUDED_BADGE_UI_BROWSER_H
 #define INCLUDED_BADGE_UI_BROWSER_H
 
-#include <stddef.h>
+#include <stdint.h>
 
 void badge_browse_textfile(char const *fname);
-void badge_browse_textfiles(char const *menufile, size_t *selected);
+void badge_browse_textfiles(char const *menufile, uint8_t *selected);
 
 #endif
index 3235838..601d159 100644 (file)
@@ -27,17 +27,17 @@ enum {
 };
 
 static void badge_menu_show(char const *const *menu,
-                            size_t n,
-                            size_t *first_visible,
-                            size_t selected,
+                            uint8_t n,
+                            uint8_t *first_visible,
+                            uint8_t selected,
                             char   selector)
 {
   badge_framebuffer fb = { { { 0 } } };
   bool arrow_up   = true;
   bool arrow_down = true;
 
-  size_t first_used_row = 0;
-  size_t used_rows = MENU_ENTRIES_VISIBLE;
+  uint8_t first_used_row = 0;
+  uint8_t used_rows = MENU_ENTRIES_VISIBLE;
 
   if(selected >= n) {
     selected = n - 1;
@@ -47,6 +47,8 @@ static void badge_menu_show(char const *const *menu,
     *first_visible = 0;
     used_rows      = n;
     first_used_row = (MENU_ENTRIES_VISIBLE - used_rows) / 2;
+  } else if(*first_visible + MENU_ENTRIES_VISIBLE > n) {
+    *first_visible = n - MENU_ENTRIES_VISIBLE;
   } else if(selected + 1 == n) {
     *first_visible = n - MENU_ENTRIES_VISIBLE;
   } else if(selected <= *first_visible) {
@@ -63,7 +65,7 @@ static void badge_menu_show(char const *const *menu,
     arrow_down = false;
   }
 
-  for(size_t i = 0; i < used_rows; ++i) {
+  for(uint8_t i = 0; i < used_rows; ++i) {
     badge_framebuffer_render_text(&fb,
                                   (int8_t) (MENU_MARGIN_LEFT + BADGE_FONT_WIDTH),
                                   (int8_t) (MENU_MARGIN_TOP  + (first_used_row + i) * MENU_ENTRIES_HEIGHT),
@@ -77,10 +79,10 @@ static void badge_menu_show(char const *const *menu,
   badge_framebuffer_flush(&fb);
 }
 
-size_t badge_menu(char const *const *menu,
-                  size_t  n,
-                  size_t *first_visible,
-                  size_t  selected)
+uint8_t badge_menu(char const *const *menu,
+                  uint8_t  n,
+                  uint8_t *first_visible,
+                  uint8_t  selected)
 {
   unsigned scroll_ticks = 0;
   int scroll_direction = 0;
@@ -130,8 +132,8 @@ size_t badge_menu(char const *const *menu,
   }
 }
 
-void badge_scroll_text(char const *const *lines, size_t n) {
-  size_t first_visible  = 0;
+void badge_scroll_text(char const *const *lines, uint8_t n) {
+  uint8_t first_visible  = 0;
   int scroll_direction  = 0;
   unsigned scroll_ticks = 0;
 
index f9bf841..a412126 100644 (file)
@@ -4,11 +4,11 @@
 #include <stddef.h>
 #include <stdint.h>
 
-size_t badge_menu(char const *const * menu,
-                  size_t  n,
-                  size_t *first_visible,
-                  size_t  preselected);
+uint8_t badge_menu(char const *const * menu,
+                   uint8_t  n,
+                   uint8_t *first_visible,
+                   uint8_t  preselected);
 
-void badge_scroll_text(char const *const *lines, size_t n);
+void badge_scroll_text(char const *const *lines, uint8_t n);
 
 #endif
This page took 0.036383 seconds and 4 git commands to generate.