Empirical
_TableRowGroup.h
Go to the documentation of this file.
1 
12 #ifndef EMP_WEB_TABLE_ROW_GROUP_H
13 #define EMP_WEB_TABLE_ROW_GROUP_H
14 
15 namespace emp {
16 namespace web {
17 
19  class TableRowGroup : public TableWidget {
20  public:
21  TableRowGroup(size_t r, size_t c, const std::string & in_id="") : TableWidget(r,c,in_id) { ; }
22  TableRowGroup(const TableWidget & in) : TableWidget(in) { ; }
23  TableRowGroup(const Widget & in) : TableWidget(in) { ; }
24  TableRowGroup(internal::TableInfo * in_info, size_t _row=0) : TableWidget(in_info, _row, 0) { ; }
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()->row_groups.size() == 0) Info()->row_groups.resize(GetNumRows());
29  Info()->row_groups[cur_row].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()->row_groups.size() == 0) Info()->row_groups.resize(GetNumRows());
35  Info()->row_groups[cur_row].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()->row_groups.size() == 0) Info()->row_groups.resize(GetNumRows());
41  Info()->row_groups[cur_row].extras.listen.Set(event_name, fun_id);
42  if (IsActive()) Info()->ReplaceHTML(); // @CAO only should replace cell's CSS
43  }
44 
45  TableRowGroup & Clear() { Info()->ClearRowGroup(cur_row); return *this; }
46  TableRowGroup & ClearStyle() { Info()->row_groups[cur_row].extras.style.Clear(); return *this; }
47  TableRowGroup & ClearAttr() { Info()->row_groups[cur_row].extras.attr.Clear(); return *this; }
48  TableRowGroup & ClearListen() { Info()->row_groups[cur_row].extras.listen.Clear(); return *this; }
49  TableRowGroup & ClearExtras() { Info()->row_groups[cur_row].extras.Clear(); return *this; }
51  TableRowGroup & ClearCells() { Info()->ClearRowGroup(cur_row); return *this; }
52 
53  std::string GetCSS(const std::string & setting) override {
54  return Info()->row_groups[cur_row].extras.GetStyle(setting);
55  }
56 
57  TableRowGroup & SetRowSpan(size_t new_span) {
58  emp_assert((cur_row + new_span <= GetNumRows()) && "Row span too wide for table!");
59 
60  // If we haven't setup rows at all yet, do so.
61  if (Info()->row_groups.size() == 0) Info()->row_groups.resize(GetNumRows());
62 
63  const size_t old_span = Info()->row_groups[cur_row].span;
64  Info()->row_groups[cur_row].span = new_span;
65 
66  if (old_span != new_span) {
67  for (size_t i=old_span; i<new_span; i++) { Info()->row_groups[cur_row+i].masked = true; }
68  for (size_t i=new_span; i<old_span; i++) { Info()->row_groups[cur_row+i].masked = false; }
69  }
70 
71  // Redraw the entire table to fix row span information.
72  if (IsActive()) Info()->ReplaceHTML();
73 
74  return *this;
75  }
76 
77  TableRowGroup SetSpan(size_t new_span) { SetRowSpan(new_span); return *this; }
78  };
79 
80 }
81 }
82 
83 #endif
TableRowGroup(internal::TableInfo *in_info, size_t _row=0)
Definition: _TableRowGroup.h:24
TableRowGroup(size_t r, size_t c, const std::string &in_id="")
Definition: _TableRowGroup.h:21
bool IsActive() const
Test if the activity state of this widget is currently ACTIVE.
Definition: Widget.h:395
TableRowGroup & ClearExtras()
Definition: _TableRowGroup.h:49
void DoCSS(const std::string &setting, const std::string &value) override
Definition: _TableRowGroup.h:27
void DoAttr(const std::string &setting, const std::string &value) override
Definition: _TableRowGroup.h:33
void ClearRowGroup(size_t row_id)
Definition: Table.h:376
std::string GetCSS(const std::string &setting) override
Definition: _TableRowGroup.h:53
Definition: Table.h:513
TableRowGroup SetSpan(size_t new_span)
Definition: _TableRowGroup.h:77
TableRowGroup & Clear()
Definition: _TableRowGroup.h:45
void DoListen(const std::string &event_name, size_t fun_id) override
Definition: _TableRowGroup.h:39
TableRowGroup & ClearListen()
Definition: _TableRowGroup.h:48
TableRowGroup & SetRowSpan(size_t new_span)
Definition: _TableRowGroup.h:57
TableRowGroup & ClearChildren()
Definition: _TableRowGroup.h:50
TableRowGroup(const Widget &in)
Definition: _TableRowGroup.h:23
An object that focuses on a group of rows in a specified table.
Definition: _TableRowGroup.h:19
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
Widget is effectively a smart pointer to a WidgetInfo object, plus some basic accessors.
Definition: Widget.h:78
#define emp_assert(...)
Definition: assert.h:199
emp::vector< TableGroupInfo > row_groups
Detail object for each column group (if needed)
Definition: Table.h:116
TableRowGroup & ClearCells()
Definition: _TableRowGroup.h:51
TableRowGroup & ClearStyle()
Definition: _TableRowGroup.h:46
TableRowGroup & ClearAttr()
Definition: _TableRowGroup.h:47
Definition: Table.h:107
size_t cur_row
Definition: Table.h:516
void ClearRowGroupChildren(size_t row_id)
Definition: Table.h:334
void ReplaceHTML() override
Definition: Table.h:462
size_t GetNumRows() const
Definition: Table.h:562
TableRowGroup(const TableWidget &in)
Definition: _TableRowGroup.h:22