aboutsummaryrefslogtreecommitdiff
path: root/ttt.jai
diff options
context:
space:
mode:
Diffstat (limited to 'ttt.jai')
-rw-r--r--ttt.jai96
1 files changed, 50 insertions, 46 deletions
diff --git a/ttt.jai b/ttt.jai
index 8f4b801..9a5f26a 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -86,10 +86,10 @@ pos_x : s32;
pos_y : s32;
Styles :: enum s16 {
- STYLE_SELECTED :: 1;
+ SELECTED :: 1;
SELECTED_INVERTED;
- STYLE_ACTIVE;
- STYLE_ACTIVE_SELECTED;
+ ACTIVE;
+ ACTIVE_SELECTED;
ERROR;
}
@@ -1017,10 +1017,10 @@ initialize_tui :: () {
// Initialize pairs of colors.
start_color();
use_default_colors(); // Using default (-1) instead of COLOR_BLACK.
- init_pair(xx Styles.STYLE_SELECTED, COLOR_BLACK, COLOR_CYAN);
+ init_pair(xx Styles.SELECTED, COLOR_BLACK, COLOR_CYAN);
init_pair(xx Styles.SELECTED_INVERTED, COLOR_CYAN, -1);
- init_pair(xx Styles.STYLE_ACTIVE, COLOR_BLUE, -1);
- init_pair(xx Styles.STYLE_ACTIVE_SELECTED, COLOR_WHITE, COLOR_BLUE);
+ init_pair(xx Styles.ACTIVE, COLOR_BLUE, -1);
+ init_pair(xx Styles.ACTIVE_SELECTED, COLOR_WHITE, COLOR_BLUE);
init_pair(xx Styles.ERROR, COLOR_RED, -1);
}
@@ -1067,6 +1067,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
box(stdscr, 0, 0);
// Draw table grids.
+ // TODO Maybe this could be simplified?
y = 0;
x = 0;
for 0..layout.columns.count-2 {
@@ -1078,7 +1079,7 @@ draw_tui :: (db: *Database, layout: *Layout) {
}
mvaddch(size_y-1, xx x, ACS_BTEE);
}
-return; /*
+
///////////////////////////////////////////////////////////////////////////
// Draw headers.
@@ -1086,94 +1087,97 @@ return; /*
x = 0;
// Headers : title
- x++;
- col = &layout->columns[L_TITLE_IDX];
- mvaddstr(y, x + col->alignment_offset, (db == &archive ? layout->archive_title : col->header));
- x += col->width;
+ x += 1;
+ col = *layout.columns[L_TITLE_IDX];
+ mvaddstr(xx y, xx (x + col.alignment_offset), ifx db == *archive then layout.archive_title.data else col.header.data);
+ x += col.width;
// Headers : days
- for (int raw_idx = 0; raw_idx < NUM_WEEK_DAYS; raw_idx++) {
- int idx = adjust_first_day_of_week[raw_idx];
- x++;
+ for 0..NUM_WEEK_DAYS-1 {
+ //for (int raw_idx = 0; raw_idx < NUM_WEEK_DAYS; raw_idx++) {
+ idx := adjust_first_day_of_week[it];
+ x += 1;
// Apply theme.
- if (idx == now_week_day && active_task != NULL) {
- attron(COLOR_PAIR(STYLE_ACTIVE) | A_BOLD);
+ if (idx == now_week_day && active_task != null) {
+ attron(COLOR_PAIR(xx Styles.ACTIVE) | A_BOLD);
}
else if (idx == now_week_day) {
- attron(COLOR_PAIR(SELECTED_INVERTED) | A_BOLD);
+ attron(COLOR_PAIR(xx Styles.SELECTED_INVERTED) | A_BOLD);
}
- col = &layout->columns[L_DAYS_IDX + idx];
- mvaddstr(y, x + col->alignment_offset, col->header);
- x += col->width;
+ col = *layout.columns[L_DAYS_IDX + idx];
+ mvaddstr(xx y, xx (x + col.alignment_offset), col.header.data);
+ x += col.width;
// Reset theme.
attrset(A_NORMAL);
}
// Headers : total
- x++;
- col = &layout->columns[L_TOTAL_IDX];
- mvaddstr(y, x + col->alignment_offset, col->header);
+ x += 1;
+ col = *layout.columns[L_TOTAL_IDX];
+ mvaddstr(xx y, xx (x + col.alignment_offset), col.header.data);
///////////////////////////////////////////////////////////////////////////
// Draw tasks.
- uint64_t total_time = 0;
- int column_width;
+ total_time := 0;
+ column_width: int;
y = 0;
// Pagination based on currently selected task (show page where selected task is).
- size_t idx_start = (db->selected_task / layout_tasks_rows) * layout_tasks_rows;
+ idx_start := (db.selected_idx / layout_tasks_rows) * layout_tasks_rows;
// Display up to rows allowed by the layout, or less if reached end of database.
- size_t idx_stop = idx_start + (layout_tasks_rows > db->count - idx_start ? db->count - idx_start : layout_tasks_rows);
- for (size_t idx = idx_start; idx < idx_stop; idx++) {
- task_st *task = &db->tasks[idx];
- y++;
+ idx_stop := idx_start + (ifx layout_tasks_rows > db.tasks.count - idx_start then db.tasks.count - idx_start else layout_tasks_rows);
+ for idx: idx_start..idx_stop {
+ //for (size_t idx = idx_start; idx < idx_stop; idx++) {
+ task := *db.tasks[idx];
+ y += 1;
x = 0;
// Apply theme.
if (task == active_task && task == selected_task) {
- attron(COLOR_PAIR(STYLE_ACTIVE_SELECTED) | A_BOLD);
+ attron(COLOR_PAIR(xx Styles.ACTIVE_SELECTED) | A_BOLD);
}
else if (task == selected_task) {
- attron(COLOR_PAIR(STYLE_SELECTED));
+ attron(COLOR_PAIR(xx Styles.SELECTED));
}
else if (task == active_task) {
- attron(COLOR_PAIR(STYLE_ACTIVE) | A_BOLD);
+ attron(COLOR_PAIR(xx Styles.ACTIVE) | A_BOLD);
}
// Task title.
- x++;
- column_width = layout->columns[L_TITLE_IDX].width;
- mvprintw(y, x, "%-*.*s", column_width, column_width, task->name);
+ x += 1;
+ column_width = layout.columns[L_TITLE_IDX].width;
+ mvprintw(y, x, "%-*.*s", column_width, column_width, task.name);
x += column_width;
// Task times.
total_time = 0;
- for (int idx = 0; idx < NUM_WEEK_DAYS; idx++) {
- x++;
+ for 0..NUM_WEEK_DAYS-1 {
+ //for (int idx = 0; idx < NUM_WEEK_DAYS; idx++) {
+ x += 1;
- int day_idx = (idx + FIRST_DAY_OF_WEEK) % NUM_WEEK_DAYS;
+ day_idx := (idx + FIRST_DAY_OF_WEEK) % NUM_WEEK_DAYS;
- column_width = layout->columns[L_DAYS_IDX + day_idx].width;
- int64_t task_stime = task->times[day_idx];
+ column_width = layout.columns[L_DAYS_IDX + day_idx].width;
+ task_stime := task.times[day_idx];
total_time = add_int64(total_time, task_stime);
- mvprintw_time(y, x, task_stime, column_width);
+ mvprintw_time(xx y, xx x, task_stime, column_width);
x += column_width;
}
// Task total.
- x++;
- mvprintw_time(y, x, total_time, layout->columns[L_TOTAL_IDX].width);
+ x += 1;
+ mvprintw_time(xx y, xx x, total_time, layout.columns[L_TOTAL_IDX].width);
// Reset theme.
attrset(A_NORMAL);
}
-
+ return; /*
///////////////////////////////////////////////////////////////////////////
// Draw selected/total tasks.
int size = snprintf(NULL, 0, " %td/%zd ", db->selected_task + 1, db->count);
@@ -1490,7 +1494,7 @@ main :: () {
active_task := get_active_task(db);
selected_task := get_selected_task(db);
action_style := A_BOLD | COLOR_PAIR(xx ifx selected_task == active_task && selected_task != null
- then Styles.STYLE_ACTIVE
+ then Styles.ACTIVE
else Styles.SELECTED_INVERTED);
error_style := A_BOLD | COLOR_PAIR(xx Styles.ERROR);
selected_task_row : int = ifx is_terminal_too_small then 0