ui: dialogue: +id_map
This commit is contained in:
@@ -44,6 +44,7 @@ add_subdirectory(widget_core)
|
|||||||
add_subdirectory(widget)
|
add_subdirectory(widget)
|
||||||
add_subdirectory(modals)
|
add_subdirectory(modals)
|
||||||
add_subdirectory(lib)
|
add_subdirectory(lib)
|
||||||
|
add_subdirectory(utils)
|
||||||
|
|
||||||
target_link_libraries(zbbs-client-tui
|
target_link_libraries(zbbs-client-tui
|
||||||
PRIVATE
|
PRIVATE
|
||||||
@@ -51,5 +52,6 @@ target_link_libraries(zbbs-client-tui
|
|||||||
widget
|
widget
|
||||||
modals
|
modals
|
||||||
bstring
|
bstring
|
||||||
|
utils
|
||||||
${CURSES_LIBRARIES}
|
${CURSES_LIBRARIES}
|
||||||
)
|
)
|
||||||
@@ -3,7 +3,13 @@ add_library(modals STATIC)
|
|||||||
file(GLOB M_HEADERS "*.h")
|
file(GLOB M_HEADERS "*.h")
|
||||||
file(GLOB M_SOURCES "*.c")
|
file(GLOB M_SOURCES "*.c")
|
||||||
|
|
||||||
target_link_libraries(modals PRIVATE widget widget_core bstring)
|
target_link_libraries(modals
|
||||||
|
PRIVATE
|
||||||
|
widget
|
||||||
|
widget_core
|
||||||
|
bstring
|
||||||
|
utils
|
||||||
|
)
|
||||||
|
|
||||||
target_sources(modals
|
target_sources(modals
|
||||||
PRIVATE
|
PRIVATE
|
||||||
@@ -17,3 +23,4 @@ target_sources(modals
|
|||||||
target_include_directories(modals PRIVATE "../widget")
|
target_include_directories(modals PRIVATE "../widget")
|
||||||
target_include_directories(modals PRIVATE "../widget_core")
|
target_include_directories(modals PRIVATE "../widget_core")
|
||||||
target_include_directories(modals PRIVATE "../lib/")
|
target_include_directories(modals PRIVATE "../lib/")
|
||||||
|
target_include_directories(widget PRIVATE "../utils/")
|
||||||
+1
-1
@@ -33,7 +33,7 @@ void notification(const char *title, const char *message,
|
|||||||
|
|
||||||
d->w.callback = alert_cb;
|
d->w.callback = alert_cb;
|
||||||
d->g_content = NULL;
|
d->g_content = NULL;
|
||||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
d->g_action = init_group(&(d->win), &(d->w), actions,&(d->id_map), horizontal);
|
||||||
|
|
||||||
dialogue_init_active_id(d);
|
dialogue_init_active_id(d);
|
||||||
d->color_scheme = color;
|
d->color_scheme = color;
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ dialogue_t *init_asa_modal(app_t *app) {
|
|||||||
dialogue_t *d = &(app->modal);
|
dialogue_t *d = &(app->modal);
|
||||||
|
|
||||||
d->w.callback = asa_modal_dialogue_callback;
|
d->w.callback = asa_modal_dialogue_callback;
|
||||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
d->g_content = init_group(&(d->win), &(d->w), content,&(d->id_map), horizontal);
|
||||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
d->g_action = init_group(&(d->win), &(d->w), actions,&(d->id_map), horizontal);
|
||||||
|
|
||||||
dialogue_init_active_id(d);
|
dialogue_init_active_id(d);
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ dialogue_t *init_dwn_pr_modal(app_t *app, bool is_upload) {
|
|||||||
dialogue_t *d = &(app->modal);
|
dialogue_t *d = &(app->modal);
|
||||||
|
|
||||||
d->w.callback = dwn_pr_modal_cb;
|
d->w.callback = dwn_pr_modal_cb;
|
||||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
d->g_content = init_group(&(d->win), &(d->w), content, &(d->id_map), horizontal);
|
||||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
d->g_action = init_group(&(d->win), &(d->w), actions, &(d->id_map), horizontal);
|
||||||
|
|
||||||
app->query_args->progress_bar = d->g_content->elements[0].element;
|
app->query_args->progress_bar = d->g_content->elements[0].element;
|
||||||
app->query_args->active_dialogue = d;
|
app->query_args->active_dialogue = d;
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ dialogue_t *init_login_credentials_modal(app_t *app) {
|
|||||||
dialogue_t *d = &(app->modal);
|
dialogue_t *d = &(app->modal);
|
||||||
|
|
||||||
d->w.callback = init_login_credentials_modal_cb;
|
d->w.callback = init_login_credentials_modal_cb;
|
||||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
d->g_content = init_group(&(d->win), &(d->w), content, &(d->id_map), horizontal);
|
||||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
d->g_action = init_group(&(d->win), &(d->w), actions, &(d->id_map), horizontal);
|
||||||
|
|
||||||
dialogue_init_active_id(d);
|
dialogue_init_active_id(d);
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ void login_modal_option_cb(callback_args_t *args) {
|
|||||||
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");
|
||||||
write(app->params->sd, app->params->uname, sizeof "anonymous"-1);
|
write(app->params->sd, app->params->uname, sizeof "anonymous" - 1);
|
||||||
app->query_args->state = S_WAIT_SERVER;
|
app->query_args->state = S_WAIT_SERVER;
|
||||||
print_bars(app);
|
print_bars(app);
|
||||||
break;
|
break;
|
||||||
@@ -55,9 +55,8 @@ dialogue_t *init_login_option_modal(app_t *app) {
|
|||||||
"Select your login "
|
"Select your login "
|
||||||
"option",
|
"option",
|
||||||
&(app->coordinates));
|
&(app->coordinates));
|
||||||
app->modal.g_action =
|
app->modal.g_action = init_group(&(app->modal.win), &(app->modal.w), children,
|
||||||
init_group(&(app->modal.win), &(app->modal.w), children,
|
&(app->modal.id_map), horizontal);
|
||||||
horizontal);
|
|
||||||
app->modal.w.callback = login_modal_option_cb;
|
app->modal.w.callback = login_modal_option_cb;
|
||||||
dialogue_init_active_id(&(app->modal));
|
dialogue_init_active_id(&(app->modal));
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ dialogue_t *init_notification_modal(app_t *app) {
|
|||||||
|
|
||||||
d->w.callback = init_notification_modal_cb;
|
d->w.callback = init_notification_modal_cb;
|
||||||
d->g_content = NULL;
|
d->g_content = NULL;
|
||||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
d->g_action = init_group(&(d->win), &(d->w), actions, &(d->id_map), horizontal);
|
||||||
|
|
||||||
dialogue_init_active_id(d);
|
dialogue_init_active_id(d);
|
||||||
|
|
||||||
|
|||||||
@@ -93,8 +93,10 @@ dialogue_t *init_register_modal(app_t *app) {
|
|||||||
dialogue_t *d = &(app->modal);
|
dialogue_t *d = &(app->modal);
|
||||||
|
|
||||||
d->w.callback = init_register_modal_cb;
|
d->w.callback = init_register_modal_cb;
|
||||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
d->g_content =
|
||||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
init_group(&(d->win), &(d->w), content, &(d->id_map), horizontal);
|
||||||
|
d->g_action =
|
||||||
|
init_group(&(d->win), &(d->w), actions, &(d->id_map), horizontal);
|
||||||
|
|
||||||
dialogue_init_active_id(d);
|
dialogue_init_active_id(d);
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ void *init_server_message_modal(app_t *app) {
|
|||||||
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));
|
||||||
app->modal.g_action =
|
app->modal.g_action =
|
||||||
init_group(&(app->modal.win), &(app->modal.w), children, horizontal);
|
init_group(&(app->modal.win), &(app->modal.w), children, &(app->modal.id_map), horizontal);
|
||||||
app->modal.w.callback = server_message_modal_cb;
|
app->modal.w.callback = server_message_modal_cb;
|
||||||
dialogue_init_active_id(&(app->modal));
|
dialogue_init_active_id(&(app->modal));
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ dialogue_t *init_upload_dialogue_modal(app_t *app) {
|
|||||||
dialogue_t *d = &(app->modal);
|
dialogue_t *d = &(app->modal);
|
||||||
|
|
||||||
d->w.callback = upload_dialogue_modal_cb;
|
d->w.callback = upload_dialogue_modal_cb;
|
||||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
d->g_content = init_group(&(d->win), &(d->w), content, &(d->id_map), horizontal);
|
||||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
d->g_action = init_group(&(d->win), &(d->w), actions, &(d->id_map), horizontal);
|
||||||
|
|
||||||
app->query_args->active_dialogue = d;
|
app->query_args->active_dialogue = d;
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ dialogue_t *init_upload_props_dialogue_modal(app_t *app) {
|
|||||||
dialogue_t *d = &(app->modal);
|
dialogue_t *d = &(app->modal);
|
||||||
|
|
||||||
d->w.callback = upload_props_dialogue_modal_cb;
|
d->w.callback = upload_props_dialogue_modal_cb;
|
||||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
d->g_content = init_group(&(d->win), &(d->w), content, &(d->id_map), horizontal);
|
||||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
d->g_action = init_group(&(d->win), &(d->w), actions, &(d->id_map), horizontal);
|
||||||
|
|
||||||
app->query_args->active_dialogue = d;
|
app->query_args->active_dialogue = d;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
add_library(utils STATIC)
|
||||||
|
|
||||||
|
file(GLOB M_HEADERS "*.h")
|
||||||
|
file(GLOB M_SOURCES "*.c")
|
||||||
|
|
||||||
|
list(REMOVE_ITEM M_HEADERS "utils.h")
|
||||||
|
|
||||||
|
target_sources(utils
|
||||||
|
PRIVATE
|
||||||
|
${M_SOURCES}
|
||||||
|
PUBLIC
|
||||||
|
FILE_SET HEADERS
|
||||||
|
FILES
|
||||||
|
${M_HEADERS}
|
||||||
|
)
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
#include "d_array.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void init_d_arr_ptr(d_array_ptr_t *arr, int64_t init_capacity) {
|
||||||
|
arr->capacity = init_capacity;
|
||||||
|
arr->length = 0;
|
||||||
|
arr->arr = malloc(sizeof(void *) * init_capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_d_arr_ptr(d_array_ptr_t *arr, void *ptr, int64_t idx) {
|
||||||
|
if (idx > arr->capacity - 1) {
|
||||||
|
arr->capacity = idx * 2;
|
||||||
|
arr->arr = realloc(arr->arr, arr->capacity);
|
||||||
|
}
|
||||||
|
arr->arr[idx] = ptr;
|
||||||
|
arr->length = idx+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_d_arr(d_array_ptr_t *arr) {
|
||||||
|
arr->capacity = 0;
|
||||||
|
arr->length = 0;
|
||||||
|
free(arr->arr);
|
||||||
|
arr->arr = NULL;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef D_ARRAY_H
|
||||||
|
#define D_ARRAY_H
|
||||||
|
/* Dynamic array of numbers */
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef struct d_array_ptr_t {
|
||||||
|
int64_t capacity;
|
||||||
|
int64_t length;
|
||||||
|
void **arr;
|
||||||
|
} d_array_ptr_t;
|
||||||
|
|
||||||
|
void init_d_arr_ptr(d_array_ptr_t *arr, int64_t init_capacity);
|
||||||
|
void add_d_arr_ptr(d_array_ptr_t *arr, void *ptr, int64_t idx);
|
||||||
|
void free_d_arr(d_array_ptr_t *arr);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#ifndef D_UTILS_H
|
||||||
|
#define D_UTILS_H
|
||||||
|
#include "d_array.h"
|
||||||
|
#endif
|
||||||
@@ -18,7 +18,9 @@ target_link_libraries(widget
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
bstring
|
bstring
|
||||||
widget_core
|
widget_core
|
||||||
|
utils
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(widget PRIVATE "../widget_core")
|
target_include_directories(widget PRIVATE "../widget_core")
|
||||||
target_include_directories(widget PRIVATE "../lib/")
|
target_include_directories(widget PRIVATE "../lib/")
|
||||||
|
target_include_directories(widget PRIVATE "../utils/")
|
||||||
@@ -178,6 +178,7 @@ void init_dialogue(dialogue_t *dialogue, const char title[], const char text[],
|
|||||||
strcpy(dialogue->w.title, title);
|
strcpy(dialogue->w.title, title);
|
||||||
t_size = strlen(text);
|
t_size = strlen(text);
|
||||||
strcpy(dialogue->text, text);
|
strcpy(dialogue->text, text);
|
||||||
|
init_d_arr_ptr(&(dialogue->id_map), MAX_IDS);
|
||||||
/* trim the last new line symbol */
|
/* trim the last new line symbol */
|
||||||
if (t_size && dialogue->text[t_size - 1] == '\n')
|
if (t_size && dialogue->text[t_size - 1] == '\n')
|
||||||
dialogue->text[t_size - 1] = '\0';
|
dialogue->text[t_size - 1] = '\0';
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <widget_core.h>
|
#include <widget_core.h>
|
||||||
|
#include <utils.h>
|
||||||
|
#define MAX_IDS 64
|
||||||
enum g_type { g_content, g_action };
|
enum g_type { g_content, g_action };
|
||||||
enum d_color_scheme { dc_normal, dc_alert };
|
enum d_color_scheme { dc_normal, dc_alert };
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ typedef struct {
|
|||||||
bool needs_destroy;
|
bool needs_destroy;
|
||||||
coordinates_t *p_coordinates;
|
coordinates_t *p_coordinates;
|
||||||
enum d_color_scheme color_scheme;
|
enum d_color_scheme color_scheme;
|
||||||
|
d_array_ptr_t id_map;
|
||||||
} dialogue_t;
|
} dialogue_t;
|
||||||
|
|
||||||
void init_dialogue(dialogue_t *d, const char title[], const char text[],
|
void init_dialogue(dialogue_t *d, const char title[], const char text[],
|
||||||
|
|||||||
+5
-2
@@ -1,5 +1,6 @@
|
|||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
|
#include "d_array.h"
|
||||||
#include "fs_file_list.h"
|
#include "fs_file_list.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "progress_bar.h"
|
#include "progress_bar.h"
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
/* make response -1 */
|
/* make response -1 */
|
||||||
#define MAKE_RESPONSE_M1(args, resp_data, response) \
|
#define MAKE_RESPONSE_M1(args, resp_data, response) \
|
||||||
@@ -83,7 +85,7 @@ union current_element {
|
|||||||
};
|
};
|
||||||
|
|
||||||
group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children,
|
group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children,
|
||||||
enum g_direction direction) {
|
d_array_ptr_t *id_map, enum g_direction direction) {
|
||||||
group_t *group = malloc(sizeof(group_t));
|
group_t *group = malloc(sizeof(group_t));
|
||||||
union current_element current;
|
union current_element current;
|
||||||
group->parent_group = NULL;
|
group->parent_group = NULL;
|
||||||
@@ -118,7 +120,7 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children,
|
|||||||
break;
|
break;
|
||||||
case w_group:
|
case w_group:
|
||||||
elements[i].element = init_group(win, &(group->w), children[i].children,
|
elements[i].element = init_group(win, &(group->w), children[i].children,
|
||||||
children[i].direction);
|
id_map, children[i].direction);
|
||||||
w = &(((group_t *)elements[i].element)->w);
|
w = &(((group_t *)elements[i].element)->w);
|
||||||
current.group = (group_t *)elements[i].element;
|
current.group = (group_t *)elements[i].element;
|
||||||
current.group->parent_group = group;
|
current.group->parent_group = group;
|
||||||
@@ -155,6 +157,7 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children,
|
|||||||
}
|
}
|
||||||
/* set dimensions */
|
/* set dimensions */
|
||||||
elements[i].id = w->id;
|
elements[i].id = w->id;
|
||||||
|
add_d_arr_ptr(id_map, &(elements[i]), w->id);
|
||||||
if (direction == horizontal) {
|
if (direction == horizontal) {
|
||||||
w->m_x = group->w.m_x + 1 + group->w.x;
|
w->m_x = group->w.m_x + 1 + group->w.x;
|
||||||
w->m_y = group->w.m_y;
|
w->m_y = group->w.m_y;
|
||||||
|
|||||||
+3
-2
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <widget_core.h>
|
#include <widget_core.h>
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
enum g_direction {
|
enum g_direction {
|
||||||
horizontal,
|
horizontal,
|
||||||
@@ -26,7 +27,7 @@ typedef struct group_el_init_t {
|
|||||||
struct group_el_init_t *children;
|
struct group_el_init_t *children;
|
||||||
} group_el_init_t;
|
} group_el_init_t;
|
||||||
|
|
||||||
typedef struct group_t{
|
typedef struct group_t {
|
||||||
widget_t w;
|
widget_t w;
|
||||||
group_el_t *elements;
|
group_el_t *elements;
|
||||||
enum g_direction direction;
|
enum g_direction direction;
|
||||||
@@ -40,7 +41,7 @@ typedef struct group_t{
|
|||||||
element_ptr = &(g->elements[element_idx]);
|
element_ptr = &(g->elements[element_idx]);
|
||||||
|
|
||||||
group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children,
|
group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children,
|
||||||
enum g_direction dir);
|
d_array_ptr_t *id_map, 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);
|
||||||
void destroy_group(group_t *group);
|
void destroy_group(group_t *group);
|
||||||
void group_default_callback(callback_args_t *args);
|
void group_default_callback(callback_args_t *args);
|
||||||
|
|||||||
@@ -8,5 +8,4 @@
|
|||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "progress_bar.h"
|
#include "progress_bar.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user