aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-09-25 09:01:04 +0000
committerdam <dam@gudinoff>2022-09-25 09:01:04 +0000
commit4ac75b26772d69a0cf1fe520b013919341b3750a (patch)
treefcddb49b3f14e3dc88594f34accbc81f4fceb0bb /main.c
parent2763fc6ad122f64cbd5023b4cbe7ff4d7101c805 (diff)
downloadtask-time-tracker-4ac75b26772d69a0cf1fe520b013919341b3750a.tar.zst
task-time-tracker-4ac75b26772d69a0cf1fe520b013919341b3750a.zip
Small cleanup on draw_tui.
Diffstat (limited to 'main.c')
-rw-r--r--main.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/main.c b/main.c
index f52f383..eff8214 100644
--- a/main.c
+++ b/main.c
@@ -717,15 +717,32 @@ void initialize_tui() {
void draw_tui(database_t *db, layout_t *layout) {
+ const static int adjust_first_day_of_week[] = {
+ (0 + FIRST_DAY_OF_WEEK) % WEEK_DAYS,
+ (1 + FIRST_DAY_OF_WEEK) % WEEK_DAYS,
+ (2 + FIRST_DAY_OF_WEEK) % WEEK_DAYS,
+ (3 + FIRST_DAY_OF_WEEK) % WEEK_DAYS,
+ (4 + FIRST_DAY_OF_WEEK) % WEEK_DAYS,
+ (5 + FIRST_DAY_OF_WEEK) % WEEK_DAYS,
+ (6 + FIRST_DAY_OF_WEEK) % WEEK_DAYS,
+ };
+
int x, y;
+ // Get context information.
+ task_t *active_task = get_active_task(db);
+ task_t *selected_task = get_selected_task(db);
+ time_t now_utc = time(NULL);
+ int now_week_day = localtime(&now_utc)->tm_wday;
+
// The first column expands to fill the remaining space dynamically.
layout->column_widths[0] = size_x - (NUM_OF_COLUMNS - 1) - 2;
for (int idx = 1; idx < NUM_OF_COLUMNS; idx++) {
layout->column_widths[0] -= layout->column_widths[idx];
}
- // TODO Unsure if this is needed.
+ // Reset theme and clear screen.
+ attrset(A_NORMAL);
erase();
// Draw outer border.
@@ -762,25 +779,20 @@ void draw_tui(database_t *db, layout_t *layout) {
x += layout->column_widths[L_TITLE_IDX];
// Headers : days
-
- time_t now_utc = time(NULL); // Get current UTC time.
- int week_day = localtime(&now_utc)->tm_wday; // Get current day of the week.
-
- for (int idx = 0; idx < WEEK_DAYS; idx++) {
+ for (int raw_idx = 0; raw_idx < WEEK_DAYS; raw_idx++) {
+ int idx = adjust_first_day_of_week[raw_idx];
x++;
- int day_idx = (idx + FIRST_DAY_OF_WEEK) % WEEK_DAYS;
-
// Apply theme.
- if (day_idx == week_day && db->active_task >= 0) {
+ if (idx == now_week_day && active_task != NULL) {
attron(COLOR_PAIR(THEME_E) | A_BOLD);
}
- else if(day_idx == week_day) {
+ else if(idx == now_week_day) {
attron(COLOR_PAIR(THEME_D) | A_BOLD);
}
- mvaddstr(y, x + layout->alignment_offsets[day_idx + L_DAYS_IDX], layout->table_headers[day_idx + L_DAYS_IDX]);
- x += layout->column_widths[day_idx + L_DAYS_IDX];
+ mvaddstr(y, x + layout->alignment_offsets[idx + L_DAYS_IDX], layout->table_headers[idx + L_DAYS_IDX]);
+ x += layout->column_widths[idx + L_DAYS_IDX];
// Reset theme.
attrset(A_NORMAL);
@@ -797,11 +809,9 @@ void draw_tui(database_t *db, layout_t *layout) {
uint64_t total_time = 0;
int column_width;
-
- task_t *active_task = get_active_task(db);
- task_t *selected_task = get_selected_task(db);
// TODO This is some sort of pagination to allow scrolling through the tasks.
+ // TODO How does this behaves when no task is selected?
y = 0;
size_t available_rows = size_y - 2;
size_t idx_start = (db->selected_task / available_rows) * available_rows;