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.
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().
|
|
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 dimension of the cell.
A minimal draw_cell() override might look like the following. 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 if columns can be resized by the user; 1=enabled, 0=disabled.
The second form sets the width of the specified column in pixels, and the table is redrawn.
The second form sets the number of rows in the table, and the table is redrawn.
The first form returns if row headers are enabled or not; 1=enabled, 0=disabled.
The second form sets if row headers should be enabled; 1=enabled, 0=disabled. If changed, the table is redrawn.
The first form returns if rows can be resized by the user by dragging the row borders in the row's header. row_header() must also be enabled for this to be useful. 1=resizable, 0=disabled.
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: