summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/static/dartboat.js24
-rw-r--r--web/web_opts.c19
2 files changed, 27 insertions, 16 deletions
diff --git a/web/static/dartboat.js b/web/static/dartboat.js
index 44daabb..4edba8a 100644
--- a/web/static/dartboat.js
+++ b/web/static/dartboat.js
@@ -37,6 +37,10 @@ function elemSetContent(sel, str) {
$(UTF8ToString(sel)).textContent = str ? UTF8ToString(str) : '';
}
+function elemSetValue(sel, str) {
+ $(UTF8ToString(sel)).value = str ? UTF8ToString(str) : '';
+}
+
function elemHasClass(sel, c) {
return $(UTF8ToString(sel)).classList.contains(UTF8ToString(c));
}
@@ -65,15 +69,6 @@ function elemScrollToBottom(sel) {
e.scrollTop = e.scrollHeight;
}
-function promptHandle(command, data) {
- const str_c = toCString(command);
- const str_d = data && toCString(data);
- _prompt_handle(str_c, str_d);
-
- _free(str_c);
- if (str_d) _free(str_d);
-}
-
function elemAppendElemv(sel, elemc, elemv, off_ns, off_name, off_content,
off_n_attrs, off_attr_names, off_attr_vals) {
const target = $(UTF8ToString(sel));
@@ -102,12 +97,13 @@ function elemAppendElemv(sel, elemc, elemv, off_ns, off_name, off_content,
}
}
-function updateDelay(val) {
- $('#delay').value = val;
-}
+function promptHandle(command, data) {
+ const str_c = toCString(command);
+ const str_d = data && toCString(data);
+ _prompt_handle(str_c, str_d);
-function updateStdev(val) {
- $('#stdev').value = parseFloat(val.toFixed(2).slice(0, 4));
+ _free(str_c);
+ if (str_d) _free(str_d);
}
function setOpt(opt, val, update_opts = true) {
diff --git a/web/web_opts.c b/web/web_opts.c
index 0f37bba..945909f 100644
--- a/web/web_opts.c
+++ b/web/web_opts.c
@@ -3,6 +3,8 @@
#include "comp.h"
#include <math.h>
+#include <stdio.h>
+#include <string.h>
#include <emscripten/emscripten.h>
@@ -11,8 +13,21 @@ int delay_ms = 1000;
void opts_init()
{
EM_ASM(readOpts());
- EM_ASM({updateDelay($0)}, delay_ms);
- EM_ASM({updateStdev($0)}, horizontal_stdev);
+
+ char buf[64];
+ sprintf(buf, "%d", delay_ms);
+ EM_ASM({elemSetValue($0, $1)}, "#delay", buf);
+
+ int len = sprintf(buf, "%4.2f", horizontal_stdev);
+ char *dot = strchr(buf, '.');
+ if (dot) {
+ for (char *ptr = buf + len - 1; ptr >= dot; --ptr) {
+ if (*ptr != '0' && *ptr != '.')
+ break;
+ *ptr = 0;
+ }
+ }
+ EM_ASM({elemSetValue($0, $1)}, "#stdev", buf);
}
EMSCRIPTEN_KEEPALIVE