GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget_table.h
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2021 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
9#ifndef GP_WIDGET_TABLE_H
10#define GP_WIDGET_TABLE_H
11
12enum gp_widget_table_row_op {
14 GP_TABLE_ROW_RESET,
16 GP_TABLE_ROW_ADVANCE,
18 GP_TABLE_ROW_MAX
19};
20
21typedef struct gp_widget_table_cell {
22 const char *text;
23 gp_widget_tattr tattr;
24} gp_widget_table_cell;
25
35 const char *id;
37 unsigned long idx;
39 int sortable:1;
41
49 int (*seek_row)(gp_widget *self, int op, unsigned int pos);
50 int (*get_cell)(gp_widget *self, gp_widget_table_cell *cell, unsigned int col_idx);
51 void (*sort)(gp_widget *self, int desc, unsigned int col_idx);
52
55 void *on_event_priv;
56
60
64typedef struct gp_widget_table_header {
67
69 char *label;
70
72 gp_widget_tattr tattr;
73
75 unsigned int col_min_size;
76 unsigned int col_fill;
78
82typedef struct gp_widget_table_col {
83 unsigned int size;
84 unsigned int min_size;
86
87typedef struct gp_widget_table {
88 unsigned int cols;
89 unsigned int min_rows;
90
92 const gp_widget_table_header *header;
95
96 unsigned int selected_row;
97 unsigned int sorted_by_col;
98 int row_selected:1;
99 int sorted_desc:1;
100 int needs_header:1;
101
102 uint64_t last_click;
103
104 unsigned int start_row;
105 unsigned int last_rows;
106
107 gp_widget_table_col *cols_w;
108
109 void *priv;
110
111 /* iterator based API */
112 union {
113 void *row_priv;
114 unsigned long row_idx;
115 };
116
117 void *free;
118
119 char buf[];
120} gp_widget_table;
121
125enum gp_widget_table_event_type {
127 GP_WIDGET_TABLE_TRIGGER,
129 GP_WIDGET_TABLE_SELECT,
130};
131
132gp_widget *gp_widget_table_new(unsigned int cols, unsigned int min_rows,
133 const gp_widget_table_col_ops *col_ops,
134 const gp_widget_table_header *header);
135
136void gp_widget_table_sort_by(gp_widget *self, int desc, unsigned int col);
137
138/*
139 * Called when table content has changed and table needs to be rerendered.
140 */
141void gp_widget_table_refresh(gp_widget *self);
142
143/*
144 * @brief Sets first row that should be shown by the table.
145 *
146 * @self A table widget.
147 * @off A row offset.
148 */
149void gp_widget_table_off_set(gp_widget *self, unsigned int off);
150
151/*
152 * @brief Sets selected row.
153 *
154 * @self A table widget.
155 * @off A row.
156 */
157void gp_widget_table_sel_set(gp_widget *self, unsigned int row);
158
159#endif /* GP_WIDGET_TABLE_H */
Event structure passed to widget event handler.
int(* on_event)(gp_widget_event *ev)
gp_widget_table_col_dsc col_map[]
gp_widget_table_col_dsc * col_dsc