1 # data file for the Fltk User Interface Designer (fluid)
5 declblock {\#include <FL/fl_draw.H>} {open public after {\#include <FL/Fl_Table_Row.H>}
8 declblock {\#include <string>} {open public after {\#include <vector>}
11 class SimpleTable {open : {public Fl_Table_Row}
13 Function {draw_cell(TableContext context, int R=0, int C=0, int X=0, int Y=0, int W=0, int H=0)} {open return_type void
15 code {static char s[40];
17 case CONTEXT_STARTPAGE: // before page is drawn..
18 fl_font(FL_HELVETICA, 16); // set the font for our drawing operations
20 case CONTEXT_COL_HEADER: // Draw column headers
21 sprintf(s,"%c",'A'+C); // "A", "B", "C", etc.
22 DrawHeader(s,X,Y,W,H);
24 case CONTEXT_ROW_HEADER: // Draw row headers
25 sprintf(s,"%02d:",R); // "001:", "002:", etc
26 DrawHeader(s,X,Y,W,H);
28 case CONTEXT_CELL: // Draw data in cells
29 if((int)m_TableData.size()-1 < R)
30 SetTableData("", 0, R);
32 if((int)m_TableData.at(R).size()-1 < C)
33 SetTableData("", C, 0);
35 DrawData(m_TableData.at(R).at(C).c_str(),
36 m_CellColors.at(R).at(C),X,Y,W,H);
42 Function {SimpleTable(int x, int y, int w, int h, const char *l = 0) : Fl_Table_Row(x,y,w,h,l)} {} {
45 Function {SetTableData(std::string data, unsigned int x = 0, unsigned int y = 0, Fl_Color color = FL_WHITE)} {return_type void
47 code {if(m_TableData.empty() || (m_TableData.size() < y+1))
49 m_TableData.resize(y+1);
53 for (unsigned int i = 0; i < m_TableData.size(); ++i)
54 if(m_TableData.at(i).empty() ||
55 (m_TableData.at(i).size() < x+1))
57 m_TableData.at(i).resize(x+1, "");
61 m_TableData.at(y).at(x) = data;
62 SetCellColor(color,x,y);} {}
64 Function {SetCellColor(Fl_Color color, unsigned int x = 0, unsigned int y = 0)} {return_type void
66 code {if(m_CellColors.empty() || (m_CellColors.size() < y+1))
68 m_CellColors.resize(y+1);
72 for (unsigned int i = 0; i < m_CellColors.size(); ++i)
73 if(m_CellColors.at(i).empty() ||
74 (m_CellColors.at(i).size() < x+1))
76 m_CellColors.at(i).resize(x+1, FL_WHITE);
80 m_CellColors.at(y).at(x) = color;} {}
82 Function {GetTableData()} {return_type {std::vector<std::vector<std::string>>}
84 code {return m_TableData;} {}
86 Function {Resize(unsigned int x = 0, unsigned int y = 0)} {} {
87 code {m_TableData.resize(y+1);
88 m_CellColors.resize(y+1);
90 for (unsigned int i = 0; i < m_TableData.size(); ++i)
92 m_CellColors.at(i).resize(x+1, FL_WHITE);
93 m_TableData.at(i).resize(x+1, "");
97 decl {using TableData = std::vector<std::vector<std::string>>;} {public local
99 decl {using TableCellColors = std::vector<std::vector<Fl_Color>>;} {public local
101 Function {DrawData(const char *s, Fl_Color cell_color, int X, int Y, int W, int H)} {private return_type void
103 code {fl_push_clip(X,Y,W,H);
105 fl_color(cell_color); fl_rectf(X,Y,W,H);
107 fl_color(FL_GRAY0); fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
109 fl_color(color()); fl_rect(X,Y,W,H);
112 Function {DrawHeader(const char *s, int X, int Y, int W, int H)} {private return_type void
114 code {fl_push_clip(X,Y,W,H);
115 fl_draw_box(FL_THIN_UP_BOX, X,Y,W,H, row_header_color());
117 fl_draw(s, X,Y,W,H, FL_ALIGN_CENTER);
120 decl {TableData m_TableData;} {private local
122 decl {TableCellColors m_CellColors;} {private local
127 Function {ViewFluid()} {protected
129 Fl_Window win_exmpl {
131 protected xywh {728 312 500 300} type Double box GTK_DOWN_BOX hide hotspot size_range {585 555 0 0}
133 Fl_Button btn_exception {
134 label {Throw Exception}
135 protected xywh {20 120 135 45}
137 Fl_Table tbl_example {open
138 protected tooltip {Simple Table Implementation Example} xywh {170 0 330 300}