10 #ifndef EMP_WEB_ATTRIBUTES_H 11 #define EMP_WEB_ATTRIBUTES_H 15 #include <emscripten.h> 18 #include "../tools/string_utils.h" 31 std::map<std::string, std::string> settings;
39 int GetSize()
const {
return (
int) settings.size(); }
42 settings[in_set] = in_val;
47 template <
typename SET_TYPE>
54 settings.insert(in_attr.settings.begin(), in_attr.settings.end());
59 bool Has(
const std::string & setting)
const {
60 return settings.find(setting) != settings.end();
65 const std::string &
Get(
const std::string & setting) {
67 return settings[setting];
70 const std::map<std::string, std::string> &
GetMap()
const {
74 void Remove(
const std::string & setting) {
75 settings.erase(setting);
79 void Clear() { settings.clear(); }
82 void Apply(
const std::string & widget_id) {
84 if (settings.size() == 0)
return;
89 var
id = Pointer_stringify($0);
90 emp_i.cur_obj = $(
'#' + id );
91 }, widget_id.c_str());
94 for (
auto attr_pair : settings) {
95 if (attr_pair.second ==
"")
continue;
98 var name = Pointer_stringify($0);
99 var value = Pointer_stringify($1);
100 emp_i.cur_obj.attr( name, value);
101 }, attr_pair.first.c_str(), attr_pair.second.c_str());
103 std::cout <<
"Setting '" << widget_id <<
"' attribute '" << attr_pair.first
104 <<
"' to '" << attr_pair.second <<
"'.";
110 void Apply(
const std::string & widget_id,
const std::string & setting) {
115 var
id = Pointer_stringify($0);
116 var setting = Pointer_stringify($1);
117 var value = Pointer_stringify($2);
118 $(
'#' + id ).attr( setting, value);
119 }, widget_id.c_str(), setting.c_str(), settings[setting].c_str());
121 std::cout <<
"Setting '" << widget_id <<
"' attribute '" << setting
122 <<
"' to '" << settings[setting] <<
"'.";
127 static void Apply(
const std::string & widget_id,
const std::string & setting,
128 const std::string & value) {
131 var
id = Pointer_stringify($0);
132 var setting = Pointer_stringify($1);
133 var value = Pointer_stringify($2);
134 $(
'#' + id ).attr( setting, value);
135 }, widget_id.c_str(), setting.c_str(), value.c_str());
137 std::cout <<
"Setting '" << widget_id <<
"' attribute '" << setting
138 <<
"' to '" << value <<
"'.";
143 operator bool()
const {
return (
bool) settings.size(); }
void Clear()
Remove all setting values.
Definition: Attributes.h:79
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
Attributes()
Definition: Attributes.h:34
int GetSize() const
Return a count of the number of attributes that have been set.
Definition: Attributes.h:39
const std::map< std::string, std::string > & GetMap() const
Definition: Attributes.h:70
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
Attributes & operator=(const Attributes &)=default
Maintains a map of attribute names to values for use in JavaScript Closely related to Style...
Definition: Attributes.h:29
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
static void Apply(const std::string &widget_id, const std::string &setting, const std::string &value)
Apply onlay a SPECIFIC attributes setting with a specifid value!
Definition: Attributes.h:127
void Apply(const std::string &widget_id)
Apply ALL of the Attribute's settings to dom element "widget_id".
Definition: Attributes.h:82
Attributes & Insert(const Attributes &in_attr)
Set all values from in_attr here as well. Return this object.
Definition: Attributes.h:53
Attributes & DoSet(const std::string &in_set, const std::string &in_val)
Definition: Attributes.h:41
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
#define emp_assert(...)
Definition: assert.h:199
void Apply(const std::string &widget_id, const std::string &setting)
Apply onlay a SPECIFIC attributes setting from the setting library to widget_id.
Definition: Attributes.h:110