1 module Language.Symantic.Document.Dim where
3 import Data.Foldable (Foldable(..))
4 import Data.Function (($), id)
5 import Data.Functor ((<$>))
7 import Data.Monoid (Monoid(..))
8 import Data.Ord (Ord(..))
9 import Data.Semigroup (Semigroup(..))
10 import Data.String (IsString(..))
11 import Prelude (min, max, Num(..), toInteger)
12 import Text.Show (Show(..))
13 import qualified Data.List as List
14 import qualified Data.Text as T
15 import qualified Data.Text.Lazy as TL
17 import Language.Symantic.Document.Sym
27 instance IsString Dim where
28 fromString [] = Dim 0 0 0 0
33 , width_first = List.head ws
34 , width_last = List.last ws
43 instance Semigroup Dim where
44 x@(Dim wx hx wfx wlx) <> y@(Dim wy hy wfy wly) =
45 let w = max (wlx + wfy) (max wx wy) in
46 let h = max 0 $ hx + hy - 1 in
50 (1, 1) -> let v = wlx + wfy in Dim w h v v
51 (1, _) -> Dim w h (wfx + wfy) wly
52 (_, 1) -> Dim w h wfx (wlx + wfy)
54 instance Monoid Dim where
57 instance Doc_Text Dim where
58 spaces i = Dim i 1 i i
59 replicate i d = if i <= 0 then empty else d <> replicate (i - 1) d
60 int i = fromString $ show i
61 integer i = fromString $ show i
62 charH _c = Dim 1 1 1 1
63 stringH t = Dim l h l l where h = min 1 l; l = length t
64 textH t = Dim l h l l where h = min 1 l; l = T.length t
65 ltextH t = Dim l h l l where h = min 1 l; l = fromInteger $ toInteger $ TL.length t
66 instance Doc_Color Dim where
100 instance Doc_Decoration Dim where