WINDEX
datasheet.h
1 namespace wex
2 {
3 
20 class datasheet : public wex::gui
21 {
22 public:
23  datasheet(gui *parent)
24  : gui(parent)
25  {
26  text("");
27  }
28 
31  void data(const std::vector<std::vector<std::string>> &vvdata)
32  {
33  vEB.clear();
34 
35  int xinit = 200;
36  int x = xinit;
37  int y = 50;
38  int w = 70;
39  int h = 30;
40  for (int krow = 0; krow < vvdata.size(); krow++)
41  {
42  std::vector<wex::editbox *> ebrow;
43  for (int kcol = 0; kcol < vvdata[0].size(); kcol++)
44  {
45  auto &eb = wex::maker::make<wex::editbox>(*this);
46  eb.move(x, y, w, h);
47  eb.text(vvdata[krow][kcol]);
48  ebrow.push_back(&eb);
49  x += w + 20;
50  }
51  vEB.push_back(ebrow);
52  y += h + 5;
53  x = xinit;
54  }
55  }
58  void rowLabels(const std::vector<std::string> &vRowLabels)
59  {
60  if (vRowLabels.size() != vEB.size())
61  return;
62 
63  int yrow0 = 50;
64  int y = yrow0;
65  int h = 30;
66  int w = 150;
67  for (int krow = 0; krow < vRowLabels.size(); krow++)
68  {
69  auto &lb = wex::maker::make<wex::label>(*this);
70  lb.move(10, y, w, 40);
71  lb.text(vRowLabels[krow]);
72  y += h + 5;
73  }
74  }
77  void colLabels(const std::vector<std::string> &vColLabels)
78  {
79  if (vColLabels.size() != vEB[0].size())
80  return;
81 
82  int xcol0 = 200;
83  int x = xcol0 + 10;
84  int w = 70;
85  for (int kcol = 0; kcol < vColLabels.size(); kcol++)
86  {
87  auto &lb = wex::maker::make<wex::label>(*this);
88  lb.move(x, 10, w, 40);
89  lb.text(vColLabels[kcol]);
90  x += w + 20;
91  }
92  }
93 
97  std::vector<std::string> dataRow(int row) const
98  {
99  std::vector<std::string> ret;
100  for( auto* v : vEB[row] )
101  ret.push_back( v->text() );
102  return ret;
103  }
104 
105 private:
106  std::vector<std::vector<wex::editbox *>> vEB;
107 };
108 }
A read/write table of values.
Definition: datasheet.h:21
std::vector< std::string > dataRow(int row) const
get data in a row
Definition: datasheet.h:97
void colLabels(const std::vector< std::string > &vColLabels)
set column labels
Definition: datasheet.h:77
void rowLabels(const std::vector< std::string > &vRowLabels)
set row labels
Definition: datasheet.h:58
void data(const std::vector< std::vector< std::string >> &vvdata)
set the data
Definition: datasheet.h:31
The base class for all windex gui elements.
Definition: wex.h:900
gui()
Construct top level window with no parent.
Definition: wex.h:907