Empirical
commands.h
Go to the documentation of this file.
1 
10 #ifndef EMP_WEB_COMMANDS_H
11 #define EMP_WEB_COMMANDS_H
12 
13 #include "Widget.h"
14 
15 namespace emp {
16 namespace web {
17 
20  class Close : public internal::WidgetCommand {
21  private:
22  std::string close_id;
23  public:
24  Close(const std::string & id) : close_id(id) { ; }
25 
26  bool Trigger(internal::WidgetInfo & w) const override {
27  if (w.id == close_id) { // Test if this is the element we need to close.
28  Widget(&w).PreventAppend();
29  return true;
30  }
31  return false;
32  }
33 
34  const std::string & GetID() const { return close_id; }
35  };
36 
39  private:
40  std::string str;
41  public:
42  PrintStr(const std::string & _s) : str(_s) { ; }
43 
44  bool Trigger(internal::WidgetInfo & w) const override {
45  w.Append(str);
46  return true;
47  }
48 
49  const std::string & GetStr() const { return str; }
50  };
51 
53  static const PrintStr endl("<br>");
54 
55 }
56 }
57 
58 #endif
Definition: Widget.h:206
std::string id
ID used for associated DOM element.
Definition: Widget.h:212
Definition: commands.h:20
Close(const std::string &id)
Definition: commands.h:24
PrintStr(const std::string &_s)
Definition: commands.h:42
const std::string & GetStr() const
Definition: commands.h:49
static const PrintStr endl("<br>")
Pre-define emp::endl to insert a "<br>" and thus acting like a newline.
void PreventAppend()
Disallow further appending to this Widget.
Definition: Widget.h:398
Widgets maintain individual components on a web page and link to Elements.
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
virtual Widget Append(const std::string &text)
Definition: Widget.h:287
Base class for command-objects that can be fed into widgets.
Definition: Widget.h:69
const std::string & GetID() const
Definition: commands.h:34
bool Trigger(internal::WidgetInfo &w) const override
Definition: commands.h:26
The PrintStr command will print a pre-specified string to a widget.
Definition: commands.h:38
bool Trigger(internal::WidgetInfo &w) const override
Definition: commands.h:44