extern WINDOW* get_menu_win(Menu* menu);
extern MenuItem* get_menu_item(Menu* menu, int index);
extern int get_selected_item(Menu* menu);
+extern bool get_menu_focused(Menu* menu);
extern int get_menu_length(Menu* menu);
extern char* get_menu_name(Menu* menu);
extern void* get_menu_userdata(Menu* menu);
return menu->selected_item;
}
+bool
+get_menu_focused(Menu* menu)
+{
+ return menu->focused;
+}
+
int
get_menu_length(Menu* menu)
{
{
MenuItem* curitem;
int hlcolor;
+
curitem = menu->menu_items[item_index];
/* color selected item */
wattron(menu->menu_win, hlcolor);
mvwprintw(menu->menu_win, start_y, 0, curitem->title);
wattroff(menu->menu_win, hlcolor);
-
}
-/* int */
-/* default_render_item(Menu* menu, int item_index, int start_y) */
-/* { */
-/* MenuItem* curitem; */
-/* int hlcolor; */
-/* curitem = menu->menu_items[item_index]; */
-
-/* /1* color selected item *1/ */
-/* hlcolor = COLOR_PAIR((item_index == menu->selected_item && menu->focused == true) ? TS_SELECTED : TS_NONSELECTED); */
-/* wattron(menu->menu_win, hlcolor); */
-/* mvwprintw(menu->menu_win, start_y, 0, curitem->title); */
-/* wattroff(menu->menu_win, hlcolor); */
-
-/* /1* display number of items *1/ */
-/* if (strlen(curitem->description) > 0) { */
-/* wattron(menu->menu_win, COLOR_PAIR(TS_ITEMCOUNT)); */
-/* mvwprintw(menu->menu_win, start_y+1, 0, curitem->description); */
-/* wattroff(menu->menu_win, COLOR_PAIR(TS_ITEMCOUNT)); */
-/* } */
-
-/* return item_height(curitem); */
-/* } */
int
default_item_height(MenuItem* menuitem)
int init_tscolors(void);
int create_todowin(void);
+/* menu render callbacks */
+void render_menuitem(Menu* menu, int item_index, int start_y);
+int menuitem_height(MenuItem* menuitem);
+
/* init stuff */
int
init_tscurses(void)
set_menu_win(new_menu, win);
set_menu_focus(new_menu, i == 0); // make first win focused
+ /* set menu render callbacks */
+ set_menu_renderitem(new_menu, *render_menuitem);
+ set_menu_itemheight(new_menu, *menuitem_height);
+
/* refresh */
refresh();
wrefresh(win);
return menu_list;
}
+void
+render_menuitem(Menu* menu, int item_index, int start_y)
+{
+ MenuItem* curitem;
+ WINDOW* menu_win;
+ int hlcolor;
+
+ curitem = get_menu_item(menu, item_index);
+ menu_win = get_menu_win(menu);
+
+ /* color selected item */
+ hlcolor = COLOR_PAIR((item_index == get_selected_item(menu) && get_menu_focused(menu) == true) ? TS_SELECTED : TS_NONSELECTED);
+ wattron(menu_win, hlcolor);
+ mvwprintw(menu_win, start_y, 0, get_menuitem_title(curitem));
+ wattroff(menu_win, hlcolor);
+
+ /* display number of items */
+ if (strlen(get_menuitem_descrip(curitem)) > 0) {
+ wattron(menu_win, COLOR_PAIR(TS_ITEMCOUNT));
+ mvwprintw(menu_win, start_y+1, 0, get_menuitem_descrip(curitem));
+ wattroff(menu_win, COLOR_PAIR(TS_ITEMCOUNT));
+ }
+
+}
+
+int
+menuitem_height(MenuItem* menuitem)
+{
+ int lines;
+
+ lines = 1;
+ if (strlen(get_menuitem_descrip(menuitem)) > 0) {
+ lines += 1;
+ }
+
+ return lines;
+}
+
MenuItem**
todolist_to_menuitem(TodoItem** item_list, int list_length)
{