From ae8beb20a2a837824cfda4d748fbe07b26a161f0 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 6 Jun 2022 19:48:09 +0200 Subject: tab bar working --- client/strings.c | 2 +- client/ui.c | 9 ++++----- client/ui.h | 9 +++------ client/ui_dirc.c | 15 ++++++++++----- client/ui_start.c | 2 +- client/ui_tabbar.c | 29 +++++++++++++++++++++-------- 6 files changed, 40 insertions(+), 26 deletions(-) diff --git a/client/strings.c b/client/strings.c index 720f7b8..5dbb6bd 100644 --- a/client/strings.c +++ b/client/strings.c @@ -15,7 +15,7 @@ void w2_strings_modes_init() { void w2_strings_tabs_init() { g_w2_tab_strings[W2_UI_TAB_START] = W2_UI_TAB_LABEL_START; - g_w2_tab_strings[W2_UI_TAB_DIRC] = W2_UI_TAB_LABEL_DIRC; + g_w2_tab_strings[W2_UI_TAB_DIRC] = W2_UI_TAB_LABEL_DIRC; } void w2_strings_init() { diff --git a/client/ui.c b/client/ui.c index a1d15ad..10e1814 100644 --- a/client/ui.c +++ b/client/ui.c @@ -13,10 +13,10 @@ WINDOW *g_w2_ui_win; WINDOW *g_w2_ui_pad_tabbar; WINDOW *g_w2_ui_pad_body; -unsigned int g_w2_ui_width = 0; -unsigned int g_w2_ui_height = 0; -w2_e_ui_tab g_w2_ui_current_tab = W2_UI_TAB_START; -w2_e_ui_tab g_w2_ui_last_tab; +unsigned int g_w2_ui_width = 0; +unsigned int g_w2_ui_height = 0; +w2_e_ui_tabs g_w2_ui_current_tab = W2_UI_TAB_START; +w2_e_ui_tabs g_w2_ui_last_tab; void w2_wmvaddstr(WINDOW *win, unsigned int y, unsigned int x, char *str) { wmove(win, y, x); @@ -77,4 +77,3 @@ void w2_ui_paint_statusbar() { for (unsigned int i = 0; i < g_w2_ui_width; i++) temp[i] = '-'; mvaddnstr(3, 0, temp, g_w2_ui_width); } - diff --git a/client/ui.h b/client/ui.h index cbf18ee..ccab75d 100644 --- a/client/ui.h +++ b/client/ui.h @@ -8,8 +8,8 @@ #define W2_UI_TAB_COUNT 2 typedef enum { W2_UI_TAB_START = 0, - W2_UI_TAB_DIRC = 1, -} w2_e_ui_tab; + W2_UI_TAB_DIRC = 1, +} w2_e_ui_tabs; extern WINDOW *g_w2_ui_win; extern WINDOW *g_w2_ui_pad_tabbar; @@ -17,7 +17,7 @@ extern WINDOW *g_w2_ui_pad_body; extern unsigned int g_w2_ui_width; extern unsigned int g_w2_ui_height; extern void (*g_w2_tab_ptrs[W2_UI_TAB_COUNT])(bool first); -extern w2_e_ui_tab g_w2_ui_current_tab; +extern w2_e_ui_tabs g_w2_ui_current_tab; /** update terminal props */ void w2_ui_update(); @@ -40,6 +40,3 @@ void w2_ui_tab_start(bool first); void w2_wmvaddstr(WINDOW *win, unsigned int y, unsigned int x, char *str); void w2_wmvaddnstr(WINDOW *win, unsigned int y, unsigned int x, char *str, unsigned int len); - - - diff --git a/client/ui_dirc.c b/client/ui_dirc.c index d275ddf..d394f8d 100644 --- a/client/ui_dirc.c +++ b/client/ui_dirc.c @@ -94,11 +94,16 @@ void w2_ui_tab_dirc(bool first) { unsigned int rb = 0; unsigned int rf = 0; while ((ch = getch()) != -1) { - if (ch == 'e' || ch == 'w') lf++; - if (ch == 'd' || ch == 's') lb++; - if (ch == 'q' || ch == 'w') rf++; - if (ch == 'a' || ch == 's') rb++; - if (ch == ' ') w2_send_mode(W2_M_DIRC); + if (ch == 'e' || ch == 'w') + lf++; + else if (ch == 'd' || ch == 's') + lb++; + else if (ch == 'q' || ch == 'w') + rf++; + else if (ch == 'a' || ch == 's') + rb++; + else if (ch == ' ') + w2_send_mode(W2_M_DIRC); } int drive_l = w2_dirc_motor_l(lf, lb); diff --git a/client/ui_start.c b/client/ui_start.c index b656c35..7608792 100644 --- a/client/ui_start.c +++ b/client/ui_start.c @@ -1,5 +1,5 @@ -#include "ui.h" #include "i18n.h" +#include "ui.h" void w2_ui_tab_start(bool first) { refresh(); diff --git a/client/ui_tabbar.c b/client/ui_tabbar.c index fc43db9..9f5707a 100644 --- a/client/ui_tabbar.c +++ b/client/ui_tabbar.c @@ -1,6 +1,7 @@ #include #include +#include "strings.h" #include "ui.h" unsigned int g_w2_ui_tabbar_scroll = 0; @@ -9,17 +10,29 @@ void (*g_w2_tab_ptrs[W2_UI_TAB_COUNT])(bool first); void w2_ui_tabbar_init() { g_w2_tab_ptrs[W2_UI_TAB_START] = &w2_ui_tab_start; - g_w2_tab_ptrs[W2_UI_TAB_DIRC] = &w2_ui_tab_dirc; + g_w2_tab_ptrs[W2_UI_TAB_DIRC] = &w2_ui_tab_dirc; } -char* w2_ui_tabbar_format_tab(char* name, bool selected) { - char* ret_val = malloc(strlen(name) + 3); - printf("%c%s%c", selected ? '[' : ' ', name, selected ? ']' : ' '); - return ret_val; +void w2_ui_switch_tab(w2_e_ui_tabs next_tab) { + g_w2_ui_current_tab = next_tab % W2_UI_TAB_COUNT; + wclear(g_w2_ui_pad_body); +} + +void w2_ui_tabbar_logic() { + int ch; + while ((ch = getch()) != -1) { + if (ch == '\t') w2_ui_switch_tab(g_w2_ui_current_tab + 1); + } } void w2_ui_paint_tabbar() { - char temp[g_w2_ui_width]; - sprintf(temp, "-- tab bar here --"); - w2_wmvaddstr(g_w2_ui_pad_tabbar, 0, g_w2_ui_width / 2 - strlen(temp) / 2, temp); + w2_ui_tabbar_logic(); + wmove(g_w2_ui_pad_tabbar, 0, 0); + for (unsigned int i = 0; i < W2_UI_TAB_COUNT; i++) { + g_w2_ui_tabbar_lengths[i] += 2 + strlen(g_w2_tab_strings[i]); + + wprintw(g_w2_ui_pad_tabbar, " %c%s%c", g_w2_ui_current_tab == i ? '[' : ' ', + g_w2_tab_strings[i], g_w2_ui_current_tab == i ? ']' : ' '); + } + wprintw(g_w2_ui_pad_tabbar, " "); } -- cgit v1.2.3