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.Semigroup (Semigroup(..))
9 import Data.String (IsString(..))
10 import Prelude (min, max, Num(..), toInteger)
11 import Text.Show (Show(..))
12 import qualified Data.List as List
13 import qualified Data.Text as T
14 import qualified Data.Text.Lazy as TL
16 import Language.Symantic.Document.Sym
26 instance IsString Dim where
27 fromString [] = Dim 0 0 0 0
32 , width_first = List.head ws
33 , width_last = List.last ws
42 instance Semigroup Dim where
43 x@(Dim wx hx wfx wlx) <> y@(Dim wy hy wfy wly) =
44 let w = max (wlx + wfy) (max wx wy) in
45 let h = max 0 $ hx + hy - 1 in
49 (1, 1) -> let v = wlx + wfy in Dim w h v v
50 (1, _) -> Dim w h (wfx + wfy) wly
51 (_, 1) -> Dim w h wfx (wlx + wfy)
53 instance Monoid Dim where
56 instance Doc_Text Dim where
57 spaces i = Dim i 1 i 1
58 int i = fromString $ show i
59 integer i = fromString $ show i
60 charH _c = Dim 1 1 1 1
61 stringH t = Dim l h l l where h = min 1 l; l = length t
62 textH t = Dim l h l l where h = min 1 l; l = T.length t
63 ltextH t = Dim l h l l where h = min 1 l; l = fromInteger $ toInteger $ TL.length t
64 instance Doc_Color Dim where
98 instance Doc_Decoration Dim where