0 | ||| Types and utilities for laying out components in a grid.
  1 | module Text.CSS.Grid
  2 |
  3 | import Data.List
  4 | import Text.CSS.Length
  5 | import Text.CSS.Percentage
  6 |
  7 | --------------------------------------------------------------------------------
  8 | --          Flex Values
  9 | --------------------------------------------------------------------------------
 10 |
 11 | public export
 12 | record Flex where
 13 |   constructor MkFlex
 14 |   value : Bits16
 15 |
 16 | export %inline
 17 | fr : Cast Flex a => Bits16 -> a
 18 | fr = cast . MkFlex
 19 |
 20 | export %inline
 21 | (.fr) : Cast Flex a => Bits16 -> a
 22 | (.fr) = fr
 23 |
 24 | export
 25 | Interpolation Flex where
 26 |   interpolate f = "\{show f.value}fr"
 27 |
 28 | --------------------------------------------------------------------------------
 29 | --          MinMax Values
 30 | --------------------------------------------------------------------------------
 31 |
 32 | public export
 33 | data MinMaxValue : Type where
 34 |   Auto       : MinMaxValue
 35 |   MML        : Length     -> MinMaxValue
 36 |   MMP        : Percentage -> MinMaxValue
 37 |   MMF        : Flex       -> MinMaxValue
 38 |   MinContent : MinMaxValue
 39 |   MaxContent : MinMaxValue
 40 |
 41 | export %inline
 42 | Cast Length MinMaxValue where
 43 |   cast = MML
 44 |
 45 | export %inline
 46 | Cast Percentage MinMaxValue where
 47 |   cast = MMP
 48 |
 49 | export %inline
 50 | Cast Flex MinMaxValue where
 51 |   cast = MMF
 52 |
 53 | export
 54 | Interpolation MinMaxValue where
 55 |   interpolate Auto       = "auto"
 56 |   interpolate MinContent = "min-content"
 57 |   interpolate MaxContent = "max-content"
 58 |   interpolate (MML x)    = interpolate x
 59 |   interpolate (MMP x)    = interpolate x
 60 |   interpolate (MMF x)    = interpolate x
 61 |
 62 | --------------------------------------------------------------------------------
 63 | --          GridValue
 64 | --------------------------------------------------------------------------------
 65 |
 66 | namespace GridValue
 67 |   public export
 68 |   data GridValue : Type where
 69 |     GL         : Length -> GridValue
 70 |     GP         : Percentage -> GridValue
 71 |     GF         : Flex -> GridValue
 72 |     MinMax     : (min,max : MinMaxValue) -> GridValue
 73 |     MaxContent : GridValue
 74 |     MinContent : GridValue
 75 |
 76 | export
 77 | Interpolation GridValue where
 78 |   interpolate (GL x)           = interpolate x
 79 |   interpolate (GP x)           = interpolate x
 80 |   interpolate (GF x)           = interpolate x
 81 |   interpolate (MinMax min max) = "minmax(\{min}, \{max})"
 82 |   interpolate MaxContent       = "max-content"
 83 |   interpolate MinContent       = "min-content"
 84 |
 85 | export
 86 | Interpolation (List GridValue) where
 87 |   interpolate = fastConcat . intersperse " " . map interpolate
 88 |
 89 | export %inline
 90 | Cast Length GridValue where
 91 |   cast = GL
 92 |
 93 | export %inline
 94 | Cast Percentage GridValue where
 95 |   cast = GP
 96 |
 97 | export %inline
 98 | Cast Flex GridValue where
 99 |   cast = GF
100 |
101 | --------------------------------------------------------------------------------
102 | --          GridPosition
103 | --------------------------------------------------------------------------------
104 |
105 | public export
106 | data GridPosition : Type where
107 |   At     : Bits32 -> GridPosition
108 |   FromTo : Bits32 -> Bits32 -> GridPosition
109 |
110 | export
111 | Interpolation GridPosition where
112 |   interpolate (At x)       = show x
113 |   interpolate (FromTo x y) = "\{show x} / \{show y}"
114 |