extern int get_selected_item(Menu* menu);
extern int get_menu_length(Menu* menu);
extern char* get_menu_name(Menu* menu);
+extern void* get_menu_userdata(Menu* menu);
extern char* get_menuitem_title(MenuItem* menuitem);
extern char* get_menuitem_descrip(MenuItem* menuitem);
+extern void* get_menuitem_userdata(MenuItem* menuitem);
extern int set_menu_win(Menu* menu, WINDOW* win);
extern int set_selected_item(Menu* menu, int selected_item);
extern int set_menu_focus(Menu* menu, bool focus);
+extern int set_menu_userdata(Menu* menu, void* userdata);
+extern int set_menuitem_descrip(MenuItem* menuitem, char* descrip);
+extern int set_menuitem_userdata(MenuItem* menuitem, void* userdata);
extern int insert_item(Menu* menu, MenuItem* menuitem, int index);
extern int delete_item(Menu* menu, int index);
extern int set_selected_menu(BoardMenu* boardmenu, int index);
extern int swap_menu(BoardMenu* boardmenu, int src_index, int dest_index);
+/* menuitem stuff */
+extern int update_menuitem_descrip(MenuItem* menuitem);
+
/* popup menu for menu item */
extern WINDOW* create_popup_win();
typedef struct MenuItem {
char* title;
char* description;
- void* user_data;
+ void* userdata;
} MenuItem;
typedef struct Menu {
WINDOW* sub_win;
int max_height;
int max_width;
- void* user_data;
+ void* userdata;
} Menu;
int swap_item(Menu* menu, int src_index, int dest_index);
return menu->menu_name;
}
+void*
+get_menu_userdata(Menu* menu)
+{
+ return menu->userdata;
+}
+
char*
get_menuitem_title(MenuItem* menuitem)
{
return menuitem->description;
}
+void*
+get_menuitem_userdata(MenuItem* menuitem)
+{
+ return menuitem->userdata;
+}
+
/* setters */
int
set_selected_item(Menu* menu, int selected_item)
{
menu->selected_item = selected_item;
-
return 0;
}
set_menu_focus(Menu* menu, bool focus)
{
menu->focused = focus;
-
+ return 0;
+}
+
+int
+set_menu_userdata(Menu* menu, void* userdata)
+{
+ menu->userdata = userdata;
+ return 0;
+}
+
+int
+set_menuitem_descrip(MenuItem* menuitem, char* descrip)
+{
+ menuitem->description = descrip;
+ return 0;
+}
+
+int
+set_menuitem_userdata(MenuItem* menuitem, void* userdata)
+{
+ menuitem->userdata = userdata;
return 0;
}
/* draw inner menu */
int cur_line = 0;
for (int i = 0; i < menu->menu_length-menu->scroll_offset; i++) {
-
+
+ MenuItem* curitem;
int wrapped_lines;
char* wrapped_text;
+
+ curitem = menu->menu_items[i];
/* wrap text by inserting newlines (maxwidth-1 for newline char)*/
- wrapped_text = wrap_text(menu->menu_items[i]->title, menu->max_width-1, &wrapped_lines);
+ wrapped_text = wrap_text(curitem->title, menu->max_width-1, &wrapped_lines);
/* color selected item */
wattron(menu->sub_win, COLOR_PAIR(
cur_line += wrapped_lines;
/* display number of items */
- /* if (menu->menu_items[i]->) */
+ if (strlen(curitem->description) > 0) {
+ mvwprintw(menu->sub_win, cur_line, 0, curitem->description);
+ cur_line += 1;
+ }
free(wrapped_text);
new_todoitem = malloc(sizeof(TodoItem));
new_todoitem->item_name = item_name;
- new_todoitem->description = NULL;
- new_todoitem->due = NULL;
+ new_todoitem->description = strdup("");
+ new_todoitem->due = strdup("");
new_todoitem->subtask_list = malloc(0);
new_todoitem->subtask_count = 0;
void
set_due(State* state, char* due)
{
-
+ state->cur_todoitem->due = due;
}
void
switch (type) {
case MD_SPAN_STRONG:
- printf("date, %s\n", state->last_block_text);
+ set_due(state, state->last_block_text);
break;
}
return 0;
items = malloc((list_length+1)*sizeof(MenuItem*));
for (int i = 0; i < list_length; i++) {
- items[i] = create_menuitem(item_list[i]->item_name);
+ MenuItem* new_menuitem;
+ new_menuitem = create_menuitem(item_list[i]->item_name);
+ /* using same struct, careful if it gets freed */
+ set_menuitem_userdata(new_menuitem, item_list[i]);
+
+ items[i] = new_menuitem;
}
items[list_length] = 0; //null terminate
return 0;
}
+/* menuitem */
+int
+update_menuitem_descrip(MenuItem* menuitem)
+{ /* need to do something about colored text */
+
+ TodoItem* item_data;
+ char* new_descrip;
+
+ item_data = (TodoItem*)get_menuitem_userdata(menuitem);
+ new_descrip = strdup("");
+
+ if (strlen(item_data->description) > 0) {
+ /* strcat(new_descrip, "☰ "); */
+ strcat(new_descrip, "~ ");
+ }
+ if (strlen(item_data->due) > 0) {
+ strcat(new_descrip, item_data->due);
+ strcat(new_descrip, " ");
+ }
+ if (item_data->subtask_count > 0) {
+ /* [, # done, /, # total, ], null */
+ int substask_len = 1+item_data->subtask_count+1+ 1+1;
+ char subtask_text[substask_len];
+ sprintf(subtask_text, "[%d/]", item_data->subtask_count);
+ strcat(new_descrip, subtask_text);
+ }
+
+ /* free old string */
+ if (strlen(new_descrip) > 0) {
+ free(get_menuitem_descrip(menuitem));
+ set_menuitem_descrip(menuitem, new_descrip);
+ }
+
+ return 0;
+}
+
/* popup */
WINDOW*
create_popup_win()
return NULL;
}
-
+/* helpers */
int
ungetstr(char* str)
{
#include "headers/utils.h"
#include "config.h"
+void render_step(BoardMenu* boardmenu);
+
int
main(int argc, char** argv)
{
BoardMenu* boardmenu;
boardmenu = create_board_menu(board);
- // this is temp
- for (int i = 0; i < boardmenu->menu_count; i++) {
- render_menu(boardmenu->menu_list[i]);
- }
+ /* need to render before user presses anything */
+ render_step(boardmenu);
char ch;
while ((ch = getch()) != BINDING_QUIT) {
break;
}
- for (int i = 0; i < boardmenu->menu_count; i++) {
- render_menu(boardmenu->menu_list[i]);
- }
+ render_step(boardmenu);
}
return 0;
}
+void
+render_step(BoardMenu* boardmenu)
+{
+ for (int i = 0; i < boardmenu->menu_count; i++) {
+
+ Menu* curmenu = boardmenu->menu_list[i];
+
+ /* update the descriptions - maybe not do this here */
+ for (int j = 0; j < get_menu_length(curmenu); j++) {
+ update_menuitem_descrip(get_menu_item(curmenu, j));
+ }
+
+ render_menu(curmenu);
+ }
+}