-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathTable.cpp
More file actions
81 lines (73 loc) · 3.05 KB
/
Table.cpp
File metadata and controls
81 lines (73 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <string>
#include <vector>
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Table.H>
#include <FL/Fl_Window.H>
namespace Examples {
class Start_Trek_Character_Table : public Fl_Table {
public:
Start_Trek_Character_Table(int x, int y, int width, int height) : Fl_Table {x, y, width, height} {
rows(static_cast<int>(cells.size()));
cols(static_cast<int>(cells[0].size()));
col_header(true);
col_width(0, 130);
col_width(1, 80);
col_width(2, 90);
col_width(3, 310);
col_width(4, 160);
col_resize(true);
}
private:
static void draw_column_header(const std::string& value, int x, int y, int width, int height) noexcept {
fl_push_clip(x, y, width, height);
fl_draw_box(FL_THIN_UP_BOX, x, y, width, height, FL_BACKGROUND_COLOR);
fl_color(FL_FOREGROUND_COLOR);
fl_font(FL_HELVETICA_BOLD, FL_NORMAL_SIZE);
fl_draw(value.c_str(), x, y, width, height, FL_ALIGN_CENTER);
fl_pop_clip();
}
static void draw_cell(const std::string& value, int x, int y, int width, int height) noexcept {
fl_push_clip(x, y, width, height);
fl_color(FL_BACKGROUND2_COLOR);
fl_rectf(x, y, width, height);
fl_color(FL_FOREGROUND_COLOR);
fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
fl_draw(value.c_str(), x + 2, y, width, height, FL_ALIGN_LEFT);
fl_color(FL_BACKGROUND_COLOR);
fl_rect(x, y, width, height);
fl_pop_clip();
}
void draw_cell(TableContext context, int row = 0, int column = 0, int x = 0, int y = 0, int width = 0, int height = 0) noexcept override {
Fl_Table::draw_cell(context, row, column, x, y, width, height);
switch (context) {
case CONTEXT_COL_HEADER: draw_column_header(column_header_datas[column], x, y, width, height); return;
case CONTEXT_CELL: draw_cell(cells[row][column], x, y, width, height); return;
default: return;
}
}
std::vector<std::string> column_header_datas {"Name", "Gender", "Species", "Affiliation", "Rank"};
std::vector<std::vector<std::string>> cells {
{"James T. Kirk", "Male", "Human", "Federation Starfleet", "Captain"},
{"Worf", "Male", "Klingon", "Federation Starfleet / House of Martok", "Lieutenant Commander"},
{"T'Pol", "Female", "Vulcan", "Vulcan High Command / United Earth Starfleet", "Commander"},
{"Kira Nerys", "Female", "Bajoran", "Bajoran Militia / Federation Starfleet", "Colonel / Commander"},
{"Phlox", "Male", "Denobulan", "Interspecies Medical Exchange", "Doctor"},
{"Jean-Luc Picard", "Male", "Human", "Federation Starfleet", "Amiral"},
{"The Doctor (EMH)", "Hologram", "Male", "\"USS Voyager\"", "Chief Medical Officer"},
};
};
class Main_Window : public Fl_Window {
public:
Main_Window() : Fl_Window {200, 100, 792, 215, "Table example"} {
resizable(table);
}
private:
Start_Trek_Character_Table table {10, 10, 772, 195};
};
}
auto main(int argc, char *argv[]) -> int {
auto window = Examples::Main_Window {};
window.show(argc, argv);
return Fl::run();
}