GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
AG_TABLE(3) FreeBSD Library Functions Manual AG_TABLE(3)

AG_Tableagar table display widget

#include <agar/core.h>
#include <agar/gui.h>

The AG_Table widget displays a set of cells organized in one or more columns. Cells can be associated with text, numerical values, pointers to numerical values, or custom functions. AG_Table is optimized for tables that must be rebuilt frequently. Individual cells, entire rows or entire columns can be selected indepedently.

Note that another table display widget, AG_Treetbl(3), is also available. It stores row information in a tree structure and provides a very different interface from AG_Table.

AG_Object(3) -> AG_Widget(3) -> AG_Table.

AG_Table *
(AG_Widget *parent, Uint flags);


AG_Table *
(AG_Widget *parent, Uint flags, void (*event_fn)(AG_Event *), const char *event_args, ...);


void
(AG_Table *tbl, Uint ms);


void
(AG_Table *tbl, int width, int nrows);


void
(AG_Table *tbl, int height);


void
(AG_Table *tbl, int height);


void
(AG_Table *tbl, int width);


void
(AG_Table *tbl, int width);


void
(AG_Table *tbl, enum ag_table_selmode mode);


void
(AG_Table *tbl, const char *sep);


AG_MenuItem *
(AG_Table *tbl, int row, int col);


void
(AG_Table *tbl, AG_EventFn fn, const char *fn_args, ...);


void
(AG_Table *tbl, AG_EventFn fn, const char *fn_args, ...);


void
(AG_Table *tbl, AG_EventFn fn, const char *fn_args, ...);


void
(AG_Table *tbl, AG_EventFn fn, const char *fn_args, ...);


void
(AG_Table *tbl, AG_EventFn fn, const char *fn_args, ...);


void
(AG_Table *tbl, AG_EventFn fn, const char *fn_args, ...);


void
(AG_Table *tbl, Uint action);

The () function allocates, initializes and attaches a new AG_Table widget.

The () variant sets the polling flag and configures the ‘table-poll’ event. event_fn is a pointer to the event-handler function responsible for populating the table (see AG_TableBegin() and AG_TableEnd() for details). event_args and the following arguments are optional AG_Event(3) style parameters that will be passed on to event_fn.

Acceptable flags include:

AG_TABLE_MULTI
Allow the user to select multiple items while holding CTRL or SHIFT.
AG_TABLE_MULTITOGGLE
Allow the user to select multiple items without holding CTRL or SHIFT.
AG_TABLE_POLL
Table contents are updated dynamically by the ‘table-poll’ event handler (implied by ()).
AG_TABLE_SCROLL_TO_SEL
If the selection is not visible, scroll towards it. This flag is writeable, but is automatically set or cleared by keyboard events.
AG_TABLE_HIGHLIGHT_COLS
Highlight the currently selected column(s) using transparency.
AG_TABLE_HFILL
Expand horizontally in parent container.
AG_TABLE_VFILL
Expand vertically in parent container.
AG_TABLE_EXPAND
Shorthand for AG_TABLE_HFILL | . This is recommended as an alternative to calling AG_TableSizeHint().
AG_TABLE_NOAUTOSORT
Disable automatic sorting (see AG_TableSort()).

The () function specifies an alternate update interval for polled tables in milliseconds (default is 250ms). Polling may be paused by calling AG_TableSetPollInterval() with an argument of 0.

The () function requests an initial sizing, where width is the width in pixels and nrows is the number of rows to display.

() sets the size of column headers in pixels. AG_TableSetRowHeight() sets the size of rows in pixels. In both cases, the default is dependent on the height of the default font.

() sets the minimum allowed column width, in pixels. The default is a small value intended to prevent the user from resizing columns to zero size. If existing columns are smaller than the specified value, AG_TableSetColMin() will resize them.

() specifies a "default" width in pixels, to use during initial size requisition for columns using FILL or a size specification in "%".

() defines the effect of cursor selections on the table. Possible values for mode are:

enum ag_table_selmode {
	AG_TABLE_SEL_ROWS,	/* Select entire rows */
	AG_TABLE_SEL_CELLS,	/* Select individual cells */
	AG_TABLE_SEL_COLS	/* Select entire columns */
};

() changes the set of accepted field-separator characters in AG_TableAddRow() (default is ":").

The () function creates a contextual AG_Menu(3) item associated with a row, column or cell. If col is a valid index and row is -1, the menu is shown when clicking on the header of the given column. If col is -1 and row is a valid index, the menu is shown when clicking on any cell of the given row. If col and row are both valid indices, the menu is shown when clicking on the given cell. If both indices are -1, the menu is shown when clicking on any cell. If a contextual menu already exists for the specified indices, AG_TableSetPopup() returns a pointer to the existing menu item.

The (), AG_TableSetColClickFn() and AG_TableSetCellClickFn() functions register a callback routine to invoke upon single-click on a row, column or cell, respectively, depending on the current selection mode. The callback routine for AG_TableSetRowClickFn() is passed the row index as an int argument. AG_TableSetColClickFn() is passed the column index and AG_TableSetCellClickFn() is passed the row and column indices in order.

