From: Daniel Liu Date: Sat, 13 Feb 2021 22:17:31 +0000 (-0500) Subject: subwin problems X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=72509aeb4746b7ea2bd9cc84cfd45dfb87042e07;p=taskasaur.git subwin problems --- diff --git a/config.h b/config.h index 3c94504..ad8648d 100644 --- a/config.h +++ b/config.h @@ -41,6 +41,8 @@ static int menu_non_selected_color = COLOR_GREEN; #define BINDING_APPEND_ITEM 'a' #define BINDING_INSERT_ABOVE 'O' #define BINDING_INSERT_BELOW 'o' +#define BINDING_MOVE_MENU_LEFT '<' +#define BINDING_MOVE_MENU_RIGHT '>' #define BINDING_EDIT_ITEM 'i' #endif diff --git a/headers/menu.h b/headers/menu.h index 617f416..b49e5b0 100644 --- a/headers/menu.h +++ b/headers/menu.h @@ -28,7 +28,9 @@ typedef struct MenuItem MenuItem; extern MenuItem* create_menuitem(char* contents); extern Menu* create_menu(char* menu_name, MenuItem** item_list); +extern WINDOW* get_menu_win(Menu* menu); extern int set_menu_win(Menu* menu, WINDOW* win); +extern WINDOW* get_menu_subwin(Menu* menu); extern MenuItem* get_menu_item(Menu* menu, int index); extern int set_menu_focus(Menu* menu, bool focus); extern int get_selected_item(Menu* menu); diff --git a/headers/utils.h b/headers/utils.h index 3dab4a9..9783172 100644 --- a/headers/utils.h +++ b/headers/utils.h @@ -22,4 +22,7 @@ extern int min(int a, int b); extern char* wrap_text(char* str, int max_width, int* lines); +/* array stuff */ +extern int ar_swap_item(void** arr, int src_index, int dest_index); + #endif diff --git a/menu.c b/menu.c index 6768de2..ffb49a6 100644 --- a/menu.c +++ b/menu.c @@ -76,6 +76,12 @@ create_menu(char* menu_name, MenuItem** item_list) return new_menu; } +WINDOW* +get_menu_win(Menu* menu) +{ + return menu->menu_win; +} + int set_menu_win(Menu* menu, WINDOW* win) { @@ -98,6 +104,12 @@ set_menu_win(Menu* menu, WINDOW* win) return 0; } +WINDOW* +get_menu_subwin(Menu* menu) +{ + return menu->sub_win; +} + MenuItem* get_menu_item(Menu* menu, int index) { @@ -137,11 +149,7 @@ get_menu_length(Menu* menu) int swap_item(Menu* menu, int src_index, int dest_index) { - MenuItem* temp; - - temp = menu->menu_items[dest_index]; - menu->menu_items[dest_index] = menu->menu_items[src_index]; - menu->menu_items[src_index] = temp; + ar_swap_item(menu->menu_items, src_index, dest_index); return 0; } diff --git a/taskasaur.c b/taskasaur.c index dc90110..8732678 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -5,6 +5,9 @@ #include "headers/utils.h" #include "config.h" +// this is temp +#define MENU_WIDTH 40 + typedef struct BoardMenu { Menu** menu_list; int menu_count; @@ -16,6 +19,7 @@ int set_selected_menu(BoardMenu* boardmenu, int index); MenuItem** todolist_to_menuitem(TodoItem** item_list, int list_length); Menu** make_menus(Board* board, int todolist_length); +int swap_menu(BoardMenu* boardmenu, int src_index, int dest_index); int main(int argc, char** argv) @@ -138,6 +142,21 @@ main(int argc, char** argv) break; case BINDING_INSERT_BELOW: menu_driver(active_menu, MENU_INSERT_BELOW); + break; + /* case BINDING_MOVE_MENU_LEFT: */ + /* if (boardmenu->selected-1 < 0) break; */ + + /* swap_menu(boardmenu, boardmenu->selected, boardmenu->selected-1); */ + /* boardmenu->selected -= 1; */ + /* set_selected_menu(boardmenu, boardmenu->selected); */ + +/* break; */ +/* case BINDING_MOVE_MENU_RIGHT: */ +/* if (boardmenu->selected >= boardmenu->menu_count-1) break; */ +/* swap_menu(boardmenu, boardmenu->selected, boardmenu->selected+1); */ + /* boardmenu->selected += 1; */ + /* set_selected_menu(boardmenu, boardmenu->selected); */ + break; case BINDING_EDIT_ITEM: menu_driver(active_menu, MENU_EDIT); @@ -209,8 +228,6 @@ todolist_to_menuitem(TodoItem** item_list, int list_length) Menu** make_menus(Board* board, int todolist_length) { - // this is temp - #define MENU_WIDTH 40 Menu** menu_list; @@ -241,3 +258,28 @@ make_menus(Board* board, int todolist_length) return menu_list; } + +int +swap_menu(BoardMenu* boardmenu, int src_index, int dest_index) +{ + /* reposition menus */ + mvwin(get_menu_win(boardmenu->menu_list[src_index]), + 1, 1+MENU_WIDTH*dest_index + ); + mvwin(get_menu_win(boardmenu->menu_list[dest_index]), + 1, 1+MENU_WIDTH*src_index + ); + wrefresh(get_menu_win(boardmenu->menu_list[src_index])); + wrefresh(get_menu_win(boardmenu->menu_list[dest_index])); + /* wclear(get_menu_win(boardmenu->menu_list[src_index])); */ + /* wclear(get_menu_win(boardmenu->menu_list[dest_index])); */ + /* touchwin(get_menu_win(boardmenu->menu_list[src_index])); */ + /* touchwin(get_menu_win(boardmenu->menu_list[dest_index])); */ + clear(); + + /* swap in array */ + ar_swap_item(boardmenu->menu_list, src_index, dest_index); + + return 0; +} + diff --git a/utils.c b/utils.c index a649239..f6f719a 100644 --- a/utils.c +++ b/utils.c @@ -47,4 +47,17 @@ wrap_text(char* str, int max_width, int* lines) } +/* array stuff */ +int +ar_swap_item(void** arr, int src_index, int dest_index) +{ + void* temp; + + temp = arr[dest_index]; + arr[dest_index] = arr[src_index]; + arr[src_index] = temp; + + return 0; +} +