From 9bd88177970ba1531be535ad81dfd2698a31bee9 Mon Sep 17 00:00:00 2001 From: Zvonimir Rudinski Date: Sun, 2 Jun 2024 06:33:54 +0200 Subject: [PATCH] add proper scroll --- main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 50ebcb5..3476285 100644 --- a/main.c +++ b/main.c @@ -159,7 +159,7 @@ void input_string(int terminal_width, int terminal_height, char *buffer, int buf void display_todos(int width, int height, int current_line) { int current_y = 1; - int current_index = current_line; + int current_index = 0; const char *padding = "..."; unsigned long title_length = 0; unsigned long padding_length = strlen(padding); @@ -168,9 +168,14 @@ void display_todos(int width, int height, int current_line) { attron(COLOR_PAIR(DEFAULT_PAIR)); - // TODO: Use an offset or something - - while(current_y < height - 2) { + // calculate the offset + if (height - 4 <= current_line) { + // ignore the first n todos + current_index = current_line - (height - 4); + } + + // while we have space to print todos + while (current_y < height - 2) { // check if we're out of bounds if (current_index >= arrlen(todos)) { break;