The (), AG_TableSetColDblClickFn(), and AG_TableSetCellDblClickFn() variants register callbacks to invoke on double-click. If both single and double-click callbacks are defined, only the single-click callback is used.

The () specifies the action(s) to take whenever a column header is pressed. Acceptable arguments to flags include:

AG_TABLE_SELECT
Select the entire column.
AG_TABLE_SORT
Change the sort direction of the column.

void
AG_TableBegin(AG_Table *tbl);


void
(AG_Table *tbl);


void
(AG_Table *tbl);


void
(AG_Table *tbl);

Tables created with () are periodically repopulated, using a callback routine. In this callback routine, calls to AG_TableAddRow() should be enclosed between AG_TableBegin() and AG_TableEnd(). It is not allowed to add or remove columns from the callback routine. The AG_TableBegin() function, notably, saves current selection information (to keep selections consistent across table re-population), and clears all rows.

This method of repopulating a table using a function nicely separates the GUI from the underlying application. It is also more efficient than it seems, since () will re-use the resources (e.g., already rendered text surfaces) of unchanged cells.

The () function sorts the rows of the table. This function is useful in combination with the AG_TABLE_NOAUTOSORT option.

The () routine clears the rows of the table. It is equivalent to calling AG_TableBegin().

int
AG_TableAddCol(AG_Table *tbl, const char *name, const char *size_spec, int (*sortFn)(const void *, const void *));


void
(AG_Table *tbl, int col);


void
(AG_Table *tbl, int col);


void
(AG_Table *tbl);


void
(AG_Table *tbl);


int
(AG_Table *tbl, int col);

The () function inserts a new column into the table, returning the number of the new column if successful, or -1 if an error has occurred. name specifies the text to display in the column header. size_spec is an optional size specification (see AG_SizeSpec(3)) used in initial sizing of the column. sortFn, if not NULL, is the compare function to use for items of this column. It is passed pointers to two AG_TableCell structures to compare.

The () and AG_TableDeselectCol() functions control the selection flag on the given column. AG_TableSelectAllCols() and AG_TableDeselectAllCols() set the selection flag on all columns of the table. AG_TableColSelected() returns 1 if the given column is selected, 0 otherwise.

Note that the of the column selection flags are independent from the selection flag of individual cells; their meaning is application-specific.

int
(AG_Table *tbl, const char *fmt, ...);


void
(AG_Table *tbl, int row);


void
(AG_Table *tbl, int row);


void
(AG_Table *tbl);


void
(AG_Table *tbl);


void
(AG_Table *tbl, int row);

The () function inserts a new row into the table and returns the new row number, or -1 if a failure has occurred. The fmt argument describes the individual fields (or cells) of this row. By default, the fields are comma-separated (the separator can be changed using AG_TableSetSeparator()). Note that it is possible to mix fields of differing types into a same column as long as the sorting function of that column can handle the combinations.

Acceptable specifiers include:

%s
Text string
%i, %d
Signed integer
%li, %ld
Long integer
%lli, %lld
Long long integer
%u, %x
Unsigned integer
%lu, %lx
Unsigned long integer
%llu, %llx
Unsigned long long integer
%[s8], %[s16], %[s32]
Signed 8-bit, 16-bit or 32-bit value
%[u8], %[u16], %[u32]
Unsigned 8-bit, 16-bit or 32-bit value
%f, %g
Floating-point value (precision modifiers like %.03f are accepted)
%p
User pointer (usually stored in hidden columns)
%[Ft]
User-specified function of the form:

void (void *tbl, char *buf, AG_Size len)

The text copied into buf (which is len bytes in size) will be displayed in the cell.

%[Fs]
User-specified function of the form:

AG_Surface * (void *tbl, int x, int y)

The returned AG_Surface(3) will be displayed in the cell. Note that this surface will be automatically freed once the widget is destroyed (similarly to AG_WidgetMapSurface(3), see %[FS] variant below). The x and y parameters can be ignored.

%[FS]
Same as "%[Fs]", except that Agar will never try to free the returned surface (similarly to AG_WidgetMapSurfaceNODUP(3)).
%[W]
A widget instance to insert into the table.

The functions () and AG_TableDeselectRow() set the selection flag on all cells of the given row. AG_TableSelectAllRows() and AG_TableDeselectAllRows() set the selection on all cells of the table. AG_TableRowSelected() returns 1 if the given row is selected, 0 otherwise.

AG_TableCell *
AG_TableGetCell(AG_Table *tbl, int row, int col);


void
(AG_Table *tbl, int row, int col);


void
(AG_Table *tbl, int row, int col);


void
(AG_Table *tbl, int row, int col);


void
(const AG_TableCell *c1, const AG_TableCell *c2);


