Empirical
WidgetExtras.h
Go to the documentation of this file.
1 
10 #ifndef EMP_WEB_WIDGET_EXTRA_H
11 #define EMP_WEB_WIDGET_EXTRA_H
12 
13 #include "Attributes.h"
14 #include "init.h"
15 #include "Listeners.h"
16 #include "Style.h"
17 
18 namespace emp {
19 namespace web {
20 
21  struct WidgetExtras {
25 
26  template <typename SET_TYPE>
27  void SetStyle(const std::string & s, SET_TYPE v) { style.Set(s, emp::to_string(v)); }
28  bool HasStyle(const std::string & setting) const { return style.Has(setting); }
29  const std::string & GetStyle(const std::string & setting) { return style.Get(setting); }
30  void RemoveStyle(const std::string & setting) { style.Remove(setting); }
31 
32  template <typename SET_TYPE>
33  void SetAttr(const std::string & s, SET_TYPE v) { attr.Set(s, emp::to_string(v)); }
34  bool HasAttr(const std::string & setting) const { return attr.Has(setting); }
35  const std::string & GetAttr(const std::string & setting) { return attr.Get(setting); }
36  void RemoveAttr(const std::string & setting) { attr.Remove(setting); }
37 
39  void Apply(const std::string & name) {
40  style.Apply(name);
41  attr.Apply(name);
42  listen.Apply(name);
43  }
44 
46  void Clear() {
47  style.Clear();
48  attr.Clear();
49  listen.Clear();
50  }
51 
53  operator bool() const { return style || attr || listen; } // Return true if any extras are set.
54  };
55 
56 }
57 }
58 
59 #endif
void Clear()
Remove all setting values.
Definition: Attributes.h:79
void Clear()
Remove all setting values.
Definition: Style.h:77
Attributes & Set(const std::string &s, SET_TYPE v)
Record that attribute "a" is set to value "v" (converted to string) and return this object...
Definition: Attributes.h:48
Define Initialize() and other functions to set up Empirical to build Emscripten projects.
std::string to_string(ALL_TYPES &&...all_values)
Definition: string_utils.h:511
const std::string & Get(const std::string &setting)
Definition: Attributes.h:65
Definition: Style.h:29
Maintains a map of attribute names to values for use in JavaScript Closely related to Style...
Definition: Attributes.h:29
Style & Set(const std::string &s, SET_TYPE v)
Record that setting "s" is set to value "v" (converted to string) and return this object...
Definition: Style.h:50
Track a set of JavaScript Listeners with their callback IDs.
Definition: Listeners.h:28
const std::string & Get(const std::string &setting)
Definition: Style.h:67
void RemoveAttr(const std::string &setting)
Definition: WidgetExtras.h:36
void Apply(const std::string &widget_id)
Apply ALL of the style settings to a specified widget.
Definition: Style.h:85
An Attributes class for tracking non-style features about HTML objects.
bool Has(const std::string &setting) const
Return true/false based on whether "setting" has been given a value in this Attributes obj...
Definition: Attributes.h:59
void Apply(const std::string &widget_id)
Apply all of the listeners being tracked.
Definition: Listeners.h:83
void Apply(const std::string &widget_id)
Apply ALL of the Attribute&#39;s settings to dom element "widget_id".
Definition: Attributes.h:82
bool HasAttr(const std::string &setting) const
Definition: WidgetExtras.h:34
void Clear()
Clear all of style, attributes, and listeners.
Definition: WidgetExtras.h:46
A class for tracking font event listeners for Widgets.
void SetStyle(const std::string &s, SET_TYPE v)
Definition: WidgetExtras.h:27
void SetAttr(const std::string &s, SET_TYPE v)
Definition: WidgetExtras.h:33
bool HasStyle(const std::string &setting) const
Definition: WidgetExtras.h:28
If we are in emscripten, make sure to include the header.
Definition: array.h:37
void Remove(const std::string &setting)
Definition: Attributes.h:74
Definition: WidgetExtras.h:21
void Apply(const std::string &name)
Apply all HTML details associated with this widget.
Definition: WidgetExtras.h:39
void Clear()
Remove all listeners.
Definition: Listeners.h:71
const std::string & GetAttr(const std::string &setting)
Definition: WidgetExtras.h:35
Attributes attr
HTML Attributes about a cell.
Definition: WidgetExtras.h:23
Style style
CSS Style.
Definition: WidgetExtras.h:22
A CSS class for tracking font style, etc.
Listeners listen
Listen for web events.
Definition: WidgetExtras.h:24
bool Has(const std::string &setting) const
Return true/false based on whether "setting" has been given a value in this Style.
Definition: Style.h:61
void RemoveStyle(const std::string &setting)
Definition: WidgetExtras.h:30
void Remove(const std::string &setting)
Remove a specific setting value.
Definition: Style.h:80
const std::string & GetStyle(const std::string &setting)
Definition: WidgetExtras.h:29