package toffee

Build not yet checked
  1. Overview
  2. Docs
CSS layout engine for OCaml (Flexbox, Grid, Block)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

mosaic-0.3.0.tbz
sha256=a92cbbcbe016fb19fb0a749222da0e459a9567aef3f4c7340d9bd6b71c53ed6f
sha512=6a7ab054605538bb31a2b73a1a6d093981a2704c9f0af5852221c05735290d74aca7c7282298c4d0f91e86a800e2ccd94b4918af883cd963449c758eb6b272b3

doc/src/toffee.geometry/point.ml.html

Source file point.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
type 'a t = { x : 'a; y : 'a }

let none = { x = None; y = None }

(* Creation *)

let make x y = { x; y }

(* Mapping *)

let map f point = { x = f point.x; y = f point.y }
let map2 f p1 p2 = { x = f p1.x p2.x; y = f p1.y p2.y }

(* Axis accessors *)

let get axis point =
  match axis with
  | Abstract_axis.Inline -> point.x
  | Abstract_axis.Block -> point.y

let set axis value point =
  match axis with
  | Abstract_axis.Inline -> { point with x = value }
  | Abstract_axis.Block -> { point with y = value }

(* Transformations *)

let transpose point = { x = point.y; y = point.x }

(* Conversions *)

let to_size point = { Size.width = point.x; height = point.y }
let of_size size = { x = size.Size.width; y = size.Size.height }

(* Comparison and string functions *)

let compare cmp a b =
  let cmp_x = cmp a.x b.x in
  if cmp_x <> 0 then cmp_x else cmp a.y b.y

let equal eq a b = eq a.x b.x && eq a.y b.y

let to_string f point =
  Printf.sprintf "{ x: %s; y: %s }" (f point.x) (f point.y)

let pp f fmt point = Format.fprintf fmt "{ x: %a; y: %a }" f point.x f point.y