60 std::map<std::string, web::Animate *>
anim_map;
63 : internal::
WidgetInfo(in_id), scroll_top(0.0), append_ok(true), text_append(false)
64 , widget_dict(), anim_map()
71 for (
auto & p : anim_map)
delete p.second;
74 std::string
TypeName()
const override {
return "DivInfo"; }
76 virtual bool IsDivInfo()
const override {
return true; }
80 return (widget_dict.find(test_name) != widget_dict.end());
85 return widget_dict[find_name];
90 widget_dict[new_widget.
GetID()] = new_widget;
106 widget_dict.erase(old_widget.
GetID());
113 old_widget->
parent =
nullptr;
124 m_children.resize(0);
136 emp_assert(in->
parent ==
nullptr &&
"Cannot insert widget if already has parent!", in->
id);
148 parent_id = Pointer_stringify($0);
149 child_id = Pointer_stringify($1);
150 $(
'#' + parent_id).append(
'<span id="' + child_id +
'"></span>');
151 },
id.c_str(), in.
GetID().c_str());
159 for (
auto & child : m_children) child->DoActivate(
false);
168 if (m_children.
size() == 0
169 || m_children.
back().IsText() ==
false 170 || m_children.
back().AppendOK() ==
false 171 || text_append ==
false) {
209 virtual void GetHTML(std::stringstream & HTML)
override {
213 HTML <<
"<div id=\'" <<
id <<
"\'>";
214 for (
Widget & w : m_children) {
215 HTML <<
"<span id=\'" << w.GetID() <<
"'></span>";
227 for (
auto & child : m_children) child->ReplaceHTML();
230 if (scroll_top >= 0.0) {
232 var div_id = Pointer_stringify($0);
233 var div_obj = document.getElementById(div_id);
234 if (div_obj == null) alert(div_id);
237 var scroll_top = $1 * div_obj.scrollHeight;
258 virtual std::string
GetType()
override {
return "web::DivInfo"; }
270 Div(
const std::string & in_name) : WidgetFacet(in_name) {
274 Div(
const Div & in) : WidgetFacet(in) { ; }
295 if (!info)
return false;
310 return Info()->GetRegistered(test_name);
320 Info()->anim_map[name] = new_anim;
A Text widget handles putting text on a web page that can be controlled and modified.
Definition: Text.h:27
void ClearChildren()
Remove all child widgets from this div.
Definition: Div.h:291
void ReplaceHTML() override
Definition: Div.h:221
DivInfo(const std::string &in_id="")
Definition: Div.h:62
~Div()
Definition: Div.h:277
void UnregisterChildren(DivInfo *regestrar) override
Definition: Div.h:117
Define Initialize() and other functions to set up Empirical to build Emscripten projects.
void ClearChildren()
Definition: Div.h:121
void Unregister(Widget &old_widget) override
Definition: Div.h:110
emp::vector< Widget > m_children
Widgets contained in this one.
Definition: Div.h:56
Widget & GetRegistered(const std::string &find_name)
Definition: Div.h:83
std::map< std::string, web::Animate * > anim_map
Streamline creation of Animate objects.
Definition: Div.h:60
bool text_append
Can we append to a current text widget?
Definition: Div.h:58
Include information (name, keyword, description) for each instance.
Manage animations on a web site.
Widget Append(const std::function< std::string()> &in_fun) override
Definition: Div.h:186
Specs for the Text widget.
emp::vector< Widget > & Children()
Get all direct child widgets to this div.
Definition: Div.h:314
Div(const Widget &in)
Definition: Div.h:275
Div(const Div &in)
Definition: Div.h:274
internal::DivInfo * Info()
Definition: Div.h:266
An object that, when active, repeatedly calls a function as fast as possible, to a maximum of 60 fram...
Definition: Animate.h:62
double ScrollTop() const
Where is the top of the scroll region?
Definition: Div.h:282
Div()
Definition: Div.h:276
Div & ScrollTop(double in_top)
Set the scroll position.
Definition: Div.h:285
bool AppendOK() const override
Definition: Div.h:178
static bool Initialize()
Stub for when Emscripten is not in use.
Definition: init.h:98
double scroll_top
Where should div scroll to? (0.0 to 1.0)
Definition: Div.h:55
size_t size() const
Definition: vector.h:151
void emplace_back(ARGS &&...args)
Definition: vector.h:219
void PreventAppend() override
Definition: Div.h:179
web::Text & GetTextWidget()
Definition: Div.h:166
Widget Append(const std::string &text) override
Definition: Div.h:182
virtual bool IsDivInfo() const override
Definition: Div.h:76
Widget Append(Widget info) override
Definition: Div.h:191
Div(const std::string &in_name)
Definition: Div.h:270
virtual void GetHTML(std::stringstream &HTML) override
Definition: Div.h:209
A widget to track a div in an HTML file, and all of its contents.
Definition: Div.h:263
const internal::DivInfo * Info() const
Definition: Div.h:267
std::string TypeName() const override
Debugging helpers...
Definition: Div.h:74
virtual std::string GetType() override
Definition: Div.h:258
virtual ~DivInfo()
Definition: Div.h:70
Widget & Find(const std::string &test_name)
Get an internal widget to this div, by the specified name.
Definition: Div.h:308
bool IsRegistered(const std::string &test_name) const
Definition: Div.h:79
Widget Append(const Font &font) override
Start a new set of Text with this font (even if one already exists.)
Definition: Div.h:199
void DoActivate(bool top_level=true) override
Definition: Div.h:158
web::Animate & AddAnimation(const std::string &name, T &&...args)
Shortcut adder for animations.
Definition: Div.h:317
bool append_ok
Can we add more children?
Definition: Div.h:57
void Unregister_recurse(Widget &old_widget) override
Definition: Div.h:104
If we are in emscripten, make sure to include the header.
Definition: array.h:37
std::map< std::string, Widget > widget_dict
By-name lookup for descendent widgets.
Definition: Div.h:59
Build a debug wrapper emp::vector around std::vector.
Definition: vector.h:42
DivInfo & operator=(const DivInfo &)=delete
#define emp_assert(...)
Definition: assert.h:199
T & back()
Definition: vector.h:183
void Deactivate(bool top_level) override
Remove this widget from the current document.
Definition: Div.h:301
void AddChild(Widget in)
Definition: Div.h:134
void Register(Widget &new_widget) override
Definition: Div.h:95
void Register_recurse(Widget &new_widget) override
Definition: Div.h:88
void RegisterChildren(DivInfo *regestrar) override
Definition: Div.h:100
Maintain information about an HTML font.
Definition: Font.h:24
web::Animate & Animate(const std::string &in_id)
Definition: Div.h:325
void Clear()
Definition: Div.h:128
void Clear()
Clear the contents of this div.
Definition: Div.h:288
bool HasChild(const Widget &test_child) const
Determine if a specified widget is internal to this one.
Definition: Div.h:294