Look at examples/table-simple.cxx and examples/table-spreadsheet.cxx
table-simple shows a read only way to look at a table of
integer values (int data[MAX_ROWS][MAX_COLS]).
Data management is entirely up to you; Fl_Table handles the UI
component, your derived class handles managing the data, and Fl_Table
invokes your derived class's draw_cell() method to tell it which
cell to draw, and will tell you the xywh value of where to draw it.
Fl_Table handles the UI drawing, but does not manage your data.
This allows you to manage the data in whatever way is best for
your application. For some people managing the data in an array
is best, for some a database, and for others the table data isn't
in memory at all, and can be purely algorithmic.
> And at least Fl_Table has understanding of rows only. How
> columns are handled?
See above examples.
> I'm also worrying about column width in sense how to handle
> easily longer data.
See the Fl_Table::col_width(col,width) method.
This lets you change on a per-column basis what the column's
width would be, and you can enable the user to interactively
resize column widths by dragging them (see Fl_Table::row_resize()).
Ditto for columns.
Since your draw_cell() method handles drawing the data,
you handle how to best display the data, e.g. left/center/right
justified in the cell, how clipping and colors and fonts are
handled, etc.
> And in the code I don't like to do so much
> tedious coordinate calculation.
Fl_Table handles coordinate calculations for you; that's the UI component.
For dynamic array you can use similarly this is:
[CODE=CPP]
#include <iostream>
#include <string>
#include <vector>
#define ROWS 3
#define COLS 5
typedef std::vector < std::vector < std::string>> a3d_t;
void resize (a3d_t &a, int rows, int cols) {
a.resize(rows);
for (int i = 0; i < rows; i++) a[i].resize(cols);
}
// g++ 3d.cxx -o 3d && ./3d
int main(){
a3d_t arr3d;
resize(arr3d, ROWS, COLS);
arr3d[0][0] = "Hello";
std::cout << arr3d[0][0] << std::endl;
return 0;
}
[/CODE]