(\* Function that, given a parameter called "constraints" representing width and height and (x, y) position, will call the record's draw function. *)
let rec draw constraints drawable =
match drawable with
| Empty -> empty_case
| Widget { f_draw; _ } | Align { f_draw; _ } -> f_draw constraints
| Flex { flex_fit; child; _ } ->
let child_constraints = apply_flex constraints flex_fit in
draw child_constraints child
(* Function to draw a sized box, meaning that any child can be no longer than this. *)
let draw_sized_box width height child constraints =
let child_constraints = clip_width_and_height width height constraints in
draw child_constraints child
(* Implements Widget case for sized_box. *)
let sized_box width height child =
Widget { f_draw = draw_sized_box width height child; ... }
(* Function to draw a margin, meaning that the constraints are decreased by the four direction parameters. *)
let draw_margin left top right bottom child constraints =
let child_constraints = decrease_constraints left top right bottom constraints in
draw child_constraints child
(* Implements Widget case for margin. *)
let margin left top right bottom child =
Widget { f_draw: draw_margin left top right bottom child; ... }
(* View which can have arbitrarily nested widgets. *)
let view =
margin 0 1 0 1 (sized_box 100 300 (empty))
(* Call draw function on view. \*)
draw (get_default_constraints()) view