Empirical
Document.h
Go to the documentation of this file.
1 
22 #ifndef EMP_WEB_DOCUMENT_H
23 #define EMP_WEB_DOCUMENT_H
24 
25 #include "events.h"
26 
27 #include "Button.h"
28 #include "Canvas.h"
29 #include "Div.h"
30 #include "FileInput.h"
31 #include "Image.h"
32 #include "Selector.h"
33 #include "Table.h"
34 #include "Text.h"
35 #include "TextArea.h"
36 
37 #include "canvas_utils.h"
38 #include "color_map.h"
39 
40 namespace emp {
41 namespace web {
42 
43  class Document : public web::Div {
44  public:
45  Document(const std::string & doc_id) : web::Div(doc_id) { Activate(); }
46  ~Document() { ; }
47 
48  // Retrieve specific types of widgets.
49 
50  // Shortcut adders for Widgets
51  template <class... T> web::Button AddButton(T &&... args){
52  web::Button new_widget(std::forward<T>(args)...);
53  info->Append(new_widget);
54  return new_widget;
55  }
56  template <class... T> web::Canvas AddCanvas(T &&... args){
57  web::Canvas new_widget(std::forward<T>(args)...);
58  info->Append(new_widget);
59  return new_widget;
60  }
61  template <class... T> web::FileInput AddFileInput(T &&... args){
62  web::FileInput new_widget(std::forward<T>(args)...);
63  info->Append(new_widget);
64  return new_widget;
65  }
66  template <class... T> web::Image AddImage(T &&... args) {
67  web::Image new_widget(std::forward<T>(args)...);
68  info->Append(new_widget);
69  return new_widget;
70  }
71  template <class... T> web::Selector AddSelector(T &&... args){
72  web::Selector new_widget(std::forward<T>(args)...);
73  info->Append(new_widget);
74  return new_widget;
75  }
76  template <class... T> web::Div AddDiv(T &&... args) {
77  web::Div new_widget(std::forward<T>(args)...);
78  info->Append(new_widget);
79  return new_widget;
80  }
81  template <class... T> web::Table AddTable(T &&... args) {
82  web::Table new_widget(std::forward<T>(args)...);
83  info->Append(new_widget);
84  return new_widget;
85  }
86  template <class... T> web::Text AddText(T &&... args) {
87  web::Text new_widget(std::forward<T>(args)...);
88  info->Append(new_widget);
89  return new_widget;
90  }
91  template <class... T> web::TextArea AddTextArea(T &&... args) {
92  web::TextArea new_widget(std::forward<T>(args)...);
93  info->Append(new_widget);
94  return new_widget;
95  }
96 
97 
98  // Setup a quick way to retrieve old widgets by name.
99  web::Button Button (const std::string & in_id) { return web::Button(Find(in_id)); }
100  web::Canvas Canvas (const std::string & in_id) { return web::Canvas(Find(in_id)); }
101  web::FileInput FileInput (const std::string & in_id) { return web::FileInput(Find(in_id)); }
102  web::Image Image (const std::string & in_id) { return web::Image(Find(in_id)); }
103  web::Selector Selector (const std::string & in_id) { return web::Selector(Find(in_id)); }
104  web::Div Div (const std::string & in_id) { return web::Div(Find(in_id)); }
105  web::Table Table (const std::string & in_id) { return web::Table(Find(in_id)); }
106  web::Text Text (const std::string & in_id) { return web::Text(Find(in_id)); }
107  web::TextArea TextArea (const std::string & in_id) { return web::TextArea(Find(in_id)); }
108 
109  };
110 
111 }
112 }
113 
114 
115 #endif
A Text widget handles putting text on a web page that can be controlled and modified.
Definition: Text.h:27
Create/control an HTML button and call a specified function when that button is clicked.
web::Selector Selector(const std::string &in_id)
Definition: Document.h:103
web::Canvas AddCanvas(T &&...args)
Definition: Document.h:56
Document(const std::string &doc_id)
Definition: Document.h:45
Definition: Image.h:26
Specs for the Selector widget.
WidgetInfo * info
Information associated with this widget.
Definition: Widget.h:82
web::FileInput AddFileInput(T &&...args)
Definition: Document.h:61
Specs for the TextArea widget.
Definition: FileInput.h:32
web::Button AddButton(T &&...args)
Definition: Document.h:51
void Activate()
Make this widget live, so changes occur immediately (once document is ready)
Definition: Widget.h:494
Specs for the Text widget.
web::TextArea AddTextArea(T &&...args)
Definition: Document.h:91
web::Button Button(const std::string &in_id)
Definition: Document.h:99
web::Text AddText(T &&...args)
Definition: Document.h:86
web::Text Text(const std::string &in_id)
Definition: Document.h:106
Manage an HTML canvas object.
Easily load an image and place it in a document.
Event handlers that use JQuery.
A widget to track a div in an HTML file, and all of its contents.
Definition: Div.h:263
Tools to dynamically build (and cache) color maps.
~Document()
Definition: Document.h:46
Div Widgets maintain an ordered collection of other widgets in an HTML div.
Specs for the FileInput widget (click on to upload a file)
web::Canvas Canvas(const std::string &in_id)
Definition: Document.h:100
web::FileInput FileInput(const std::string &in_id)
Definition: Document.h:101
Widget & Find(const std::string &test_name)
Get an internal widget to this div, by the specified name.
Definition: Div.h:308
web::Table AddTable(T &&...args)
Definition: Document.h:81
web::Image AddImage(T &&...args)
Definition: Document.h:66
Definition: Document.h:43
Definition: TextArea.h:25
Manage an HTML Canvas object.
Definition: Canvas.h:27
web::Selector AddSelector(T &&...args)
Definition: Document.h:71
If we are in emscripten, make sure to include the header.
Definition: array.h:37
Create or control an HTML Button object that you can manipulate and update as needed.
Definition: Button.h:42
virtual Widget Append(const std::string &text)
Definition: Widget.h:287
Specs for the Table widget.
Definition: Selector.h:36
web::Div AddDiv(T &&...args)
Definition: Document.h:76
web::Div Div(const std::string &in_id)
Definition: Document.h:104
Definition: Table.h:638
web::Image Image(const std::string &in_id)
Definition: Document.h:102
web::Table Table(const std::string &in_id)
Definition: Document.h:105
web::TextArea TextArea(const std::string &in_id)
Definition: Document.h:107
Various versions of the Draw() function to draw images onto a canvas.