Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fltk/fltk/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Fl_Table widget is a table of rows and columns with scrolling support. This is the base class that must be subclassed to be useful. Applications typically use widgets derived from this class rather than using it directly.
Fl_Table does not handle the data in the table. The draw_cell() method must be overridden by a subclass to manage drawing the contents of cells.
Constructor
Creates a new table widget.Optional label for the widget
Table Context
The TableContext enum indicates where an event or draw operation is occurring:
CONTEXT_NONE - No known context
CONTEXT_STARTPAGE - Before table is redrawn
CONTEXT_ENDPAGE - After table is redrawn
CONTEXT_ROW_HEADER - In row header
CONTEXT_COL_HEADER - In column header
CONTEXT_CELL - In a data cell
CONTEXT_TABLE - In dead zone of table
CONTEXT_RC_RESIZE - Column or row being resized
Size Configuration
Sets the number of rows in the table.
Sets the number of columns in the table.
Sets the height of a specific row.
Sets the width of a specific column.
Sets all rows to the same height.
Sets all columns to the same width.
Enables or disables row headers.1 to enable, 0 to disable
Enables or disables column headers.1 to enable, 0 to disable
Sets the row header width.
Sets the column header height.
Sets the row header color.
Sets the column header color.
Resizing
Allows or disallows interactive row resizing.1 to allow, 0 to disallow
Allows or disallows interactive column resizing.1 to allow, 0 to disallow
Sets minimum row resize height.Minimum height in pixels (≥1)
Sets minimum column resize width.Minimum width in pixels (≥1)
Scrolls to show the specified row at the top.Row number to position at top
Scrolls to show the specified column at the left.Column number to position at left
Returns the range of visible cells.Returns bottom visible row
Returns left visible column
Returns right visible column
Selection
Checks if a cell is selected.Returns 1 if selected, 0 otherwise.
Gets the current selection range.Returns top row of selection
Returns left column of selection
Returns bottom row of selection
Returns right column of selection
Sets the selection range.Right column of selection
Callbacks
Returns the row number where the event occurred (call from callback).
Returns the column number where the event occurred (call from callback).
Returns the table context where the event occurred (call from callback).
Returns 1 if user is interactively resizing a row or column.
Virtual Methods to Override
Override this method to handle drawing cells.Where the draw is occurring
Example
#include <FL/Fl_Table.H>
#include <FL/fl_draw.H>
#include <stdio.h>
class MyTable : public Fl_Table {
void draw_cell(TableContext context, int R, int C,
int X, int Y, int W, int H) override {
static char s[40];
sprintf(s, "%d/%d", R, C);
switch (context) {
case CONTEXT_STARTPAGE:
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);
// Background
fl_color(is_selected(R,C) ? 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;
}
}
public:
MyTable(int X, int Y, int W, int H, const char *L=0)
: Fl_Table(X, Y, W, H, L) {
rows(30);
cols(10);
row_header(1);
col_header(1);
col_header_height(25);
row_header_width(60);
col_resize(1);
row_resize(1);
end();
}
};
int main() {
Fl_Window *win = new Fl_Window(800, 600, "Table Example");
MyTable *table = new MyTable(10, 10, 780, 580);
win->end();
win->show();
return Fl::run();
}
See Also