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.tree/scrollable_overflow.ml.html

Source file scrollable_overflow.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
47
48
49
50
51
module Rectf = Toffee_geometry.Rectf

(* The rectangle with its right and bottom edges carrying, in their sign,
   whether the scroll origin is reversed in that axis: the rectangle contains
   the origin, so the edges' magnitudes are never negative. *)
type t = Rectf.t

let zero = Rectf.zero

let make (rect : Rectf.t) ~reversed_x ~reversed_y =
  if
    Bool.equal (Float.sign_bit rect.right) reversed_x
    && Bool.equal (Float.sign_bit rect.bottom) reversed_y
  then rect
  else
    {
      rect with
      right = Float.copy_sign rect.right (if reversed_x then -1.0 else 1.0);
      bottom = Float.copy_sign rect.bottom (if reversed_y then -1.0 else 1.0);
    }

let left (t : t) = t.left [@@inline]
let right (t : t) = Float.abs t.right [@@inline]
let top (t : t) = t.top [@@inline]
let bottom (t : t) = Float.abs t.bottom [@@inline]
let reversed_x (t : t) = Float.sign_bit t.right [@@inline]
let reversed_y (t : t) = Float.sign_bit t.bottom [@@inline]
let packed (t : t) : Rectf.t = t

let rect (t : t) : Rectf.t =
  if Float.sign_bit t.right || Float.sign_bit t.bottom then
    { t with right = Float.abs t.right; bottom = Float.abs t.bottom }
  else t

let equal (a : t) (b : t) =
  Rectf.equal a b
  && Bool.equal (reversed_x a) (reversed_x b)
  && Bool.equal (reversed_y a) (reversed_y b)

let compare (a : t) (b : t) =
  let c = Rectf.compare (rect a) (rect b) in
  if c <> 0 then c
  else
    let c = Bool.compare (reversed_x a) (reversed_x b) in
    if c <> 0 then c else Bool.compare (reversed_y a) (reversed_y b)

let to_string t =
  Printf.sprintf "%s%s%s"
    (Rectf.to_string (rect t))
    (if reversed_x t then " reversed-x" else "")
    (if reversed_y t then " reversed-y" else "")