Code

screen_help: removed the help_text_row_t typedef
[ncmpc.git] / src / screen_help.c
index 4d501742bb0f2cf533382d361a680af92affe46e..1d83bf77c3ba106644b2447f19b36a37afcca086 100644 (file)
 
 #include <glib.h>
 
-typedef struct {
+#include <assert.h>
+
+struct help_text_row {
        signed char highlight;
        command_t command;
        const char *text;
-} help_text_row_t;
+};
 
-static help_text_row_t help_text[] = {
+static const struct help_text_row help_text[] = {
        { 1, CMD_NONE, N_("Movement") },
        { 2, CMD_NONE, NULL },
        { 0, CMD_LIST_PREVIOUS, NULL },
@@ -177,8 +179,6 @@ static help_text_row_t help_text[] = {
 #endif
 };
 
-#define help_text_rows (sizeof(help_text) / sizeof(help_text[0]))
-
 static struct list_window *lw;
 
 static const char *
@@ -186,8 +186,7 @@ list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char** second_column,
 {
        static char buf[512];
 
-       if (idx >= help_text_rows)
-               return NULL;
+       assert(idx < G_N_ELEMENTS(help_text));
 
        if (help_text[idx].highlight)
                *highlight = true;
@@ -224,13 +223,13 @@ help_init(WINDOW *w, int cols, int rows)
 {
   lw = list_window_init(w, cols, rows);
        lw->hide_cursor = true;
+       list_window_set_length(lw, G_N_ELEMENTS(help_text));
 }
 
 static void
 help_resize(int cols, int rows)
 {
-  lw->cols = cols;
-  lw->rows = rows;
+       list_window_resize(lw, cols, rows);
 }
 
 static void
@@ -255,17 +254,16 @@ help_paint(void)
 static bool
 help_cmd(G_GNUC_UNUSED struct mpdclient *c, command_t cmd)
 {
-       if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
+       if (list_window_scroll_cmd(lw, cmd)) {
                list_window_paint(lw, list_callback, NULL);
                wrefresh(lw->w);
                return true;
        }
 
        list_window_set_cursor(lw, lw->start);
-       if (screen_find(lw,  help_text_rows,
-                       cmd, list_callback, NULL)) {
+       if (screen_find(lw,  cmd, list_callback, NULL)) {
                /* center the row */
-               list_window_center(lw, help_text_rows, lw->selected);
+               list_window_center(lw, lw->selected);
                list_window_paint(lw, list_callback, NULL);
                wrefresh(lw->w);
                return true;