Fl_Group | +----Fl_Table | +----Fl_Table_Row
#include <FL/Fl_Table.H>
This widget does not handle the data in the table. The draw_cell() method must be overridden by a subclass to manage drawing the contents of the cells.
This widget can act as a container for FLTK widgets (see widgettable.cxx), or custom widgets (see testtablerow.cxx, with custom widgets being optimal for very large tables.
When acting as a container for custom widgets, events on the cells and/or headings generate callbacks when they are clicked by the user. You control when events are generated based on the values you supply for when().
When acting as a container for FLTK widgets, the fltk widgets maintain themselves, and although the draw_cell() method must be overridden, its contents can be very simple. (See the draw_cell() code in widgettable.cxx).
Only cells that are completely (or partially) visible will be told to draw.
context will be one of the following:
row and col will be set to the row and column number the user clicked on. In the case of row headers, col will be 0. In the case of column headers, row will be 0.
x/y/w/h will be the position and dimensions of where the cell should be drawn.
In the case of custom widgets, a minimal draw_cell() override might look like the following. With custom widgets it is up to the caller to handle drawing everything within the dimensions of the cell, including handling the selection color. Note all clipping must be handled as well; this allows drawing outside the dimensions of the cell if so desired for 'custom effects'.
void MyTable::draw_cell(TableContext context, int R=0, int C=0, int X=0, int Y=0, int W=0, int H=0) { static char s[40]; sprintf(s, "%d/%d", R, C); // text for each cell switch ( context ) { case CONTEXT_NEWPAGE: fl_font(FL_HELVETICA, 16); return; case CONTEXT_ROW_HEADER: case CONTEXT_COL_HEADER: fl_push_clip(X, Y, W, H); { fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, color()); fl_color(FL_BLACK); fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER); } fl_pop_clip(); return; case CONTEXT_CELL: fl_push_clip(X, Y, W, H); { // BG COLOR fl_color( row_selected(R) ? selection_color() : FL_WHITE); fl_rectf(X, Y, W, H); // TEXT fl_color(FL_BLACK); fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER); // BORDER fl_color(FL_LIGHT2); fl_rect(X, Y, W, H); } fl_pop_clip(); return; default: return; } //NOTREACHED }
context will be one of the following:
row and col will be set to the row and column number the user clicked on. If someone clicked on a row header, col will be 0. If someone clicked on a column header, row will be 0.
The second form sets the number of columns in the table, and the table is redrawn.
The second form sets if column headers should be enabled; 1=enabled, 0=disabled. If changed, the table is redrawn.
The second form sets the column header color and the table is redrawn.
The second form sets the column header height to n and causes the screen to redraw.
The second form sets the column scroll position to column 'col', and causes the screen to redraw.
The second form sets if columns can be resized by the user; 1=enabled, 0=disabled.
The second form returns the current width of the specified column in pixels and causes the screen to redraw.
The second form sets the number of rows in the table, and the table is redrawn.
The second form sets if row headers should be enabled; 1=enabled, 0=disabled. If changed, the table is redrawn.
The second form sets the row header color and causes the screen to redraw.
The second form sets the row header width to n and causes the screen to redraw.
The second form sets the row scroll position to 'row', and causes the screen to redraw.
The second form sets if rows can be resized by the user; 1=enabled, 0=disabled.
The first form returns the current height of the specified row in pixels.
The second form sets the height of the specified row in pixels, and the table is redrawn.
The second form sets which row should be at the top of the table, scrolling as necessary, and the table is redrawn. If the table cannot be scrolled that far, it is scrolled as far as possible.
The second form sets when the parent's Fl_Table::callback() is called. These are the only values currently supported: