ui: finishes nested groups; +email field in registration modal

This commit is contained in:
2026-02-26 15:07:04 +02:00
parent b10766f6e3
commit 8f6ec355e7
14 changed files with 71 additions and 64 deletions
+5 -3
View File
@@ -1,10 +1,12 @@
# TODO: # TODO:
## Current: ## Current:
- [ ] UI: vertical layout (needs for email in registration) - [x] UI: vertical layout (needs for email in registration)
- [ ] Nested groups - [x] Nested groups
- [x] Create dynamic map of elements IDs and their pointers - [x] Create dynamic map of elements IDs and their pointers
- [ ] Adapt modals to new value-forwarding method - [x] Adapt modals to new value-forwarding method
- [ ] Move text to the end if text in the input is larger, than field
- [ ] More intuitive navigation between nested groups (by pressing left and right buttons)
## Features: ## Features:
- [x] Search files - [x] Search files
+1 -1
View File
@@ -25,7 +25,7 @@ void notification(const char *title, const char *message,
return; return;
group_el_init_t actions[] = { group_el_init_t actions[] = {
{.type = w_button, .label = "OK", .is_default = 1}, {.type = w_end}}; {.type = w_button, .label = "OK", .is_default = true}, {.type = w_end}};
dialogue_t *d = malloc(sizeof(dialogue_t)); dialogue_t *d = malloc(sizeof(dialogue_t));
+3 -10
View File
@@ -1,17 +1,10 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <ncurses.h> #include <ncurses.h>
// #include "../app.h"
// #include "../widget/dialogue.h"
// #include "../widget/group.h"
// #include "../widget/input.h"
// #include "../widget/button.h"
#include <widget.h> #include <widget.h>
#include <widget_core.h>
#include "../connection.h" #include "../connection.h"
#include "group.h" #include "group.h"
#include "widget_core.h"
typedef struct { typedef struct {
button_t *element; button_t *element;
@@ -51,8 +44,8 @@ dialogue_t *init_asa_modal(app_t *app) {
{.type = w_end}}; {.type = w_end}};
group_el_init_t actions[] = { group_el_init_t actions[] = {
{.type = w_button, .label = "Connect", .is_default = 1}, {.type = w_button, .label = "Connect", .is_default = true, .val.num = 1},
{.type = w_button, .label = "Cancel", .is_default = 0}, {.type = w_button, .label = "Cancel", .is_default = false, .val.num = 2},
{.type = w_end}}; {.type = w_end}};
init_dialogue(&(app->modal), "Connect to server", init_dialogue(&(app->modal), "Connect to server",
+1 -1
View File
@@ -17,7 +17,7 @@ dialogue_t *init_dwn_pr_modal(app_t *app, bool is_upload) {
sprintf(text, "%s file: %s", is_upload ? "Uploading" : "Downloading", sprintf(text, "%s file: %s", is_upload ? "Uploading" : "Downloading",
is_upload ? app->query_args->file->name : app->file_args->f_selected.name); is_upload ? app->query_args->file->name : app->file_args->f_selected.name);
group_el_init_t actions[] = { group_el_init_t actions[] = {
{.type = w_button, .label = "Cancel", .is_default = 1}, {.type = w_end}}; {.type = w_button, .label = "Cancel", .is_default = true, .val.num = 1}, {.type = w_end}};
app->modal.w.parent_win = &app->win; app->modal.w.parent_win = &app->win;
init_dialogue(&(app->modal), is_upload ? "Upload" : "Download", text, init_dialogue(&(app->modal), is_upload ? "Upload" : "Download", text,
+4 -4
View File
@@ -24,7 +24,7 @@ void init_login_credentials_modal_cb(callback_args_t *args) {
dialogue_default_callback(&d_args); dialogue_default_callback(&d_args);
if (d_args.resp_data.code == cbrp_val) { if (d_args.resp_data.code == cbrp_val) {
switch (d_args.resp_data.val.val.num) { switch (d_args.resp_data.val.val.num) {
case 0: case 1:
app->params->uname = malloc(in_name->value_len + 1); app->params->uname = malloc(in_name->value_len + 1);
app->params->pass = malloc(in_pass->value_len + 1); app->params->pass = malloc(in_pass->value_len + 1);
strncpy(app->params->uname, in_name->value, in_name->value_len); strncpy(app->params->uname, in_name->value, in_name->value_len);
@@ -36,7 +36,7 @@ void init_login_credentials_modal_cb(callback_args_t *args) {
d->needs_destroy = true; d->needs_destroy = true;
print_bars(app); print_bars(app);
break; break;
case 1: case 2:
app->query_args->state = S_ASK_LOGIN_TYPE; app->query_args->state = S_ASK_LOGIN_TYPE;
app->modal.needs_destroy = true; app->modal.needs_destroy = true;
} }
@@ -55,8 +55,8 @@ dialogue_t *init_login_credentials_modal(app_t *app) {
{.type = w_end}}; {.type = w_end}};
group_el_init_t actions[] = { group_el_init_t actions[] = {
{.type = w_button, .label = "Login", .is_default = true}, {.type = w_button, .label = "Login", .is_default = true, .val.num = 1},
{.type = w_button, .label = "Cancel", .is_default = false}, {.type = w_button, .label = "Cancel", .is_default = false, .val.num = 2},
{.type = w_end}}; {.type = w_end}};
init_dialogue(&(app->modal), "Login", "Your login credentials", init_dialogue(&(app->modal), "Login", "Your login credentials",
+6 -6
View File
@@ -22,7 +22,7 @@ void login_modal_option_cb(callback_args_t *args) {
dialogue_default_callback(&d_args); dialogue_default_callback(&d_args);
if (d_args.resp_data.code == cbrp_val) { if (d_args.resp_data.code == cbrp_val) {
switch (d_args.resp_data.val.val.num) { switch (d_args.resp_data.val.val.num) {
case 0: case 1:
d->needs_destroy = true; d->needs_destroy = true;
app->params->uname = malloc(sizeof "anonymous"); app->params->uname = malloc(sizeof "anonymous");
strcpy(app->params->uname, "anonymous"); strcpy(app->params->uname, "anonymous");
@@ -30,11 +30,11 @@ void login_modal_option_cb(callback_args_t *args) {
app->query_args->state = S_WAIT_SERVER; app->query_args->state = S_WAIT_SERVER;
print_bars(app); print_bars(app);
break; break;
case 1: case 2:
d->needs_destroy = true; d->needs_destroy = true;
app->query_args->state = S_ASK_LOGIN_USER; app->query_args->state = S_ASK_LOGIN_USER;
break; break;
case 2: case 3:
d->needs_destroy = true; d->needs_destroy = true;
app->query_args->state = S_ASK_REGISTER; app->query_args->state = S_ASK_REGISTER;
break; break;
@@ -45,9 +45,9 @@ void login_modal_option_cb(callback_args_t *args) {
dialogue_t *init_login_option_modal(app_t *app) { dialogue_t *init_login_option_modal(app_t *app) {
if (app == NULL) if (app == NULL)
return NULL; return NULL;
group_el_init_t children[] = {{.type = w_button, .label = "Anonymous"}, group_el_init_t children[] = {{.type = w_button, .label = "Anonymous", .val.num = 1},
{.type = w_button, .label = "User"}, {.type = w_button, .label = "User", .val.num = 2},
{.type = w_button, .label = "Register"}, {.type = w_button, .label = "Register", .val.num = 3},
{.type = w_end}}; {.type = w_end}};
init_dialogue(&(app->modal), "Login", init_dialogue(&(app->modal), "Login",
+1 -1
View File
@@ -29,7 +29,7 @@ dialogue_t *init_notification_modal(app_t *app) {
return NULL; return NULL;
group_el_init_t actions[] = { group_el_init_t actions[] = {
{.type = w_button, .label = "OK", .is_default = 1, .val.num = 1}, {.type = w_button, .label = "OK", .is_default = true, .val.num = 1},
{.type = w_end}}; {.type = w_end}};
init_dialogue(&(app->modal), "Notification", app->query_args->notification, init_dialogue(&(app->modal), "Notification", app->query_args->notification,
+12 -9
View File
@@ -25,14 +25,17 @@ void init_register_modal_cb(callback_args_t *args) {
memcpy(&d_args, args, sizeof(callback_args_t)); memcpy(&d_args, args, sizeof(callback_args_t));
d_args.app = NULL; d_args.app = NULL;
d_args.element = app->active_widget; d_args.element = app->active_widget;
input_t *in_name = d->g_content->elements[0].element; group_t *g_email_user = d->g_content->elements[0].element;
input_t *in_pass = d->g_content->elements[1].element; group_t *g_passwords = d->g_content->elements[1].element;
input_t *in_pass_r = d->g_content->elements[2].element; input_t *in_name = g_email_user->elements[0].element;
input_t *in_email = g_email_user->elements[1].element;
input_t *in_pass = g_passwords->elements[0].element;
input_t *in_pass_r = g_passwords->elements[1].element;
dialogue_default_callback(&d_args); dialogue_default_callback(&d_args);
if (d_args.resp_data.code == cbrp_val && if (d_args.resp_data.code == cbrp_val &&
d_args.resp_data.val.type == val_num) { d_args.resp_data.val.type == val_num) {
switch (d_args.resp_data.val.val.num) { switch (d_args.resp_data.val.val.num) {
case 0: case 1:
if (strcmp(in_pass->value, in_pass_r->value)) { if (strcmp(in_pass->value, in_pass_r->value)) {
alert("Your passwords do not match"); alert("Your passwords do not match");
in_pass->value[0] = '\0'; in_pass->value[0] = '\0';
@@ -47,12 +50,12 @@ void init_register_modal_cb(callback_args_t *args) {
app->params->uname[in_name->value_len] = 0; app->params->uname[in_name->value_len] = 0;
strncpy(app->params->pass, in_pass->value, in_pass->value_len); strncpy(app->params->pass, in_pass->value, in_pass->value_len);
app->params->pass[in_pass->value_len] = 0; app->params->pass[in_pass->value_len] = 0;
sprintf(query, "register %s %s\n%n", app->params->uname, sprintf(query, "register %s %s %*s\n%n", app->params->uname,
app->params->pass, &qlen); app->params->pass, (int) in_email->value_len, in_email->value, &qlen);
write(app->params->sd, query, qlen); write(app->params->sd, query, qlen);
app->query_args->state = S_WAIT_REGISTER_CONFIRMATION; app->query_args->state = S_WAIT_REGISTER_CONFIRMATION;
break; break;
case 1: case 2:
app->query_args->state = S_ASK_LOGIN_TYPE; app->query_args->state = S_ASK_LOGIN_TYPE;
app->modal.needs_destroy = true; app->modal.needs_destroy = true;
} }
@@ -83,8 +86,8 @@ dialogue_t *init_register_modal(app_t *app) {
{.type = w_end}}; {.type = w_end}};
group_el_init_t actions[] = { group_el_init_t actions[] = {
{.type = w_button, .label = "Register", .is_default = true}, {.type = w_button, .label = "Register", .is_default = true, .val.num = 1},
{.type = w_button, .label = "Cancel", .is_default = false}, {.type = w_button, .label = "Cancel", .is_default = false, .val.num = 2},
{.type = w_end}}; {.type = w_end}};
init_dialogue(&(app->modal), "Credentials", "There is information needed", init_dialogue(&(app->modal), "Credentials", "There is information needed",
+1 -1
View File
@@ -38,7 +38,7 @@ void *init_server_message_modal(app_t *app) {
if (app == NULL) if (app == NULL)
return NULL; return NULL;
group_el_init_t children[] = { group_el_init_t children[] = {
{.type = w_button, .label = "OK", .is_default = 1, .val.num = 1}, {.type = w_end}}; {.type = w_button, .label = "OK", .is_default = true, .val.num = 1}, {.type = w_end}};
init_dialogue(&(app->modal), "Server response", init_dialogue(&(app->modal), "Server response",
app->query_args->server_message.text, &(app->coordinates)); app->query_args->server_message.text, &(app->coordinates));
+1 -1
View File
@@ -42,7 +42,7 @@ dialogue_t *init_upload_dialogue_modal(app_t *app) {
{.type = w_end}}; {.type = w_end}};
group_el_init_t actions[] = { group_el_init_t actions[] = {
{.type = w_button, .label = "Cancel", .is_default = 0}, {.type = w_end}}; {.type = w_button, .label = "Cancel", .is_default = false, .val.num = 0}, {.type = w_end}};
app->modal.w.parent_win = &app->win; app->modal.w.parent_win = &app->win;
init_dialogue(&(app->modal), "Upload new file", "Enter essential data", init_dialogue(&(app->modal), "Upload new file", "Enter essential data",
+2 -2
View File
@@ -52,8 +52,8 @@ dialogue_t *init_upload_props_dialogue_modal(app_t *app) {
{.type = w_end}}; {.type = w_end}};
group_el_init_t actions[] = { group_el_init_t actions[] = {
{.type = w_button, .label = "Upload", .is_default = 1}, {.type = w_button, .label = "Upload", .is_default = true},
{.type = w_button, .label = "Cancel", .is_default = 0}, {.type = w_button, .label = "Cancel", .is_default = false},
{.type = w_end}, {.type = w_end},
}; };
-1
View File
@@ -10,7 +10,6 @@
typedef enum { typedef enum {
modal_color_pair = 3, modal_color_pair = 3,
modal_border_color_pair = 4,
} color; } color;
typedef enum { typedef enum {
+22 -17
View File
@@ -95,7 +95,8 @@ void dialogue_default_callback(callback_args_t *args) {
if (d->active_el->g_type == g_action) { if (d->active_el->g_type == g_action) {
new_args.element = d->g_action; new_args.element = d->g_action;
group_default_callback(&new_args); group_default_callback(&new_args);
mempcpy(&(args->resp_data), &(new_args.resp_data), sizeof(new_args.resp_data)); mempcpy(&(args->resp_data), &(new_args.resp_data),
sizeof(new_args.resp_data));
} else if (d->g_action != NULL) { } else if (d->g_action != NULL) {
for (int i = 0; i < d->g_action->count; i++) { for (int i = 0; i < d->g_action->count; i++) {
if (d->g_action->elements[i].is_default) { if (d->g_action->elements[i].is_default) {
@@ -105,7 +106,6 @@ void dialogue_default_callback(callback_args_t *args) {
} }
} }
} else { } else {
/* TODO: temp solution, improve */
args->resp_data.code = cbrp_val; args->resp_data.code = cbrp_val;
args->resp_data.val.val.num = d->active_el->idx; args->resp_data.val.val.num = d->active_el->idx;
return; return;
@@ -160,30 +160,35 @@ void init_dialogue(dialogue_t *dialogue, const char title[], const char text[],
dialogue->text[t_size - 1] = '\0'; dialogue->text[t_size - 1] = '\0';
} }
void dialogue_init_active_id(dialogue_t *dialogue) { int group_init_active_id(group_t *g, dialogue_t *d) {
enum w_type widget_type; enum w_type wt;
if (dialogue->g_content != NULL) { for (int i = 0; i < g->count; i++) {
for (int i = 0; i < dialogue->g_content->count; i++) { wt = g->elements[i].type;
widget_type = dialogue->g_content->elements[i].type; if (wt == w_button || wt == w_input ||
if (widget_type == w_button || widget_type == w_input || wt == w_fs_file_list) { /* Add here new types */
widget_type == w_fs_file_list) { /* Add here new types */ d->active_el = g->elements + i;
dialogue->active_el = dialogue->g_content->elements + i; return 1;
return; } else if (wt == w_group) {
group_t *child_g = g->elements[i].element;
return group_init_active_id(child_g, d);
} }
} }
return 0;
}
void dialogue_init_active_id(dialogue_t *dialogue) {
if (dialogue->g_content != NULL) {
if (group_init_active_id(dialogue->g_content, dialogue)) {
return;
}
} }
if (dialogue->g_action != NULL) { if (dialogue->g_action != NULL) {
for (int i = 0; i < dialogue->g_action->count; i++) { if (group_init_active_id(dialogue->g_action, dialogue)) {
widget_type = dialogue->g_action->elements[i].type;
if (widget_type == w_button || widget_type == w_input ||
widget_type == w_fs_file_list) {
dialogue->active_el = dialogue->g_action->elements + i;
return; return;
} }
} }
} }
}
#define DETECT_GROUP_SIZE(group, line_max_len, y, x) \ #define DETECT_GROUP_SIZE(group, line_max_len, y, x) \
if (group) { \ if (group) { \
+10 -5
View File
@@ -40,13 +40,15 @@ int32_t draw_input(input_t *input, uint32_t active_id) {
w_par = w_par->w_parent; w_par = w_par->w_parent;
} }
wattrset(win, COLOR_PAIR(modal_color_pair)); if (input->w.id == active_id) {
wattrset(win, COLOR_PAIR(3));
} else {
wattrset(win, COLOR_PAIR(0) | A_REVERSE | A_BOLD);
}
mvwhline(win, margin_y, margin_x, 0, input->w.x); mvwhline(win, margin_y, margin_x, 0, input->w.x);
mvwhline(win, margin_y + 2, margin_x, 0, input->w.x); mvwhline(win, margin_y + 2, margin_x, 0, input->w.x);
mvwprintw(win, margin_y, margin_x + 1, " %s ", input->w.title);
// left // left
mvwvline(win, margin_y, margin_x, ACS_ULCORNER, 1); mvwvline(win, margin_y, margin_x, ACS_ULCORNER, 1);
mvwvline(win, margin_y + 1, margin_x, 0, 1); mvwvline(win, margin_y + 1, margin_x, 0, 1);
@@ -56,6 +58,9 @@ int32_t draw_input(input_t *input, uint32_t active_id) {
mvwvline(win, margin_y + 1, margin_x + input->w.x - 1, 0, 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 + 2, margin_x + input->w.x - 1, ACS_LRCORNER, 1);
wattrset(win, COLOR_PAIR(0) | A_REVERSE);
mvwprintw(win, margin_y, margin_x + 1, " %s ", input->w.title);
margin_x++; margin_x++;
if (input->w.id == active_id) { if (input->w.id == active_id) {
@@ -66,10 +71,10 @@ int32_t draw_input(input_t *input, uint32_t active_id) {
if (input->is_hidden) { if (input->is_hidden) {
mvwprintw(win, margin_y + 1, margin_x, "%.*s%*s", (int)input->value_len, mvwprintw(win, margin_y + 1, margin_x, "%.*s%*s", (int)input->value_len,
stars, input->w.x - input->value_len - 2, ""); stars, (int)(input->w.x - input->value_len - 2), "");
} else { } else {
mvwprintw(win, margin_y + 1, margin_x, "%s%*s", input->value, mvwprintw(win, margin_y + 1, margin_x, "%s%*s", input->value,
input->w.x - input->value_len - 2, ""); (int)(input->w.x - input->value_len - 2), "");
} }
input->w.cur.y = margin_y + 1; input->w.cur.y = margin_y + 1;