ring: use xzmalloc_aligned
[netsniff-ng.git] / ui.h
blobfbc0eba510c034aaaf27230de7879320a076b2bb
1 #ifndef UI_H
2 #define UI_H
4 #define _LGPL_SOURCE
5 #include <stdbool.h>
6 #include <inttypes.h>
7 #include <urcu/list.h>
9 enum ui_event_id {
10 UI_EVT_SCROLL_LEFT,
11 UI_EVT_SCROLL_RIGHT,
12 UI_EVT_SCROLL_UP,
13 UI_EVT_SCROLL_DOWN,
14 UI_EVT_SELECT_NEXT,
17 enum ui_align {
18 UI_ALIGN_LEFT,
19 UI_ALIGN_RIGHT,
22 struct ui_text {
23 chtype *str;
24 size_t slen;
25 size_t len;
28 struct ui_col {
29 struct cds_list_head entry;
30 uint32_t id;
31 const char *name;
32 uint32_t len;
33 int pos;
34 int color;
35 enum ui_align align;
38 struct ui_table {
39 int y;
40 int x;
41 int rows_y;
42 struct cds_list_head cols;
43 struct ui_text *row;
44 int hdr_color;
45 int col_pad;
46 int width;
47 int height;
48 int scroll_x;
49 int scroll_y;
50 const char *delim;
51 int data_count;
53 void * (* data_iter)(void *data);
54 void (* data_bind)(struct ui_table *tbl, const void *data);
57 struct ui_tab;
59 enum ui_tab_event_t {
60 UI_TAB_EVT_OPEN,
61 UI_TAB_EVT_CLOSE,
64 typedef void (* ui_tab_event_cb) (struct ui_tab *tab, enum ui_tab_event_t evt,
65 uint32_t id);
67 struct ui_tab {
68 struct ui_col *active;
69 struct ui_table tbl;
70 int color;
72 ui_tab_event_cb on_tab_event;
75 extern void ui_table_init(struct ui_table *tbl);
76 extern void ui_table_uninit(struct ui_table *tbl);
77 extern void ui_table_clear(struct ui_table *tbl);
78 extern void ui_table_pos_set(struct ui_table *tbl, int y, int x);
79 extern void ui_table_height_set(struct ui_table *tbl, int height);
81 extern void ui_table_col_add(struct ui_table *tbl, uint32_t id, const char *name,
82 uint32_t len);
83 extern void ui_table_col_color_set(struct ui_table *tbl, int col_id, int color);
84 extern void ui_table_col_align_set(struct ui_table *tbl, int col_id, enum ui_align align);
85 extern void ui_table_col_delim_set(struct ui_table *tbl, const char *delim);
87 extern void ui_table_row_add(struct ui_table *tbl);
88 extern void ui_table_row_show(struct ui_table *tbl);
89 extern void ui_table_row_col_set(struct ui_table *tbl, uint32_t col_id,
90 const char *str);
92 extern void ui_table_header_color_set(struct ui_table *tbl, int color);
93 extern void ui_table_header_print(struct ui_table *tbl);
95 extern void ui_table_event_send(struct ui_table *tbl, enum ui_event_id id);
96 extern void ui_table_data_iter_set(struct ui_table *tbl, void * (* iter)(void *data));
97 extern void ui_table_data_bind_set(struct ui_table *tbl,
98 void (* bind)(struct ui_table *tbl, const void *data));
99 extern void ui_table_data_bind(struct ui_table *tbl);
100 extern int ui_table_data_count(struct ui_table *tbl);
101 extern int ui_table_scroll_height(struct ui_table *tbl);
103 extern struct ui_tab *ui_tab_create(void);
104 extern void ui_tab_destroy(struct ui_tab *tab);
105 extern void ui_tab_pos_set(struct ui_tab *tab, int y, int x);
106 extern void ui_tab_event_cb_set(struct ui_tab *tab, ui_tab_event_cb cb);
107 extern void ui_tab_active_color_set(struct ui_tab *tab, int color);
108 extern void ui_tab_show(struct ui_tab *tab);
109 extern void ui_tab_entry_add(struct ui_tab *tab, uint32_t id, const char *name);
110 extern void ui_tab_event_send(struct ui_tab *tab, uint32_t id);
112 #endif /* UI_H */