void
(AG_Table *tbl, const AG_TableCell *c, char *dst, AG_Size dstLen);

The () routine returns a pointer to the table cell currently at the specified row and column position.

(), AG_TableDeselectCell() and AG_TableCellSelected() control and query the selection flag on an individual cell located at the given row and column.

The () function compares cells c1 and c2. It returns 0 if the contents of the two cells is identical, otherwise the returned value depends on the type. If the cells have different types, it returns 1. If they are text-based, the return value of strcmp(3) is returned. If they are numerical, the difference is returned. For pointer and surface cells, the return value is 1 if they differ.

The () function writes a formatted string representation of the current cell value, to the fixed-size buffer dst.

int
AG_TableSaveASCII(AG_Table *tbl, FILE *f, char separator);

() writes the formatted contents of the table into an ASCII file f. Each row is separated by a newline, and cells are separated by the character given by the separator argument. The function returns 0 on success, -1 on failure.

The AG_Table widget generates the following events:

(int index)
The row at specified index was selected.

For the AG_Table object:

AG_TableCell *cells
Cell data in sorted rows (read-only).
AG_TableCol *cols
Column data (read-only);
int n
Number of columns (read-only).
int m
Number of rows (read-only).

For the AG_TableCell structure:

enum ag_table_cell_type type
Data type (see below).
Uint id
Optional user-specified ID (or 0).
char fmt[]
Format string (read-only; see ()).
AG_Widget *widget
Embedded widget for AG_CELL_WIDGET type cells (read-only).
int selected
Selection flag (1 = selected, 0 = not selected).
AG_Table *tbl
Back pointer to AG_Table widget.

For the AG_TableCol structure:

char name[]
Column header text string (read-only).
Uint flags
Flags including AG_TABLE_COL_FILL (expand to fill remaining space), AG_TABLE_COL_ASCENDING (sort ascending), AG_TABLE_COL_DESCENDING (sort descending) and AG_TABLE_COL_SELECTED (column selection flag).
int w
Column width in pixels (read-only).
int wPct
Column width in % (or -1).

The cell data type is determined by enum ag_table_cell_type:

AG_CELL_NULL
Empty cell.
AG_CELL_STRING
C string.
AG_CELL_INT
Integer value.
AG_CELL_UINT
Unsigned integer value.
AG_CELL_LONG
Native long integer.
AG_CELL_LONG
Native unsigned long integer.
AG_CELL_FLOAT
Floating point number (single-precision).
AG_CELL_DOUBLE
Floating point number (double-precision).
AG_CELL_PSTRING
Pointer to a C string.
AG_CELL_PINT
Pointer to an integer.
AG_CELL_PUINT
Pointer to an unsigned integer.
AG_CELL_PLONG
Pointer to a long integer.
AG_CELL_PULONG
Pointer to a unsigned long integer.
AG_CELL_INT64
64-bit integer (if HAVE_64BIT only).
AG_CELL_PUINT8
 
AG_CELL_PSINT8
 
AG_CELL_PUINT16
 
AG_CELL_PSINT16
 
AG_CELL_PUINT32
 
AG_CELL_PSINT32
 
AG_CELL_PUINT64
 
AG_CELL_PSINT64
Pointer to an integer in specified format.
AG_CELL_PFLOAT
 
AG_CELL_PDOUBLE
Pointer to a floating-point number.
AG_CELL_POINTER
Generic pointer.
AG_CELL_FN_SU
Function returning a surface (see %[Fs]).
AG_CELL_FN_SU_NODUP
Function returning a surface that should not be freed (see %[FS]).
AG_CELL_FN_TXT
Function returning a text string.
AG_CELL_WIDGET
Embedded widget (see %[W]).

The following code fragment creates a table and immediately populates it:

AG_Table *tbl;

tbl = AG_TableNew(win, AG_TABLE_EXPAND);
AG_TableAddCol(tbl, "Column 1", "<ExpectedSize>", NULL);
AG_TableAddCol(tbl, "Column 2", NULL, NULL);
AG_TableAddRow(tbl, "%s:%i", "Item1", 123);
AG_TableAddRow(tbl, "%s:%i", "Item2", 456);
AG_TableAddRow(tbl, "%s:%i", "Item3", 789);

The following code fragment creates a table and arranges for periodical update of its contents from an UpdateMyTable() function:

void
UpdateMyTable(AG_Event *event)
{
	AG_Table *tbl = AG_TABLE_SELF();

	AG_TableBegin(tbl);
	AG_TableAddRow(tbl, "%s:%d", "foo", 1234);
	AG_TableEnd(tbl);
}

...

AG_Table *tbl;

tbl = AG_TableNewPolled(win, AG_TABLE_EXPAND, UpdateMyTable, NULL);

For more example usages, see tests/table.c in the Agar source distribution.

AG_Intro(3), AG_Surface(3), AG_Widget(3), AG_Window(3)

The AG_Table widget first appeared in Agar 1.0.

December 21, 2022 Agar 1.7

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.