From: Daniel Date: Fri, 26 Feb 2021 23:43:01 +0000 (-0500) Subject: lots of fixes X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=abf215afaba441f488105fb9d30d95264c2e5850;p=taskasaur.git lots of fixes --- diff --git a/makefile b/makefile index 810a1a4..33e5495 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ CC=gcc -CFLAGS=-g -Wall -Wno-unused-variable -Wno-switch -LIBS=-lncursesw -lmd4c +CFLAGS=-g -Wall -Wno-unused-variable -Wno-unused-but-set-variable -Wno-switch +LIBS=-ltinfo -lncurses -lmd4c make: taskasaur diff --git a/menu.c b/menu.c index a7fbbec..621607b 100644 --- a/menu.c +++ b/menu.c @@ -273,13 +273,20 @@ menu_insert_mode(Menu* menu, int insert_index) { char temp[MAX_CONTENTS_LENGTH+1]; // remember null char* new_contents; + int insert_pos; curs_on(); + // account for multiline items + insert_pos = menu->scroll_offset; + for (int i = 0; i < insert_index; i++) { + insert_pos += item_height(menu->menu_items[i]); + } + /* move cursor to right spot */ ungetstr(menu->menu_items[insert_index]->title); mvwgetnstr(menu->sub_win, - insert_index, // account for wrap later too + insert_pos, 0, temp, MAX_CONTENTS_LENGTH @@ -337,16 +344,19 @@ menu_driver(Menu* menu, MenuAction action) case MENU_APPEND: insert_item(menu, create_blank_menuitem(), menu->menu_length); + render_menu(menu); // refresh after inserting menu_insert_mode(menu, menu->selected_item); break; case MENU_INSERT_ABOVE: insert_item(menu, create_blank_menuitem(), menu->selected_item); + render_menu(menu); menu_insert_mode(menu, menu->selected_item); break; case MENU_INSERT_BELOW: insert_item(menu, create_blank_menuitem(), menu->selected_item+1); + render_menu(menu); menu_insert_mode(menu, menu->selected_item); // inserted item is cur now break; @@ -386,7 +396,8 @@ render_menu(Menu* menu) // may be dangerous, assumes render after every action menu->scroll_offset += 1; } else if (menu->selected_item < menu->scroll_offset) { - menu->scroll_offset -= 1; + menu->scroll_offset = menu->scroll_offset-1; + if (menu->scroll_offset < 0) menu->scroll_offset = 0; } /* draw inner menu */ diff --git a/render.c b/render.c index 6760c9c..ee77fe6 100644 --- a/render.c +++ b/render.c @@ -211,6 +211,7 @@ set_selected_menu(BoardMenu* boardmenu, int index) /* also try to jump to a similar position if possible */ /* rn theres a bug if old menu is empty */ new_pos = min(get_selected_item(old_menu), get_menu_length(new_menu)-1); + if (new_pos < 0) new_pos = 0; set_selected_item(new_menu, new_pos); boardmenu->selected = index; diff --git a/taskasaur.c b/taskasaur.c index dbc3d31..5392cf6 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -64,6 +64,7 @@ main(int argc, char** argv) break; case BINDING_MOVE_ITEM_LEFT: if (boardmenu->selected-1 < 0) break; + if (get_menu_length(boardmenu->menu_list[boardmenu->selected]) == 0) break; { Menu* from_menu; Menu* to_menu; @@ -92,6 +93,7 @@ main(int argc, char** argv) break; case BINDING_MOVE_ITEM_RIGHT: if (boardmenu->selected >= boardmenu->menu_count-1) break; + if (get_menu_length(boardmenu->menu_list[boardmenu->selected]) == 0) break; // this is legit cpy paste please fix this { Menu* from_menu;