on master help sign in
Allow 'empty' text images and relax constraints on joining clipped images.
d482c11Chris Penner
.gitignore+1
@@ -9,3 +9,4 @@ test/benchmark
9.cabal-sandbox
9.cabal-sandbox
10cabal.sandbox.config
10cabal.sandbox.config
11test/cabal.sandbox.config
11test/cabal.sandbox.config
12+.stack-work
src/Graphics/Vty/Image.hs+4−9
@@ -88,17 +88,13 @@ vertCat = foldr vertJoin EmptyImage
88
88
89-- | A Data.Text.Lazy value
89-- | A Data.Text.Lazy value
90text :: Attr -> TL.Text -> Image
90text :: Attr -> TL.Text -> Image
91−text a txt
92− | TL.length txt == 0 = EmptyImage
93− | otherwise = let displayWidth = safeWcswidth (TL.unpack txt)
91+text a txt = let displayWidth = safeWcswidth (TL.unpack txt)
94− in HorizText a txt displayWidth (fromIntegral $! TL.length txt)
92+ in HorizText a txt displayWidth (fromIntegral $! TL.length txt)
95
93
96-- | A Data.Text value
94-- | A Data.Text value
97text' :: Attr -> T.Text -> Image
95text' :: Attr -> T.Text -> Image
98−text' a txt
99− | T.length txt == 0 = EmptyImage
100− | otherwise = let displayWidth = safeWcswidth (T.unpack txt)
96+text' a txt = let displayWidth = safeWcswidth (T.unpack txt)
101− in HorizText a (TL.fromStrict txt) displayWidth (T.length txt)
97+ in HorizText a (TL.fromStrict txt) displayWidth (T.length txt)
102
98
103-- | an image of a single character. This is a standard Haskell 31-bit character assumed to be in
99-- | an image of a single character. This is a standard Haskell 31-bit character assumed to be in
104-- the ISO-10646 encoding.
100-- the ISO-10646 encoding.
@@ -117,7 +113,6 @@ char a c =
117-- directly to iso10646String or string.
113-- directly to iso10646String or string.
118--
114--
119iso10646String :: Attr -> String -> Image
115iso10646String :: Attr -> String -> Image
120−iso10646String _ [] = EmptyImage
121iso10646String a str =
116iso10646String a str =
122 let displayWidth = safeWcswidth str
117 let displayWidth = safeWcswidth str
123 in HorizText a (TL.pack str) displayWidth (length str)
118 in HorizText a (TL.pack str) displayWidth (length str)
src/Graphics/Vty/Image/Internal.hs+4−4
@@ -66,14 +66,14 @@ clipText txt leftSkip rightClip =
66--
66--
67-- * an empty image of no size or content.
67-- * an empty image of no size or content.
68data Image =
68data Image =
69− -- | A horizontal text span is always >= 1 column and has a row height of 1.
69+ -- | A horizontal text span has a row height of 1.
70 HorizText
70 HorizText
71 { attr :: Attr
71 { attr :: Attr
72 -- | The text to display. The display width of the text is always outputWidth.
72 -- | The text to display. The display width of the text is always outputWidth.
73 , displayText :: DisplayText
73 , displayText :: DisplayText
74− -- | The number of display columns for the text. Always > 0.
74+ -- | The number of display columns for the text.
75 , outputWidth :: Int
75 , outputWidth :: Int
76− -- | the number of characters in the text. Always > 0.
76+ -- | the number of characters in the text.
77 , charWidth :: Int
77 , charWidth :: Int
78 }
78 }
79 -- | A horizontal join can be constructed between any two images. However a HorizJoin instance is
79 -- | A horizontal join can be constructed between any two images. However a HorizJoin instance is
@@ -82,7 +82,7 @@ data Image =
82 | HorizJoin
82 | HorizJoin
83 { partLeft :: Image
83 { partLeft :: Image
84 , partRight :: Image
84 , partRight :: Image
85− , outputWidth :: Int -- ^ imageWidth partLeft == imageWidth partRight. Always > 1
85+ , outputWidth :: Int -- ^ imageWidth partLeft == imageWidth partRight. Always > 0
86 , outputHeight :: Int -- ^ imageHeight partLeft == imageHeight partRight. Always > 0
86 , outputHeight :: Int -- ^ imageHeight partLeft == imageHeight partRight. Always > 0
87 }
87 }
88 -- | A veritical join can be constructed between any two images. However a VertJoin instance is
88 -- | A veritical join can be constructed between any two images. However a VertJoin instance is
src/Graphics/Vty/PictureToSpans.hs+1−1
@@ -309,7 +309,7 @@ addMaybeClippedJoin name skip remaining offset i0Dim i0 i1 size = do
309 when (state^.remaining <= 0) $ fail $ name ++ " with remaining <= 0"
309 when (state^.remaining <= 0) $ fail $ name ++ " with remaining <= 0"
310 case state^.skip of
310 case state^.skip of
311 s -- TODO: check if clipped in other dim. if not use addUnclipped
311 s -- TODO: check if clipped in other dim. if not use addUnclipped
312− | s >= size -> fail $ name ++ " on fully clipped"
312+ | s > size -> fail $ name ++ " on fully clipped"
313 | s == 0 -> if state^.remaining > i0Dim
313 | s == 0 -> if state^.remaining > i0Dim
314 then do
314 then do
315 addMaybeClipped i0
315 addMaybeClipped i0