-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtoplevel_example.ml
46 lines (37 loc) · 1.39 KB
/
toplevel_example.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(* This file is part of BOGUE. *)
(*-------------------------------------------------------*)
(* How to make Bogue work in an OCaml toplevel (or REPL) *)
(*-------------------------------------------------------*)
(* This file can be sent directly to an OCaml toplevel *)
#thread;;
#require "bogue";;
open Bogue;;
module W = Widget;;
module L = Layout;;
(*-------------------------------------------------------*)
(* a simple check button *)
let b = W.check_box ();;
let layout = L.resident ~w:100 b;;
let board = Main.make [] [layout];;
Main.run board;;
(*-------------------------------------------------------*)
(*-------------------------------------------------------*)
(* a table with selectable rows *)
let list = [
["English"; "French"];
[ "hello"; "salut" ];
[ "bye bye"; "salut"];
[ "see you"; "à plus"];
[ "darn"; "zut"];
[ "holy cow"; "oh punaise"]];;
let table, sel = Table.of_list ~h:200 list;;
(* Let's preselect row#2 *)
Tvar.set sel (Selection.toggle (Tvar.get sel) 2);;
let layout = L.tower [L.resident (W.label "This is a nice table"); table];;
Main.(run (make [] [layout]));;
(* Here is what row numbers the user has selected *)
Selection.sprint (Tvar.get sel);;
(* And the corresponding rows *)
Selection.iter (fun i ->
String.concat ";" (List.nth list (i+1)) |> print_endline) (Tvar.get sel);;
(*-------------------------------------------------------*)