PageRenderTime 13ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/src/visualiser/spinner.ml

http://github.com/hhughes/ocaml-frui
OCaml | 40 lines | 38 code | 2 blank | 0 comment | 0 complexity | 619ad6f4a7ba7846bfe862fe71b836fc MD5 | raw file
 1type button_type = Up | Down
 2
 3let create_button (e : Dom.element) (input : Dom.input) ty set_input =
 4  let button = (Dom.document#createElement "button" : Dom.button) in
 5  let set_value i _ =
 6    let v = int_of_string input#_get_value in
 7    input#_set_value (string_of_int (v + i));
 8    set_input ();
 9    true
10  in
11  ignore (e#appendChild button);
12  match ty with
13    | Up ->
14      button#_set_className "up";
15      let button_text = (Dom.document#createTextNode "^" : Dom.text) in
16      ignore (button#appendChild button_text);
17      button#_set_onclick (set_value 1)
18    | Down ->
19      button#_set_className "down";
20      let button_text = (Dom.document#createTextNode "v" : Dom.text) in
21      ignore (button#appendChild button_text);
22      button#_set_onclick (set_value (-1))
23
24let create e v =
25  let input = (Dom.document#createElement "input" : Dom.input) in
26  let set_input () =
27    let i = int_of_string input#_get_value in
28    v#set (float_of_int i)
29  in
30  let set_value i =
31    let x = int_of_float i in
32    input#_set_value (string_of_int x)
33  in
34  input#_set_value (string_of_int (int_of_float v#get));
35  input#_set_onchange set_input;
36  input#_set_className "spinner";
37  create_button e input Up set_input;
38  create_button e input Down set_input;
39  ignore (Froc.lift set_value v#b);
40  ignore (e#appendChild input)