/* ncurses doesn't support multiline menu items,
* so i wrote my own menu lib */
+typedef enum {
+ MENU_UP = 0,
+ MENU_DOWN,
+ MENU_TOP,
+ MENU_BOTTOM
+} MenuAction;
+
typedef struct Menu Menu;
typedef struct MenuItem MenuItem;
extern int set_menu_win(Menu* menu, WINDOW* win);
extern MenuItem* get_menu_items(Menu* menu);
+extern int menu_driver(Menu* menu, MenuAction action);
+
extern int render_menu(Menu* menu);
extern int free_menu(Menu* menu);
return NULL;
}
+int
+menu_driver(Menu* menu, MenuAction action)
+{
+
+ switch (action) {
+ case MENU_UP:
+ menu->selected_item = menu->selected_item-1 >= 0 ? menu->selected_item-1 : 0;
+ break;
+ case MENU_DOWN:
+ menu->selected_item = menu->selected_item+1 <= menu->menu_length-1 ? menu->selected_item+1 : menu->menu_length-1;
+ break;
+ case MENU_TOP:
+ menu->selected_item = 0;
+ break;
+ case MENU_BOTTOM:
+ menu->selected_item = menu->menu_length-1;
+ break;
+ default:
+ fprintf(stderr, "Invalid menu action");
+ }
+
+ return 0;
+}
+
int
render_menu(Menu* menu)
{
#include "headers/render.h"
#include "headers/menu.h"
#include "headers/utils.h"
+#include "config.h"
int
main(int argc, char** argv)
{
+ char ch;
/* Board* board; */
/* board = begin_parse("test_board.md"); */
/* log_todo(board); */
/* init curses */
init_tscurses();
-
- MenuItem** item_list = malloc(4*sizeof(MenuItem*));
- for (int i = 0; i < 3; i++) {
+ MenuItem** item_list = malloc(6*sizeof(MenuItem*));
+ for (int i = 0; i < 5; i++) {
item_list[i] = create_menuitem("Many of you are probably feeling a little sad.");
}
+ item_list[5] = 0;
Menu* menu = create_menu(item_list);
-
render_menu(menu);
- getch();
+ while ((ch = getch()) != BINDING_QUIT) {
+
+ switch (ch) {
+
+ case BINDING_SCROLL_UP:
+ menu_driver(menu, MENU_UP);
+ break;
+ case BINDING_SCROLL_DOWN:
+ menu_driver(menu, MENU_DOWN);
+ break;
+ case BINDING_JUMP_TOP:
+ menu_driver(menu, MENU_TOP);
+ break;
+ case BINDING_JUMP_BOTTOM:
+ menu_driver(menu, MENU_BOTTOM);
+ break;
+ }
+ render_menu(menu);
- exit_tscurses();
+ }
- /* int out; */
- /* printf("%s", wrap_text("ayylmaooooxdxdxdxdxd", 3, &out)); */
- /* printf("%d\n", out); */
- /* wrap_text("ayylmaooooxdxdxdxdxd", 3, &out); */
-
+ exit_tscurses();
return 0;
}