From 4395e1184320f15426a70a9ebbe47f26e5f5fbba Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Thu, 11 Dec 2025 17:55:52 +0200 Subject: [PATCH] fixes and improves tab navigation mechanism. --- TODO.md | 3 +- src/common.h | 8 ++++ src/connection.c | 17 ++------ src/connection.h | 2 +- src/deps.mk | 14 +++---- src/server.c | 3 +- src/ui/app.c | 14 +++---- src/ui/app.h | 5 ++- src/ui/modals/ask_server_addr.c | 48 +++++++++++++--------- src/ui/modals/login.c | 30 +++++++------- src/ui/widget.h | 1 + src/ui/widget/button.c | 8 +++- src/ui/widget/dialogue.c | 72 ++++++++++++++++++++------------- src/ui/widget/dialogue.h | 7 ++-- src/ui/widget/group.c | 67 +++++++++++++----------------- src/ui/widget/group.h | 17 +++++--- src/ui/widget/input.c | 13 +++--- 17 files changed, 180 insertions(+), 149 deletions(-) create mode 100644 src/common.h diff --git a/TODO.md b/TODO.md index ea611ba..48eb438 100644 --- a/TODO.md +++ b/TODO.md @@ -5,4 +5,5 @@ TODO: - [x] use parent widgets pointers to count the margins correctly - [ ] Hotkeys for buttons - [ ] Simpler refresh on typing / entering in input -- [ ] Group elements as lists \ No newline at end of file +- [ ] Group elements as lists +- [ ] Process arrows \ No newline at end of file diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..76b7bcf --- /dev/null +++ b/src/common.h @@ -0,0 +1,8 @@ +#ifndef COMMON_H +#define COMMON_H +#include +typedef struct { + uint32_t cur_y, cur_x; + uint32_t max_y, max_x; +} coordinates_t; +#endif \ No newline at end of file diff --git a/src/connection.c b/src/connection.c index 311feb1..b30df8d 100644 --- a/src/connection.c +++ b/src/connection.c @@ -41,20 +41,11 @@ void clear_params(params_t *params) { params->uname = NULL; } -void get_missing_params(params_t *params) { - size_t lsize; - char *bufptr = NULL; - +void get_ip_port(params_t *params, char *ip, char *port) { struct sockaddr_in addr; - - if (!params->addr) { - printf("host> "); - getline(&bufptr, &lsize, stdin); - inet_aton(bufptr, &(addr.sin_addr)); - params->addr = addr.sin_addr.s_addr; - free(bufptr); - bufptr = NULL; - } + inet_aton(ip, &(addr.sin_addr)); + params->addr = addr.sin_addr.s_addr; + params->port = htons(atoi(port)); } void close_session(int sd) { close(sd); } diff --git a/src/connection.h b/src/connection.h index 3f8df6e..79b9296 100644 --- a/src/connection.h +++ b/src/connection.h @@ -5,7 +5,7 @@ void connect_to_server(int sd, params_t *params); void init_params(params_t *restrict); void clear_params(params_t *params); -void get_missing_params(params_t *restrict); +void get_ip_port(params_t *params, char *ip, char *port); void close_session(int sd); int init_client(); void analyze_args(int argc, char *argv[], params_t *restrict); diff --git a/src/deps.mk b/src/deps.mk index d3e8ba8..b4f2c1a 100644 --- a/src/deps.mk +++ b/src/deps.mk @@ -5,13 +5,13 @@ file_processor.o: src/file_processor.c src/client.h src/main.h \ src/types.h src/query.h main.o: src/main.c src/connection.h src/main.h src/types.h src/ui/app.h \ src/ui/widget/dialogue.h src/ui/widget/../widget.h \ - src/ui/widget/../../main.h src/ui/widget/button.h \ - src/ui/widget/../../main.h src/ui/widget/group.h \ - src/ui/modals/ask_server_addr.h src/ui/modals/../app.h \ - src/ui/modals/../widget/dialogue.h src/ui/modals/login.h src/ui/widget.h \ - src/ui/widget/dialogue.h + src/ui/widget/../../main.h src/ui/widget/../../common.h \ + src/ui/widget/button.h src/ui/widget/../../main.h src/ui/widget/group.h \ + src/ui/../common.h src/ui/modals/ask_server_addr.h \ + src/ui/modals/../app.h src/ui/modals/../widget/dialogue.h \ + src/ui/modals/login.h src/ui/widget.h src/ui/widget/dialogue.h query.o: src/query.c src/file_processor.h src/main.h src/types.h \ src/connection.h src/client.h src/server.h -server.o: src/server.c src/client.h src/main.h src/types.h \ - src/connection.h src/query.h src/ui.h +server.o: src/server.c src/client.h src/main.h src/types.h src/query.h \ + src/ui.h ui.o: src/ui.c diff --git a/src/server.c b/src/server.c index 9581c2f..7b8ee30 100644 --- a/src/server.c +++ b/src/server.c @@ -1,5 +1,4 @@ #include "client.h" -#include "connection.h" #include "main.h" #include "query.h" #include "ui.h" @@ -69,7 +68,7 @@ int process_server_command(char *line, int l_len, query_args_t *q_args) { free(params->pass); params->uname = NULL; params->pass = NULL; - get_missing_params(params); + // get_missing_params(params); write(q_args->sd, params->uname, strlen(params->uname)); return 0; } diff --git a/src/ui/app.c b/src/ui/app.c index 0dd7a0d..50d04c7 100644 --- a/src/ui/app.c +++ b/src/ui/app.c @@ -13,10 +13,10 @@ app_t *init_app() { app_t *_app = calloc(1, sizeof(app_t)); // associate values for screen size - _app->cur_y = y_max; - _app->cur_x = x_max; + _app->coordinates.max_x = _app->coordinates.cur_x = x_max; + _app->coordinates.max_y = _app->coordinates.cur_y = y_max; - _app->win = newwin(_app->cur_y, _app->cur_x, 0, 0); + _app->win = newwin(_app->coordinates.cur_y, _app->coordinates.cur_x, 0, 0); // define the width for each sub window int menu_w_x = x_max / 6; @@ -79,18 +79,18 @@ void print_bars(app_t *app) { wattrset(app->win, A_REVERSE); // print top and bottom bars - for (int i = 1; i < app->cur_x - 1; i++) { + for (int i = 1; i < app->coordinates.cur_x - 1; i++) { mvwprintw(app->win, 1, i, " "); - mvwprintw(app->win, app->cur_y - 2, i, " "); + mvwprintw(app->win, app->coordinates.cur_y - 2, i, " "); } // add content to the top bar mvwprintw(app->win, 1, 2, "example cprint_barsurses app | "); mvwprintw(app->win, 1, sizeof "example cprint_barsurses app | " + 1, - "size %d, %d", app->cur_x, app->cur_y); + "size %d, %d", app->coordinates.cur_x, app->coordinates.cur_y); // add content to the bottom bar - mvwprintw(app->win, app->cur_y - 2, 2, "F1 - Help | F9 - Quit"); + mvwprintw(app->win, app->coordinates.cur_y - 2, 2, "F1 - Help | F9 - Quit"); wattroff(app->win, A_REVERSE); } diff --git a/src/ui/app.h b/src/ui/app.h index f455242..70a851d 100644 --- a/src/ui/app.h +++ b/src/ui/app.h @@ -1,8 +1,9 @@ #ifndef N_APP_H #define N_APP_H -#include #include "widget/dialogue.h" +#include "../common.h" +#include typedef enum { MODAL_COLOR_PAIR = 3, @@ -23,8 +24,8 @@ typedef struct { dialogue_e type; dialogue_t dialogue; } modal; - int cur_y, cur_x; params_t *params; + coordinates_t coordinates; } app_t; app_t *init_app(); diff --git a/src/ui/modals/ask_server_addr.c b/src/ui/modals/ask_server_addr.c index 48c0e21..a85445d 100644 --- a/src/ui/modals/ask_server_addr.c +++ b/src/ui/modals/ask_server_addr.c @@ -1,7 +1,11 @@ +#include "../../connection.h" #include "../app.h" #include "../widget/dialogue.h" #include "../widget/group.h" +#include "../widget/input.h" #include +#include +#include #include typedef struct { @@ -9,20 +13,27 @@ typedef struct { enum w_type type; } group_bt_t; -void asa_modal_group_callback(callback_args_t *args) { - group_resp_t *response = (group_resp_t *)args->resp_data; - callback_args_t ch_args; - memcpy(&ch_args, args, sizeof(callback_args_t)); - ch_args.app = NULL; - group_default_callback(&ch_args); - if (response->value > -1) { - switch (response->value) { +void asa_modal_dialogue_callback(callback_args_t *args) { + int32_t response; + callback_args_t d_args; + app_t *app = args->app; + dialogue_t *d = (dialogue_t *)args->widget; + memcpy(&d_args, args, sizeof(callback_args_t)); + d_args.app = NULL; + d_args.resp_data = &response; + input_t *in_ip = d->g_content->elements[0].element; + input_t *in_port = d->g_content->elements[1].element; + dialogue_default_callback(&d_args); + if (response > -1) { + switch (response) { case 0: - // exit(10); + get_ip_port(app->params, in_ip->value, in_port->value); + destroy_dialogue(d); + app->modal.type = none; + break; case 1: - // exit(11); - case 2: - // exit(12); + destroy_app(app); + exit(0); } } } @@ -35,19 +46,18 @@ dialogue_t *init_asa_modal(app_t *app) { {.type = w_input, .label = "Port", .length = 5}, {.type = w_end}}; - group_el_init_t actions[] = {{.type = w_button, .label = "Connect"}, - {.type = w_button, .label = "Cancel"}, - {.type = w_end}}; + group_el_init_t actions[] = { + {.type = w_button, .label = "Connect", .is_default = 1}, + {.type = w_button, .label = "Cancel", .is_default = 0}, + {.type = w_end}}; init_dialogue(&(app->modal.dialogue), "Connect to server", - "There is information needed", app->cur_y, app->cur_x); + "There is information needed", &(app->coordinates)); dialogue_t *d = &(app->modal.dialogue); + d->w.callback = asa_modal_dialogue_callback; d->g_content = init_group(&(d->win), &(d->w), content, horizontal); - d->g_content->w.callback = asa_modal_group_callback; - d->g_action = init_group(&(d->win), &(d->w), actions, horizontal); - d->g_action->w.callback = asa_modal_group_callback; dialogue_init_active_id(d); diff --git a/src/ui/modals/login.c b/src/ui/modals/login.c index ca6ce10..25d6d0b 100644 --- a/src/ui/modals/login.c +++ b/src/ui/modals/login.c @@ -2,6 +2,7 @@ #include "../widget/dialogue.h" #include "../widget/group.h" #include +#include #include typedef struct { @@ -10,20 +11,21 @@ typedef struct { } group_bt_t; void login_modal_group_callback(callback_args_t *args) { - group_resp_t *response = (group_resp_t *)args->resp_data; - callback_args_t ch_args; - memcpy(&ch_args, args, sizeof(callback_args_t)); - ch_args.app = NULL; - group_default_callback(&ch_args); - if (response->value > -1) { - // TODO: finish actions - switch (response->value) { + int32_t response; + callback_args_t d_args; + app_t *app = args->app; + dialogue_t *d = (dialogue_t *)args->widget; + memcpy(&d_args, args, sizeof(callback_args_t)); + d_args.app = NULL; + d_args.resp_data = &response; + dialogue_default_callback(&d_args); + if (response > -1) { + switch (response) { case 0: - // exit(10); + break; case 1: - // exit(11); - case 2: - // exit(12); + // exit(0); + break; } } } @@ -39,11 +41,11 @@ dialogue_t *init_login_modal(app_t *app) { init_dialogue(&(app->modal.dialogue), "Login", "Select your login " "option", - app->cur_y, app->cur_x); + &(app->coordinates)); app->modal.dialogue.g_content = init_group(&(app->modal.dialogue.win), &(app->modal.dialogue.w), children, horizontal); - app->modal.dialogue.g_content->w.callback = login_modal_group_callback; + app->modal.dialogue.w.callback = login_modal_group_callback; return NULL; } \ No newline at end of file diff --git a/src/ui/widget.h b/src/ui/widget.h index c57111b..dad9346 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -19,6 +19,7 @@ typedef struct { void *widget; void *data; void *resp_data; + uint32_t active_id; } callback_args_t; enum rsize { diff --git a/src/ui/widget/button.c b/src/ui/widget/button.c index 31b6117..f389dbc 100644 --- a/src/ui/widget/button.c +++ b/src/ui/widget/button.c @@ -9,10 +9,12 @@ button_t *init_button(WINDOW **win, widget_t *w_parent, char *label) { button_t *btn = malloc(sizeof(button_t)); - init_widget(&(btn->w), w_parent, win, label); + init_widget(&(btn->w), w_parent, win, label); btn->is_disabled = 0; btn->w.x = strlen(btn->w.title) + 6; // + "[ ]" - btn->w.y = 1; // TODO: detect new line + btn->w.y = 1; // TODO: detect new line + btn->w.cur.y = 0; + btn->w.cur.x = 0; return btn; } @@ -31,6 +33,8 @@ int32_t draw_button(button_t *btn, uint32_t active_id) { } mvwprintw(win, margin_y, margin_x, "%s", title); + btn->w.cur.y = margin_y; + btn->w.cur.x = margin_x; wattroff(win, A_BOLD | A_REVERSE); return strlen(title); diff --git a/src/ui/widget/dialogue.c b/src/ui/widget/dialogue.c index a894645..5dc7ee9 100644 --- a/src/ui/widget/dialogue.c +++ b/src/ui/widget/dialogue.c @@ -7,54 +7,71 @@ #include "dialogue.h" #include "group.h" +#define INCR_ACTIVE_ID(d, current, next) \ + if (d->active.id != d->current->last_id) { \ + d->active.id = d->active.id + 1; \ + } else if (d->next != NULL) { \ + d->active.id = d->next->first_id; \ + d->active.type = next; \ + } else { \ + d->active.id = d->current->first_id; \ + } + void dialogue_default_callback(callback_args_t *args) { dialogue_t *d = (void *)args->widget; char key = *((char *)args->data); app_t *app = (app_t *)args->app; callback_args_t new_args; - group_resp_t response; + int32_t *resp_value = (int32_t *)args->resp_data; + group_el_t *default_element = NULL; memcpy(&new_args, args, sizeof(callback_args_t)); - new_args.widget = d->g_content; - new_args.resp_data = &response; + new_args.active_id = d->active.id; + switch (key) { case '\t': - // TODO: active task if (d->active.type == g_content) { - if (d->active.id != d->g_content->last_id) { - d->active.id = d->active.id + 1; - } else { - d->active.id = d->g_content->first_id; - } + INCR_ACTIVE_ID(d, g_content, g_action); + } else if (d->active.type == g_action) { + INCR_ACTIVE_ID(d, g_action, g_content); } + *resp_value = -1; + draw_dialogue(d); + break; + case '\n': if (d->active.type == g_action) { - if (d->active.id != d->g_action->last_id) { - d->active.id = d->active.id + 1; - } else { - d->active.id = d->g_action->first_id; + new_args.widget = new_args.widget = d->g_action; + group_default_callback(&new_args); + } else { + for (int i = 0; i < d->g_action->count; i++) { + if (d->g_action->elements[i].is_default) { + *resp_value = i; + return; + } } } draw_dialogue(d); break; default: - d->g_content->w.callback(&new_args); - if (response.value > -1) { - d->is_initiated = 0; - destroy_dialogue(d); - app->modal.type = none; + if (d->active.type == g_content) { + new_args.widget = new_args.widget = d->g_content; + group_default_callback(&new_args); } else { + new_args.widget = new_args.widget = d->g_action; + group_default_callback(&new_args); + } + if (*resp_value == -1) { draw_dialogue(d); } } } void init_dialogue(dialogue_t *dialogue, const char title[], const char text[], - uint32_t cur_y, uint32_t cur_x) { + coordinates_t *p_coordinates) { dialogue->win = 0; dialogue->g_content = NULL; dialogue->w.x = 0; dialogue->w.y = 0; - dialogue->cur_y = cur_y; - dialogue->cur_x = cur_x; + dialogue->p_coordinates = p_coordinates; dialogue->w.callback = dialogue_default_callback; dialogue->is_initiated = 1; strcpy(dialogue->w.title, title); @@ -123,12 +140,10 @@ int32_t draw_dialogue(dialogue_t *d) { /* space for action block */ - y += 2; - d->w.x = x; d->w.y = y; - d->w.m_y = (d->cur_y - y) / 2; - d->w.m_x = (d->cur_x - x) / 2; + d->w.m_y = (d->p_coordinates->max_y - y) / 2; + d->w.m_x = (d->p_coordinates->max_x - x) / 2; /* render window */ if (d->win == NULL) { @@ -156,10 +171,10 @@ int32_t draw_dialogue(dialogue_t *d) { print_multiline_text(d->win, d->text, d->w.x, 2, 1, PMT_ALIGN_CENTER); wattroff(d->win, A_REVERSE); if (d->g_content != NULL) { - draw_group(d->win, d->g_content, d->active.id); + draw_group(d->win, d->g_content, d->active.id, &(d->w)); } if (d->g_action != NULL) { - draw_group(d->win, d->g_action, d->active.id); + draw_group(d->win, d->g_action, d->active.id, &(d->w)); } return 0; }; @@ -168,6 +183,9 @@ void destroy_dialogue(dialogue_t *d) { if (d->g_content) { destroy_group(d->g_content); } + if (d->g_action) { + destroy_group(d->g_action); + } delwin(d->win); d->win = NULL; d->is_initiated = 0; diff --git a/src/ui/widget/dialogue.h b/src/ui/widget/dialogue.h index cf4d4ca..f527318 100644 --- a/src/ui/widget/dialogue.h +++ b/src/ui/widget/dialogue.h @@ -2,6 +2,7 @@ #define DIALOGUE_H #include "../widget.h" +#include "../../common.h" #include "button.h" #include "group.h" #include @@ -17,16 +18,14 @@ typedef struct { struct { int32_t id; enum g_type type; - uint32_t y, x; } active; - uint32_t cur_y; - uint32_t cur_x; char text[DIALOGUE_TEXT]; uint32_t is_initiated : 1; + coordinates_t *p_coordinates; } dialogue_t; void init_dialogue(dialogue_t *d, const char title[], const char text[], - uint32_t cur_x, uint32_t cur_y); + coordinates_t *p_coordinates); int32_t draw_dialogue(dialogue_t *d); void destroy_dialogue(dialogue_t *d); void dialogue_default_callback(callback_args_t *args); diff --git a/src/ui/widget/group.c b/src/ui/widget/group.c index f09b660..e165cfa 100644 --- a/src/ui/widget/group.c +++ b/src/ui/widget/group.c @@ -9,36 +9,23 @@ #define MAKE_RESPONSE_M1(args, resp_data, response) \ if (args->resp_data != NULL) { \ - response->active_id = g->active_id; \ - response->value = -1; \ - } - -#define FIND_ELEMENT(args, element_ptr, element_idx) \ - if (args->resp_data != NULL) { \ - for (int i = 0; i < g->count; i++) { \ - if (g->elements[i].id == g->active_id) { \ - element_ptr = &(g->elements[i]); \ - element_idx = i; \ - break; \ - } \ - } \ + *response = -1; \ } void group_default_callback(callback_args_t *args) { group_t *g = (group_t *)args->widget; char key = *((char *)args->data); - group_resp_t *response = (group_resp_t *)args->resp_data; + int32_t *response = (int32_t *)args->resp_data; input_t *input; group_el_t *element_ptr; int32_t element_idx = -1; switch (key) { case '\n': /* Enter */ - FIND_ELEMENT(args, element_ptr, element_idx); - response->active_id = g->active_id; - response->value = element_idx; + FIND_ACTIVE_ELEMENT(g, args->active_id, element_ptr, element_idx); + *response = element_idx; break; case '\177': /* DEL */ - FIND_ELEMENT(args, element_ptr, element_idx); + FIND_ACTIVE_ELEMENT(g, args->active_id, element_ptr, element_idx); if (element_ptr->type == w_input) { input = (input_t *)element_ptr->element; if (input->value_len) { @@ -48,7 +35,7 @@ void group_default_callback(callback_args_t *args) { MAKE_RESPONSE_M1(args, resp_data, response); break; default: - FIND_ELEMENT(args, element_ptr, element_idx); + FIND_ACTIVE_ELEMENT(g, args->active_id, element_ptr, element_idx); if (element_ptr->type == w_input) { input = (input_t *)element_ptr->element; if (input->max_len > input->value_len) { @@ -76,12 +63,13 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children, } group->elements = calloc(group->count, sizeof(group_el_t)); group_el_t *elements = group->elements; - for (int i = 0; i < group->count; i++) { + for (int32_t i = 0; i < group->count; i++) { elements[i].type = children[i].type; + elements[i].is_default = children[i].is_default; } /* init child elements */ - for (int i = 0; i < group->count; i++) { + for (int32_t i = 0; i < group->count; i++) { widget_t *w; switch (elements[i].type) { case w_button: @@ -101,7 +89,7 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children, // set dimensions elements[i].id = w->id; if (direction == horizontal) { - w->m_x = group->w.x; + w->m_x = group->w.x + 1; w->m_y = group->w.m_y; group->w.x += w->x + 1; if (group->w.y < w->y) @@ -109,7 +97,6 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children, } if (i == 0) { group->first_id = w->id; - group->active_id = w->id; } else { group->last_id = w->id; } @@ -118,8 +105,11 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children, return group; } -void draw_group(WINDOW *win, group_t *group, int32_t active_id) { +void draw_group(WINDOW *win, group_t *group, int32_t active_id, + widget_t *dialog_w) { group_el_t *children = group->elements; + group_el_t *active_element = NULL; + uint32_t active_idx; for (int i = 0; i < group->count; i++) { group_el_t *el = &children[i]; switch (el->type) { @@ -135,22 +125,23 @@ void draw_group(WINDOW *win, group_t *group, int32_t active_id) { break; } } - for (int i = 0; i < group->count; i++) { - if (group->elements[i].id == group->active_id && - group->elements[i].type == w_input) { - input_t *input = group->elements[i].element; - uint32_t margin_y = input->w.m_y + input->w.w_parent->m_y; - uint32_t margin_x = input->w.m_x + input->w.w_parent->m_x + 1; - if (input->max_len == input->value_len) { - wmove(win, margin_y + 1, margin_x + input->value_len); - } else { - wmove(win, margin_y + 1, - margin_x + input->value_len + - 1); // x: +1: margin left from the border - } - curs_set(1); + /* move cursor */ + FIND_ACTIVE_ELEMENT(group, active_id, active_element, active_idx); + + if (active_element != NULL && active_element->id == active_id && + active_element->type == w_input) { + input_t *input = active_element->element; + dialog_w->cur.y = input->w.cur.y; + if (input->max_len == input->value_len) { + dialog_w->cur.x = input->w.cur.x + input->value_len - 1; + } else { + dialog_w->cur.x = input->w.cur.x + input->value_len; } } + if (dialog_w->cur.y || dialog_w->cur.x) { + wmove(win, dialog_w->cur.y, dialog_w->cur.x); + curs_set(1); + } } void destroy_group(group_t *group) { diff --git a/src/ui/widget/group.h b/src/ui/widget/group.h index 4f89452..73681be 100644 --- a/src/ui/widget/group.h +++ b/src/ui/widget/group.h @@ -13,10 +13,12 @@ typedef struct { uint32_t id; void *element; enum w_type type; + uint32_t is_default : 1; } group_el_t; typedef struct { enum w_type type; + uint32_t is_default : 1; char label[DIALOGUE_TITLE]; uint32_t length; } group_el_init_t; @@ -24,20 +26,23 @@ typedef struct { typedef struct { widget_t w; group_el_t *elements; - uint32_t active_id; // TODO: needs to be removed enum g_direction direction; uint32_t count; uint32_t first_id, last_id; } group_t; -typedef struct { - int32_t value; - uint32_t active_id; -} group_resp_t; +#define FIND_ACTIVE_ELEMENT(g, active_id, element_ptr, element_idx) \ + for (int i = 0; i < g->count; i++) { \ + if (g->elements[i].id == active_id) { \ + element_ptr = &(g->elements[i]); \ + element_idx = i; \ + break; \ + } \ + } group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children, enum g_direction dir); -void draw_group(WINDOW *win, group_t *group, int32_t active_id); +void draw_group(WINDOW *win, group_t *group, int32_t active_id, widget_t *dialog_w); void destroy_group(group_t *group); void group_default_callback(callback_args_t *args); diff --git a/src/ui/widget/input.c b/src/ui/widget/input.c index 374cd65..176ed8c 100644 --- a/src/ui/widget/input.c +++ b/src/ui/widget/input.c @@ -13,7 +13,7 @@ input_t *init_input(WINDOW **win, widget_t *w_parent, char *label, init_widget(&(input->w), w_parent, win, label); input->is_disabled = 0; input->w.y = 3; // with borders - input->w.x = length + 2; // with borders + input->w.x = length + 2; // with borders uint32_t t_len = strlen(input->w.title) + 4; // with borders and space if (input->w.x < t_len) input->w.x = t_len; @@ -27,7 +27,7 @@ input_t *init_input(WINDOW **win, widget_t *w_parent, char *label, int32_t draw_input(input_t *input, uint32_t active_id) { WINDOW *win = *(input->w.parent_win); uint32_t margin_y = input->w.m_y + input->w.w_parent->m_y; - uint32_t margin_x = input->w.m_x + input->w.w_parent->m_x + 1; // +1: margin left from the border + uint32_t margin_x = input->w.m_x + input->w.w_parent->m_x; wattrset(win, COLOR_PAIR(MODAL_COLOR_PAIR)); @@ -41,9 +41,9 @@ int32_t draw_input(input_t *input, uint32_t active_id) { mvwvline(win, margin_y + 1, margin_x, 0, 1); mvwvline(win, margin_y + 2, margin_x, ACS_LLCORNER, 1); // right - mvwvline(win, margin_y, margin_x + input->w.x-1, ACS_URCORNER, 1); - mvwvline(win, margin_y + 1, margin_x + input->w.x-1, 0, 1); - mvwvline(win, margin_y + 2, margin_x + input->w.x-1, ACS_LRCORNER, 1); + mvwvline(win, margin_y, margin_x + input->w.x - 1, ACS_URCORNER, 1); + mvwvline(win, margin_y + 1, margin_x + input->w.x - 1, 0, 1); + mvwvline(win, margin_y + 2, margin_x + input->w.x - 1, ACS_LRCORNER, 1); // TODO: correct sizes (x) @@ -57,7 +57,8 @@ int32_t draw_input(input_t *input, uint32_t active_id) { uint32_t x_c = 0; mvwprintw(win, margin_y + 1, margin_x, "%s", input->value); - + input->w.cur.y = margin_y + 1; + input->w.cur.x = margin_x; for (int i = 0; i < input->w.x - input->value_len - 2; i++) { mvwprintw(win, margin_y + 1, margin_x + i + input->value_len, " "); }