]> matita.cs.unibo.it Git - helm.git/blob - helm/www/lambdadelta/bin/xhtbl/matrix.ml
- we begin the new site based on ld_web
[helm.git] / helm / www / lambdadelta / bin / xhtbl / matrix.ml
1 module A = Array
2
3 module T = Table
4
5 type cell = {
6    ck: T.text list; (* contents *)
7    cc: T.css;       (* css classes *)
8    cb: T.border;    (* border *)
9 }
10
11 type matrix = {
12    r: int;              (* rows *)
13    c: int;              (* columns *)
14    m: cell array array; (* matrix *)
15 }
16
17 let empty = {
18    ck = []; cc = []; cb = T.border false;
19 }
20
21 let make ts = {
22    r = ts.T.rf; c = ts.T.cf;
23    m = A.make_matrix ts.T.rf ts.T.cf empty;
24 }
25
26 let set_key m y x kl = 
27    m.m.(y).(x) <- {m.m.(y).(x) with ck = kl}
28
29 let set_css m y x c = 
30    m.m.(y).(x) <- {m.m.(y).(x) with cc = c @ m.m.(y).(x).cc}
31
32 let set_west m y x b =
33    let c = m.m.(y).(x) in
34    let cb = {c.cb with T.w = c.cb.T.w || b.T.w} in 
35    m.m.(y).(x) <- {c with cb = cb}
36
37 let set_north m y x b =
38    let c = m.m.(y).(x) in
39    let cb = {c.cb with T.n = c.cb.T.n || b.T.n} in 
40    m.m.(y).(x) <- {c with cb = cb}
41
42 let set_east m y x b =
43    if x < pred m.c then set_west m y (succ x) {b with T.w = b.T.e} else
44    let c = m.m.(y).(x) in
45    let cb = {c.cb with T.e = c.cb.T.e || b.T.e} in 
46    m.m.(y).(x) <- {c with cb = cb}
47
48 let set_south m y x b =
49    if y < pred m.r then set_north m (succ y) x {b with T.n = b.T.s} else
50    let c = m.m.(y).(x) in
51    let cb = {c.cb with T.s = c.cb.T.s || b.T.s} in 
52    m.m.(y).(x) <- {c with cb = cb}