package toffee
Build not yet checked sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
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.style/length_percentage.ml.html
Source file length_percentage.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 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 126type t = Compact_length.t (* Constructors *) let length value = Compact_length.length value let percent value = Compact_length.percent value let calc index = Compact_length.calc index let px value = length value let pct value = percent (value /. 100.0) (* Constants *) let zero = Compact_length.zero (* Inspection *) let is_length t = Compact_length.is_length t let is_percent t = Compact_length.is_percent t let is_calc t = Compact_length.is_calc t (* Value extraction *) let value t = Compact_length.value t (* Conversion/Resolution *) let resolve t context = if is_length t then value t else if is_percent t then (* Emulate f32 arithmetic to match Taffy's behavior *) let result = context *. value t in (* Round to f32 precision *) Int32.float_of_bits (Int32.bits_of_float result) else failwith "Length_percentage.resolve: calc requires resolve_with_calc; intrinsic \ values are unsupported" let resolve_with_calc t context calc_resolver = if is_length t then value t else if is_percent t then (* Emulate f32 arithmetic to match Taffy's behavior *) let result = context *. value t in (* Round to f32 precision *) Int32.float_of_bits (Int32.bits_of_float result) else if is_calc t then calc_resolver (Compact_length.get_calc_index t) context else failwith "Length_percentage.resolve_with_calc: unsupported tag (expected \ length/percent/calc)" (* Pretty printing *) let to_string = Compact_length.to_string (* Comparison *) let equal = Compact_length.equal let compare = Compact_length.compare let pp = Compact_length.pp (* Additional helpers *) let uses_percentage t = Compact_length.uses_percentage t let resolved_percentage_size t parent_size = Compact_length.resolved_percentage_size t parent_size let resolved_percentage_size_with_calc t parent_size calc_resolver = Compact_length.resolved_percentage_size_with_calc t parent_size calc_resolver (* Resolve functions from Taffy's resolve.rs *) let maybe_resolve t context calc_resolver = if is_length t then Some (value t) else if is_percent t then match context with | None -> None | Some dim -> (* Emulate f32 arithmetic to match Taffy's behavior *) let result = dim *. value t in (* Round to f32 precision *) Some (Int32.float_of_bits (Int32.bits_of_float result)) else if is_calc t then match context with | None -> None | Some dim -> Some (calc_resolver (Compact_length.get_calc_index t) dim) else failwith "Length_percentage.maybe_resolve: unsupported tag (expected \ length/percent/calc)" (* [maybe_resolve], with 0 for [None], and without its option: layout resolves every padding and border side of every node with it. *) let resolve_or_zero t context calc_resolver = if is_length t then value t else if is_percent t then match context with | None -> 0.0 | Some dim -> (* Emulate f32 arithmetic to match Taffy's behavior *) Int32.float_of_bits (Int32.bits_of_float (dim *. value t)) else if is_calc t then match context with | None -> 0.0 | Some dim -> calc_resolver (Compact_length.get_calc_index t) dim else failwith "Length_percentage.resolve_or_zero: unsupported tag (expected \ length/percent/calc)" (* Every padding, border and margin of every node a layout visits is resolved, and nearly all are zero: those resolve to the one zero rect. *) let resolve_rect_or_zero context calc_resolver (rect : t Toffee_geometry.Rect.t) = let zero = Compact_length.is_zero in if zero rect.left && zero rect.right && zero rect.top && zero rect.bottom then Toffee_geometry.Rectf.zero else let side t = resolve_or_zero t context calc_resolver in { Toffee_geometry.Rectf.left = side rect.left; right = side rect.right; top = side rect.top; bottom = side rect.bottom; }
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>