diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-03 21:25:44 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-03 21:25:44 -0700 |
commit | 1ab3c4995e44f44a845dce7b241554c0621527b9 (patch) | |
tree | af02db07c5873f893b1506d224ac78c1fd2fefbd /web/web_opts.c | |
parent | e091cdb3187b60a9901bd14d475eebc481c9a299 (diff) | |
download | dartboat-1ab3c4995e44f44a845dce7b241554c0621527b9.tar.gz dartboat-1ab3c4995e44f44a845dce7b241554c0621527b9.tar.xz |
web: use generic JS function for updating opt elems
Diffstat (limited to 'web/web_opts.c')
-rw-r--r-- | web/web_opts.c | 19 |
1 files changed, 17 insertions, 2 deletions
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 |