Skip to main content

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

Fl_Table
constructor
Creates a new table widget.
X
int
required
X position of the widget
Y
int
required
Y position of the widget
W
int
required
Width of the widget
H
int
required
Height of the widget
L
const char*
default:"0"
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

rows
void
Sets the number of rows in the table.
val
int
required
Number of rows
cols
void
Sets the number of columns in the table.
val
int
required
Number of columns
row_height
void
Sets the height of a specific row.
row
int
required
Row number
height
int
required
Height in pixels
col_width
void
Sets the width of a specific column.
col
int
required
Column number
width
int
required
Width in pixels
row_height_all
void
Sets all rows to the same height.
height
int
required
Height in pixels
col_width_all
void
Sets all columns to the same width.
width
int
required
Width in pixels

Headers

row_header
void
Enables or disables row headers.
flag
int
required
1 to enable, 0 to disable
col_header
void
Enables or disables column headers.
flag
int
required
1 to enable, 0 to disable
row_header_width
void
Sets the row header width.
width
int
required
Width in pixels
col_header_height
void
Sets the column header height.
height
int
required
Height in pixels
row_header_color
void
Sets the row header color.
val
Fl_Color
required
Color value
col_header_color
void
Sets the column header color.
val
Fl_Color
required
Color value

Resizing

row_resize
void
Allows or disallows interactive row resizing.
flag
int
required
1 to allow, 0 to disallow
col_resize
void
Allows or disallows interactive column resizing.
flag
int
required
1 to allow, 0 to disallow
row_resize_min
void
Sets minimum row resize height.
val
int
required
Minimum height in pixels (≥1)
col_resize_min
void
Sets minimum column resize width.
val
int
required
Minimum width in pixels (≥1)

Scrolling and Position

row_position
void
Scrolls to show the specified row at the top.
row
int
required
Row number to position at top
col_position
void
Scrolls to show the specified column at the left.
col
int
required
Column number to position at left
visible_cells
void
Returns the range of visible cells.
r1
int&
required
Returns top visible row
r2
int&
required
Returns bottom visible row
c1
int&
required
Returns left visible column
c2
int&
required
Returns right visible column

Selection

is_selected
int
Checks if a cell is selected.
r
int
required
Row number
c
int
required
Column number
Returns 1 if selected, 0 otherwise.
get_selection
void
Gets the current selection range.
row_top
int&
required
Returns top row of selection
col_left
int&
required
Returns left column of selection
row_bot
int&
required
Returns bottom row of selection
col_right
int&
required
Returns right column of selection
set_selection
void
Sets the selection range.
row_top
int
required
Top row of selection
col_left
int
required
Left column of selection
row_bot
int
required
Bottom row of selection
col_right
int
required
Right column of selection

Callbacks

callback_row
int
Returns the row number where the event occurred (call from callback).
callback_col
int
Returns the column number where the event occurred (call from callback).
callback_context
TableContext
Returns the table context where the event occurred (call from callback).
is_interactive_resize
int
Returns 1 if user is interactively resizing a row or column.

Virtual Methods to Override

draw_cell
virtual void
Override this method to handle drawing cells.
context
TableContext
required
Where the draw is occurring
R
int
default:"0"
Row number
C
int
default:"0"
Column number
X
int
default:"0"
X position to draw
Y
int
default:"0"
Y position to draw
W
int
default:"0"
Width of cell
H
int
default:"0"
Height of cell

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