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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
module Layout = B_layout
module Avar = B_avar
module Sync = B_sync
open B_utils
let push_avar room action =
let update _ _ = action (); 0 in
let avar = Avar.create ~duration:0 ~update 0 in
Layout.animate_w room avar
let push _ = Sync.push
let split_at test list =
let rec loop before = function
| [] -> failwith "split_at: no matching element was not found in the list."
| a::rest -> if test a
then List.rev before, rest
else loop (a::before) rest in
loop [] list
let make_hfill_sync ?right_margin layout =
let open Layout in
let rooms = siblings layout in
List.iter resize_fix_x rooms;
let before,after = split_at (equal layout) rooms in
let bx,_,bw,_ = bounding_geometry before in
let ax,_,aw,_ = bounding_geometry after in
let initial_width = width layout in
let margin_left = getx layout - bx - bw in
let margin_right = ax - getx layout - width layout in
let right_margin = default right_margin
(if before = [] then margin_left else bx) in
let old_resize = layout.resize in
let resize (w,h) =
let keep_resize = true in
let available_width = w - aw - bw - bx
- margin_left - margin_right - right_margin
|> imax initial_width in
let offset = available_width - width layout in
old_resize (w,h);
set_width ~keep_resize layout available_width;
List.iter (fun r ->
setx ~keep_resize r (getx r + offset)) after in
layout.resize <- resize
let make_hfill ?right_margin layout =
push layout (fun () ->
make_hfill_sync ?right_margin layout;
Layout.resize layout)
let hfill ?right_margin () =
let l = Layout.empty ~w:0 ~h:0 ~name:"hfill-space" () in
make_hfill ?right_margin l;
l
let make_vfill_sync ?bottom_margin layout =
let open Layout in
let rooms = siblings layout in
List.iter resize_fix_y rooms;
let before,after = split_at (equal layout) rooms in
let _,by,_,bh = bounding_geometry before in
let _,ay,_,ah = bounding_geometry after in
let initial_height = height layout in
let margin_top = gety layout - by - bh in
let margin_bottom = ay - gety layout - height layout in
let bottom_margin = default bottom_margin
(if before = [] then margin_top else by) in
let resize (_w,h) =
let keep_resize = true in
let available_height = h - ah - bh - by
- margin_top - margin_bottom - bottom_margin
|> imax initial_height in
let offset = available_height - height layout in
set_height ~keep_resize layout available_height;
List.iter (fun r ->
sety ~keep_resize r (gety r + offset)) after in
layout.resize <- resize
let make_vfill ?bottom_margin layout =
push layout (fun () ->
make_vfill_sync ?bottom_margin layout;
Layout.resize layout)
let vfill ?bottom_margin () =
let l = Layout.empty ~w:0 ~h:0 ~name:"vfill-space" () in
make_vfill ?bottom_margin l;
l
let full_width_sync ?right_margin ?left_margin layout =
let open Layout in
let left_margin = default_lazy left_margin (lazy (getx layout)) in
let right_margin = default right_margin left_margin in
resize_fix_x layout;
let f = layout.resize in
let resize (w,h) =
let keep_resize = true in
f (w,h);
setx ~keep_resize layout left_margin;
set_width ~keep_resize layout (w - left_margin - right_margin) in
layout.resize <- resize
let full_width ?right_margin ?left_margin layout =
push layout (fun () ->
full_width_sync ?right_margin ?left_margin layout;
Layout.resize layout)
let full_height_sync ?top_margin ?bottom_margin layout =
let open Layout in
let top_margin = default_lazy top_margin (lazy (gety layout)) in
let bottom_margin = default bottom_margin top_margin in
resize_fix_y layout;
let f = layout.resize in
let resize (w,h) =
let keep_resize = true in
f (w,h);
sety ~keep_resize layout top_margin;
set_height ~keep_resize layout (h - top_margin - bottom_margin) in
layout.resize <- resize
let full_height ?top_margin ?bottom_margin layout =
push layout (fun () ->
full_height_sync ?top_margin ?bottom_margin layout;
Layout.resize layout)
let keep_bottom_sync ~reset_scaling ?margin layout =
let open Layout in
match layout.house with
| None -> printd (debug_board + debug_error)
"Cannot apply [keep_bottom_sync] to room %s because it has no \
house."
(sprint_id layout)
| Some house ->
let bottom = default_lazy margin
(lazy (height house - gety layout - height layout)) in
let f = layout.resize in
let resize (w,h) =
let keep_resize = true in
if not reset_scaling then f (w,h);
sety ~keep_resize layout (h - height layout - bottom) in
layout.resize <- resize
let keep_bottom ?(reset_scaling = false) ?margin layout =
push layout (fun () ->
keep_bottom_sync ~reset_scaling ?margin layout;
Layout.resize layout)
let keep_right_sync ~reset_scaling ?margin layout =
let open Layout in
match layout.house with
| None -> printd (debug_board + debug_error)
"Cannot apply [keep_right_sync] to room %s because it has no house."
(sprint_id layout)
| Some house ->
let right = default_lazy margin
(lazy (width house - getx layout - width layout)) in
let f = layout.resize in
let resize (w,h) =
let keep_resize = true in
if not reset_scaling then f (w,h);
setx ~keep_resize layout (w - width layout - right) in
layout.resize <- resize
let keep_right ?(reset_scaling = false) ?margin layout =
push layout (fun () ->
keep_right_sync ~reset_scaling ?margin layout;
Layout.resize layout)