Empirical
_TableColGroup.h
Go to the documentation of this file.
1 
12 #ifndef EMP_WEB_TABLE_COL_GROUP_H
13 #define EMP_WEB_TABLE_COL_GROUP_H
14 
15 namespace emp {
16 namespace web {
17 
19  class TableColGroup : public TableWidget {
20  public:
21  TableColGroup(size_t r, size_t c, const std::string & in_id="") : TableWidget(r,c,in_id) { ; }
22  TableColGroup(const TableWidget & in) : TableWidget(in) { ; }
23  TableColGroup(const Widget & in) : TableWidget(in) { ; }
24  TableColGroup(internal::TableInfo * in_info, size_t _col=0) : TableWidget(in_info, 0, _col) { ; }
25 
26  // Apply CSS to appropriate component based on current state.
27  void DoCSS(const std::string & setting, const std::string & value) override {
28  if (Info()->col_groups.size() == 0) Info()->col_groups.resize(GetNumCols());
29  Info()->col_groups[cur_col].extras.style.Set(setting, value);
30  if (IsActive()) Info()->ReplaceHTML(); // @CAO only should replace cell's CSS
31  }
32 
33  void DoAttr(const std::string & setting, const std::string & value) override {
34  if (Info()->col_groups.size() == 0) Info()->col_groups.resize(GetNumCols());
35  Info()->col_groups[cur_col].extras.attr.Set(setting, value);
36  if (IsActive()) Info()->ReplaceHTML(); // @CAO only should replace cell's CSS
37  }
38 
39  void DoListen(const std::string & event_name, size_t fun_id) override {
40  if (Info()->col_groups.size() == 0) Info()->col_groups.resize(GetNumCols());
41  Info()->col_groups[cur_col].extras.listen.Set(event_name, fun_id);
42  if (IsActive()) Info()->ReplaceHTML(); // @CAO only should replace cell's CSS
43  }
44 
45  TableColGroup & Clear() { Info()->ClearColGroup(cur_col); return *this; }
46  TableColGroup & ClearStyle() { Info()->col_groups[cur_col].extras.style.Clear(); return *this; }
47  TableColGroup & ClearAttr() { Info()->col_groups[cur_col].extras.attr.Clear(); return *this; }
48  TableColGroup & ClearListen() { Info()->col_groups[cur_col].extras.listen.Clear(); return *this; }
49  TableColGroup & ClearExtras() { Info()->col_groups[cur_col].extras.Clear(); return *this; }
51  TableColGroup & ClearCells() { Info()->ClearColGroup(cur_col); return *this; }
52 
53  std::string GetCSS(const std::string & setting) override {
54  return Info()->col_groups[cur_col].extras.GetStyle(setting);
55  }
56 
58  TableColGroup SetColSpan(size_t new_span) {
59  emp_assert((cur_col + new_span <= GetNumCols()) && "Col span too wide for table!",
60  cur_col, new_span, GetNumCols(), GetID());
61 
62  // If we haven't setup columns at all yet, do so.
63  if (Info()->col_groups.size() == 0) Info()->col_groups.resize(GetNumCols());
64 
65  const size_t old_span = Info()->col_groups[cur_col].span;
66  Info()->col_groups[cur_col].span = new_span;
67 
68  if (old_span != new_span) {
69  for (size_t i=old_span; i<new_span; i++) { Info()->col_groups[cur_col+i].masked = true; }
70  for (size_t i=new_span; i<old_span; i++) { Info()->col_groups[cur_col+i].masked = false; }
71  }
72 
73  // Redraw the entire table to fix col span information.
74  if (IsActive()) Info()->ReplaceHTML();
75 
76  return *this;
77  }
78 
80  TableColGroup SetSpan(size_t new_span) { SetColSpan(new_span); return *this; }
81  };
82 
83 }
84 }
85 
86 #endif
TableColGroup & ClearAttr()
Definition: _TableColGroup.h:47
bool IsActive() const
Test if the activity state of this widget is currently ACTIVE.
Definition: Widget.h:395
TableColGroup & ClearListen()
Definition: _TableColGroup.h:48
TableColGroup(const Widget &in)
Definition: _TableColGroup.h:23
TableColGroup & ClearStyle()
Definition: _TableColGroup.h:46
void DoAttr(const std::string &setting, const std::string &value) override
Definition: _TableColGroup.h:33
size_t cur_col
Definition: Table.h:517
void ClearColGroupChildren(size_t col_id)
Definition: Table.h:339
TableColGroup & Clear()
Definition: _TableColGroup.h:45
TableColGroup SetSpan(size_t new_span)
Since only number of columns is relevant, this function also sets the width of this column group...
Definition: _TableColGroup.h:80
An object that focuses on a group of columns in a specified table.
Definition: _TableColGroup.h:19
Definition: Table.h:513
const std::string & GetID() const
What is the HTML string ID for this Widget?
Definition: Widget.h:401
TableColGroup(const TableWidget &in)
Definition: _TableColGroup.h:22
emp::vector< TableGroupInfo > col_groups
Detail object for each column (if needed)
Definition: Table.h:115
void DoCSS(const std::string &setting, const std::string &value) override
Definition: _TableColGroup.h:27
void DoListen(const std::string &event_name, size_t fun_id) override
Definition: _TableColGroup.h:39
size_t GetNumCols() const
Definition: Table.h:561
internal::TableInfo * Info()
Get a properly cast version of info.
Definition: Table.h:522
If we are in emscripten, make sure to include the header.
Definition: array.h:37
TableColGroup & ClearChildren()
Definition: _TableColGroup.h:50
TableColGroup & ClearExtras()
Definition: _TableColGroup.h:49
Widget is effectively a smart pointer to a WidgetInfo object, plus some basic accessors.
Definition: Widget.h:78
std::string GetCSS(const std::string &setting) override
Definition: _TableColGroup.h:53
#define emp_assert(...)
Definition: assert.h:199
TableColGroup(internal::TableInfo *in_info, size_t _col=0)
Definition: _TableColGroup.h:24
TableColGroup(size_t r, size_t c, const std::string &in_id="")
Definition: _TableColGroup.h:21
Definition: Table.h:107
TableColGroup SetColSpan(size_t new_span)
Set the width of this column group.
Definition: _TableColGroup.h:58
void ReplaceHTML() override
Definition: Table.h:462
void ClearColGroup(size_t col_id)
Definition: Table.h:380
TableColGroup & ClearCells()
Definition: _TableColGroup.h:51