10 #ifndef EMP_EM_FUNCTIONS_H 11 #define EMP_EM_FUNCTIONS_H 15 #include "../tools/alert.h" 16 #include "../tools/string_utils.h" 21 #define AlertVar(VAR) emp::Alert(std::string(#VAR) + std::string("=") + std::to_string(VAR)) 24 static void DelayCall(
const std::function<
void()> & in_fun,
int delay) {
25 uint32_t callback_id = JSWrapOnce(in_fun);
28 window.setTimeout(
function() {
emp.Callback($0); }, $1);
29 }, callback_id, delay);
33 static void OnResize(
const std::function<
void()> & in_fun) {
34 uint32_t callback_id = JSWrap(in_fun);
37 window.addEventListener(
"resize",
function() {
emp.Callback($0); });
42 static void OnResize(
const std::function<
void(
int,
int)> & in_fun) {
43 uint32_t callback_id = JSWrap(in_fun);
46 window.addEventListener(
"resize",
function() {
47 emp.Callback($0, window.innerWidth, window.innerHeight);
53 inline double GetTime() {
return EM_ASM_DOUBLE_V({
return (
new Date()).getTime(); }); }
64 var color = Pointer_stringify($0);
65 $(
"body").first().css(
"background-color", color);
69 static void SetColor(
const std::string color) {
71 var color = Pointer_stringify($0);
72 $(
"body").first().css(
"color", color);
79 var type = Pointer_stringify($0);
80 document.body.style.cursor = type;
86 var url = Pointer_stringify($0);
92 static std::string
text2html(
const std::string & text) {
93 std::stringstream html;
96 case '<': html <<
"<";
break;
97 case '>': html <<
">";
break;
98 case '&': html <<
"&";
break;
99 case ' ': html <<
" ";
break;
100 case '\n': html <<
"<br>";
break;
double GetTime()
Get the current time, as provided by the web browser.
Definition: emfunctions.h:53
static void DelayCall(const std::function< void()> &in_fun, int delay)
Call a function after a specified amount of time.
Definition: emfunctions.h:24
static std::string text2html(const std::string &text)
Definition: emfunctions.h:92
int GetWindowInnerHeight()
Determine with height of the current window.
Definition: emfunctions.h:59
static void OnResize(const std::function< void()> &in_fun)
Provide a function to call whenever a window's size changes (no arguments).
Definition: emfunctions.h:33
static void SetBackgroundColor(const std::string color)
Set the background color of this web page.
Definition: emfunctions.h:62
Wrap a C++ function and convert it to an integer that can be called from Javascript.
If we are in emscripten, make sure to include the header.
Definition: array.h:37
static void SetColor(const std::string color)
Definition: emfunctions.h:69
static void OpenWindow(const std::string &url)
Definition: emfunctions.h:84
static void SetCursor(const char *type)
Definition: emfunctions.h:77
int GetWindowInnerWidth()
Determine with width of the current window.
Definition: emfunctions.h:56