Navigation C API Pages Python bindings Applications

Table widget

Table widget is a widget that shows a table.

The table content is not stored in the widget, instead there are callbacks that are called to get the cells content when table is being rendered.

Table widget callbacks
enum gp_widget_table_row_op {
        GP_TABLE_ROW_RESET,
        GP_TABLE_ROW_ADVANCE,
        GP_TABLE_ROW_TELL,
};

typedef struct gp_widget_table_col_dsc {
        /** Column human readable ID */
        const char *id;
        /** An index to map the human readable ID to */
        unsigned long idx;
        /** If sort is not set this describes if column is sortable */
        int sortable:1;
} gp_widget_table_col_dsc;

typedef struct gp_widget_table_col_ops {
        int (*seek_row)(gp_widget *self, int op, unsigned int pos);
        int (*get_cell)(gp_widget *self, gp_widget_table_cell *cell, unsigned int col_idx);
        void (*sort)(gp_widget *self, int desc, unsigned int col_idx);

        /** NULL id terminated column map array */
        gp_widget_table_col_dsc col_map[];
} gp_widget_table_col_ops;

The gp_widget_table_col_dsc structure describes a column and the gp_widget_table_col_ops describes all possible columns along with callbacks to get table cells and possibly sort table by a column.

What user sees on the screen is described by an array of gp_widget_table_header structures which is usually loaded from a JSON description.

Table 1. seek_row() callback ops
enum gp_widget_table_row_op Description

GP_TABLE_ROW_RESET

Sets the current row to 0 i.e. the first row in the table.

GP_TABLE_ROW_ADVANCE

Moves the current row by the op parameter elements forward. Returns non-zero if resulting row is valid and zero if not.

GP_TABLE_ROW_MAX

Returns the number of rows in a table i.e. max_index + 1, or -1 if unknown at the time of the call.

Sorting

If any of the table columns is sortable the sortable flag has to be set in the corresponding column description and the col_ops→sort() callback must be implemented for the particular column.