on master help sign in
Use Word instead of Int for the dimension type
0cdd6f3Ben Boeckel
src/Graphics/Vty/Image.hs+16−10
@@ -102,9 +102,9 @@ data Image =
102 | EmptyImage
102 | EmptyImage
103 | Translation (Int, Int) Image
103 | Translation (Int, Int) Image
104 -- Crop an image to a size
104 -- Crop an image to a size
105− | ImageCrop (Int, Int) Image
105+ | ImageCrop (Word, Word) Image
106 -- Pad an image up to a size
106 -- Pad an image up to a size
107− | ImagePad (Int, Int) Image
107+ | ImagePad (Word, Word) Image
108 deriving Eq
108 deriving Eq
109
109
110instance Show Image where
110instance Show Image where
@@ -213,8 +213,8 @@ image_width VertJoin { output_width = w } = w
213image_width BGFill { output_width = w } = w
213image_width BGFill { output_width = w } = w
214image_width EmptyImage = 0
214image_width EmptyImage = 0
215image_width ( Translation _v i ) = image_width i
215image_width ( Translation _v i ) = image_width i
216−image_width ( ImageCrop _v i ) = min (image_width i) (toEnum $ fst _v)
216+image_width ( ImageCrop _v i ) = min (image_width i) $ fst _v
217−image_width ( ImagePad _v i ) = max (image_width i) (toEnum $ fst _v)
217+image_width ( ImagePad _v i ) = max (image_width i) $ fst _v
218
218
219-- | The height of an Image. This is the number of display rows the image will occupy.
219-- | The height of an Image. This is the number of display rows the image will occupy.
220image_height :: Image -> Word
220image_height :: Image -> Word
@@ -224,8 +224,8 @@ image_height VertJoin { output_height = r } = r
224image_height BGFill { output_height = r } = r
224image_height BGFill { output_height = r } = r
225image_height EmptyImage = 0
225image_height EmptyImage = 0
226image_height ( Translation _v i ) = image_height i
226image_height ( Translation _v i ) = image_height i
227−image_height ( ImageCrop _v i ) = min (image_height i) (toEnum $ snd _v)
227+image_height ( ImageCrop _v i ) = min (image_height i) $ snd _v
228−image_height ( ImagePad _v i ) = max (image_height i) (toEnum $ snd _v)
228+image_height ( ImagePad _v i ) = max (image_height i) $ snd _v
229
229
230-- | Combines two images side by side.
230-- | Combines two images side by side.
231--
231--
@@ -342,8 +342,14 @@ empty_image = EmptyImage
342translate :: (Int, Int) -> Image -> Image
342translate :: (Int, Int) -> Image -> Image
343translate v i = Translation v i
343translate v i = Translation v i
344
344
345−crop :: (Int, Int) -> Image -> Image
345+crop :: (Word, Word) -> Image -> Image
346−crop v i = ImageCrop v i
346+crop v@(w,h) i
347+ | w == 0 = EmptyImage
348+ | h == 0 = EmptyImage
349+ | otherwise = ImagePad v i
347
350
348−pad :: (Int, Int) -> Image -> Image
351+pad :: (Word, Word) -> Image -> Image
352+pad v@(w,h) i
353+ | w == 0 = EmptyImage
354+ | h == 0 = EmptyImage
349−pad = ImagePad v i
355+ | otherwise = ImagePad v i
src/Graphics/Vty/Span.hs+9−9
@@ -152,18 +152,18 @@ ops_for_row mrow_ops bg region image y remaining_columns
152 else width
152 else width
153 forM_ [y .. y + actual_height - 1] $ \y' -> snoc_bg_fill mrow_ops bg actual_width y'
153 forM_ [y .. y + actual_height - 1] $ \y' -> snoc_bg_fill mrow_ops bg actual_width y'
154 Translation _offset i -> ops_for_row mrow_ops bg region i y remaining_columns
154 Translation _offset i -> ops_for_row mrow_ops bg region i y remaining_columns
155− ImageCrop _size i ->
155+ ImageCrop (max_w,max_h) i ->
156− if y >= (toEnum $ snd _size)
156+ if y >= max_h
157 then return ()
157 then return ()
158− else ops_for_row mrow_ops bg region i y (min remaining_columns $ toEnum $ fst _size)
158+ else ops_for_row mrow_ops bg region i y (min remaining_columns max_w)
159− ImagePad (x,y) i -> do
159+ ImagePad (min_w,min_h) i -> do
160− let hpad = if image_width i < x
160+ let hpad = if image_width i < min_w
161− then background_fill (x - image_width i) (image_height i)
161+ then background_fill (min_w - image_width i) (image_height i)
162 else empty_image
162 else empty_image
163− let vpad = if image_height i < y
163+ let vpad = if image_height i < min_h
164− then background_fill (image_width i) (y - image_height i)
164+ then background_fill (image_width i) (min_h - image_height i)
165 else empty_image
165 else empty_image
166− ops_for_row mrow_ops bg region (vert_join (horiz_join i hpad) vpad) y remaining_columns
166+ ops_for_row mrow_ops bg region ((i <|> hpad) <-> vpad) y remaining_columns
167
167
168snoc_text_span :: (Foldable.Foldable t)
168snoc_text_span :: (Foldable.Foldable t)
169 => Attr
169 => Attr