PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/src/graph/spinner.ml

http://github.com/hhughes/ocaml-frui
OCaml | 39 lines | 37 code | 2 blank | 0 comment | 0 complexity | 8571a19abe098d1382f067cbbe7d2ff3 MD5 | raw file
 1type button_type = Up | Down
 2
 3let create_button (e : Dom.element) (input : Dom.input) ty set_input inc =
 4  let button = (Dom.document#createElement "button" : Dom.button) in
 5  let set_value i _ =
 6    let v = float_of_string input#_get_value in
 7    input#_set_value (string_of_float (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 inc)
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. *. inc))
23
24let create e v inc =
25  let input = (Dom.document#createElement "input" : Dom.input) in
26  let set_input () =
27    let i = float_of_string input#_get_value in
28    v#set i
29  in
30  let set_value i =
31    input#_set_value (string_of_float i)
32  in
33  input#_set_value (string_of_float v#get);
34  input#_set_onchange set_input;
35  input#_set_className "spinner";
36  create_button e input Up set_input inc;
37  create_button e input Down set_input inc;
38  ignore (Froc.lift set_value v#b);
39  ignore (e#appendChild input)