ui: possibility to hide input value

This commit is contained in:
2026-01-01 13:45:01 +02:00
parent fded75e3a8
commit 6a9dad9557
6 changed files with 23 additions and 11 deletions
-2
View File
@@ -1,11 +1,9 @@
TODO: TODO:
- [x] More universal Makefile - [x] More universal Makefile
- [ ] Draw only when something changes in UI
- [ ] Check and fix registration and login - [ ] Check and fix registration and login
- [x] UI: destroy child elements everywhere - [x] UI: destroy child elements everywhere
- [x] use parent widgets pointers to count the margins correctly - [x] use parent widgets pointers to count the margins correctly
- [ ] Hotkeys for buttons - [ ] Hotkeys for buttons
- [ ] Simpler refresh on typing / entering in input
- [ ] Group elements as lists - [ ] Group elements as lists
- [x] Process arrows - [x] Process arrows
- [x] Optimize modals re-drawings - [x] Optimize modals re-drawings
+7 -4
View File
@@ -37,7 +37,7 @@ void init_login_credentials_modal_cb(callback_args_t *args) {
app->params->pass[in_pass->value_len] = 0; app->params->pass[in_pass->value_len] = 0;
write(app->params->sd, app->params->uname, in_name->value_len); write(app->params->sd, app->params->uname, in_name->value_len);
app->query_args->state = S_WAIT_SERVER; app->query_args->state = S_WAIT_SERVER;
destroy_dialogue(d,app); destroy_dialogue(d, app);
print_bars(app); print_bars(app);
break; break;
case 1: case 1:
@@ -52,12 +52,15 @@ dialogue_t *init_login_credentials_modal(app_t *app) {
return NULL; return NULL;
group_el_init_t content[] = { group_el_init_t content[] = {
{.type = w_input, .label = "Username", .length = 15}, {.type = w_input, .label = "Username", .length = 15},
{.type = w_input, .label = "Password", .length = 15}, {.type = w_input,
.label = "Password",
.length = 15,
.is_hidden_value = true},
{.type = w_end}}; {.type = w_end}};
group_el_init_t actions[] = { group_el_init_t actions[] = {
{.type = w_button, .label = "Login", .is_default = 1}, {.type = w_button, .label = "Login", .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}};
init_dialogue(&(app->modal), "Credentials", "There is information needed", init_dialogue(&(app->modal), "Credentials", "There is information needed",
+1 -1
View File
@@ -85,7 +85,7 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children,
break; break;
case w_input: case w_input:
elements[i].element = elements[i].element =
init_input(win, &(group->w), children[i].label, children[i].length); init_input(win, &(group->w), children[i].label, children[i].length, children[i].is_hidden_value);
w = &(((input_t *)elements[i].element)->w); w = &(((input_t *)elements[i].element)->w);
break; break;
case w_progress: case w_progress:
+1
View File
@@ -19,6 +19,7 @@ typedef struct {
typedef struct { typedef struct {
enum w_type type; enum w_type type;
uint32_t is_default : 1; uint32_t is_default : 1;
uint32_t is_hidden_value : 1;
char label[DIALOGUE_TITLE]; char label[DIALOGUE_TITLE];
uint32_t length; uint32_t length;
} group_el_init_t; } group_el_init_t;
+9 -1
View File
@@ -8,7 +8,7 @@
#include "input.h" #include "input.h"
input_t *init_input(WINDOW **win, widget_t *w_parent, char *label, input_t *init_input(WINDOW **win, widget_t *w_parent, char *label,
uint32_t length) { uint32_t length, uint32_t is_hidden_value) {
input_t *input = malloc(sizeof(input_t)); input_t *input = malloc(sizeof(input_t));
init_widget(&(input->w), w_parent, win, label); init_widget(&(input->w), w_parent, win, label);
input->is_disabled = 0; input->is_disabled = 0;
@@ -21,10 +21,12 @@ input_t *init_input(WINDOW **win, widget_t *w_parent, char *label,
input->value[0] = '\0'; input->value[0] = '\0';
input->value_len = 0; input->value_len = 0;
input->max_len = length; input->max_len = length;
input->is_hidden = is_hidden_value;
return input; return input;
} }
int32_t draw_input(input_t *input, uint32_t active_id) { int32_t draw_input(input_t *input, uint32_t active_id) {
const char stars[] = "*******************";
WINDOW *win = *(input->w.parent_win); WINDOW *win = *(input->w.parent_win);
uint32_t margin_y = input->w.m_y + input->w.w_parent->m_y; 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; uint32_t margin_x = input->w.m_x + input->w.w_parent->m_x;
@@ -54,8 +56,14 @@ int32_t draw_input(input_t *input, uint32_t active_id) {
} }
uint32_t x_c = 0; uint32_t x_c = 0;
if (input->is_hidden) {
mvwprintw(win, margin_y + 1, margin_x, "%.*s%*s", (int) input->value_len, stars,
input->w.x - input->value_len - 2, "");
} 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, ""); input->w.x - input->value_len - 2, "");
}
input->w.cur.y = margin_y + 1; input->w.cur.y = margin_y + 1;
input->w.cur.x = margin_x; input->w.cur.x = margin_x;
+3 -1
View File
@@ -11,9 +11,11 @@ typedef struct {
uint32_t value_len; uint32_t value_len;
uint32_t max_len; uint32_t max_len;
uint32_t is_disabled : 1; uint32_t is_disabled : 1;
uint32_t is_hidden : 1;
} input_t; } input_t;
input_t *init_input(WINDOW **win, widget_t *w_parent, char *label, uint32_t size); input_t *init_input(WINDOW **win, widget_t *w_parent, char *label,
uint32_t size, uint32_t is_hidden_value);
int32_t draw_input(input_t *input, uint32_t active_id); int32_t draw_input(input_t *input, uint32_t active_id);
void destroy_input(input_t *input); void destroy_input(input_t *input);
#endif #endif