diff options
author | louie <lshprung@tutanota.com> | 2023-07-07 15:03:52 -0700 |
---|---|---|
committer | louie <lshprung@tutanota.com> | 2023-07-08 17:28:21 -0700 |
commit | 15b92cd8b26116a5c59fab1490f50b33a5cdf01c (patch) | |
tree | b7ab60c0601e2dda33ef915c0919c431c355f664 /src/draw.c | |
parent | 2d4457781f7262bef67d6681767db9393ce35b6d (diff) |
Create tui_text structure
Diffstat (limited to 'src/draw.c')
-rw-r--r-- | src/draw.c | 38 |
1 files changed, 33 insertions, 5 deletions
@@ -7,11 +7,14 @@ #include "draw.h" #include "entry.h" #include "group.h" +#include "tui_text.h" + +void draw_data(Tui_text **main_text, Group **groups, int g_count, Entry **entries, int e_count, WINDOW *w, int start_x, int start_y); -void draw_data(Group **groups, int g_count, Entry **entries, int e_count, WINDOW *w, int start_x, int start_y); void tui_init(Group **groups, int g_count, Entry **entries, int e_count) { int input; // capture user input + Tui_text *main_text = NULL; // keep track of text location - this array will be in order - top to bottom WINDOW *w_main; // set an interrupt to end cleanly @@ -29,7 +32,7 @@ void tui_init(Group **groups, int g_count, Entry **entries, int e_count) { refresh(); // draw groups and entries - draw_data(groups, g_count, entries, e_count, w_main, 1, 1); + draw_data(&main_text, groups, g_count, entries, e_count, w_main, 1, 1); wrefresh(w_main); input = getch(); @@ -44,24 +47,49 @@ void tui_end() { -void draw_data(Group **groups, int g_count, Entry **entries, int e_count, WINDOW *w, int start_x, int start_y) { +void draw_data(Tui_text **main_text, Group **groups, int g_count, Entry **entries, int e_count, WINDOW *w, int start_x, int start_y) { int i; int j; + int mt_index = 0; // separate index to keep track of main_text array char buf[BUF_LEN]; + + // initialize main_text + if(*main_text != NULL) free(*main_text); + *main_text = malloc(sizeof(Tui_text) * (e_count + g_count)); for(i = 0; i < g_count; ++i) { + // print group mvwprintw(w, start_y, start_x, "%s", group_get_name(&((*groups)[i]))); + + // save group in main_text array + tui_text_set_x(&((*main_text)[mt_index]), start_x); + tui_text_set_y(&((*main_text)[mt_index]), start_y); + tui_text_set_type(&((*main_text)[mt_index]), GROUP); + tui_text_set_data(&((*main_text)[mt_index]), &((*groups)[i])); + ++mt_index; + ++start_y; for(j = 0; j < e_count; ++j) { + // check if an entry belongs to the group if(entry_get_group_id(&((*entries)[j])) == group_get_id(&((*groups)[i]))) { + // print entry mvwprintw(w, start_y, start_x, "\t"); + // print date if there is one if(entry_get_due_date(&((*entries)[j])) != NULL) { memset(buf, 0, BUF_LEN); strftime(buf, BUF_LEN, "%a, %m/%d", entry_get_due_date(&((*entries)[j]))); wprintw(w, "%s: ", buf); } - //mvprintw(start_y, start_x, "\t%s", entry_get_title(&((*entries)[i]))); - wprintw(w, "%s", entry_get_title(&((*entries)[i]))); + // print entry title + wprintw(w, "%s", entry_get_title(&((*entries)[j]))); + + // save entry in main_text array + tui_text_set_x(&((*main_text)[mt_index]), start_x); + tui_text_set_y(&((*main_text)[mt_index]), start_y); + tui_text_set_type(&((*main_text)[mt_index]), ENTRY); + tui_text_set_data(&((*main_text)[mt_index]), &((*entries)[j])); + mt_index++; + ++start_y; } } |