module Data.Niagra.Properties.Units
(
Operation(..),
calc,
px,
px',
cm,
cm',
mm,
mm',
inch,
inch',
pt,
pt',
pc,
pc',
unitless,
unitless',
em,
em',
ex,
ex',
ch,
ch',
rem,
rem',
vw,
vw',
vh,
vh',
vmin,
vmin',
vmax,
vmax',
perc,
perc',
auto
)
where
import Data.Niagra.Value
import Data.Niagra.Builder
import Data.Niagra.Builder.Numbers
import Data.Text (Text)
import Data.Monoid
import Prelude hiding (rem)
data Operation = OpAdd | OpSub | OpDiv | OpMul
instance Value Operation where
build OpAdd = singleton '+'
build OpSub = singleton '-'
build OpDiv = singleton '/'
build OpMul = singleton '*'
calc :: Operation -> Builder -> Builder -> Builder
calc op a b = mconcat ["calc(", a, singleton ' ', build op, singleton ' ', b, singleton ')']
wholeMeas :: Text -> Integer -> Builder
wholeMeas _ 0 = decimal 0
wholeMeas t v = decimal v <> fromText t
floatMeas :: Text -> Double -> Builder
floatMeas _ 0.0 = realFloat 0.0
floatMeas t v = realFloat v <> fromText t
px,cm,mm,inch,pt,pc,unitless :: Integer -> Builder
px',cm',mm',inch',pt',pc',unitless' :: Double -> Builder
px = wholeMeas "px"
px' = floatMeas "px"
cm = wholeMeas "cm"
cm' = floatMeas "cm"
mm = wholeMeas "mm"
mm' = floatMeas "mm"
inch = wholeMeas "in"
inch' = floatMeas "in"
pt = wholeMeas "pt"
pt' = floatMeas "pt"
pc = wholeMeas "pc"
pc' = floatMeas "pc"
unitless = decimal
unitless' = realFloat
em,ex,ch,rem,vw,vh,vmin,vmax,perc :: Integer -> Builder
em',ex',ch',rem',vw',vh',vmin',vmax',perc' :: Double -> Builder
em = wholeMeas "em"
em' = floatMeas "em"
ex = wholeMeas "ex"
ex' = floatMeas "ex"
ch = wholeMeas "ch"
ch' = floatMeas "ch"
rem = wholeMeas "rem"
rem' = floatMeas "rem"
vw = wholeMeas "vw"
vw' = floatMeas "vw"
vh = wholeMeas "vh"
vh' = floatMeas "vh"
vmin = wholeMeas "vmin"
vmin' = floatMeas "vmin"
vmax = wholeMeas "vmax"
vmax' = floatMeas "vmax"
perc = wholeMeas "%"
perc' = floatMeas "%"
auto :: Builder
auto = fromText "auto"