on master help sign in
Return the new number of columns to skip as well
commit4c218b7b5ebaece1166ef7253d14338ff26d7209 authorBen Boeckel <MathStuf@gmail.com> dateSat 2 Apr 2011, 11:51 (16 years ago) parent111e5ad
1 file changed+30−24
src/Graphics/Vty/Span.hs+30−24
src/Graphics/Vty/Span.hs+30−24
@@ -111,7 +111,7 @@ build_spans pic region = do
111111 -- The ops builder recursively descends the image and outputs span ops that would
112112 -- display that image. The number of columns remaining in this row before exceeding the
113113 -- bounds is also provided. This is used to clip the span ops produced.
114− _ <- ops_for_row mrow_ops (pic_background pic) region (pic_image pic) 0 0 0 (region_width region)
114+ _ <- ops_for_row mrow_ops (pic_background pic) region (pic_image pic) (0,0) 0 (region_width region)
115115 -- Fill in any unspecified columns with the background pattern.
116116 forM_ [0 .. region_height region - 1] $ \row -> do
117117 end_x <- readSTArray mrow_ops row >>= return . span_ops_effected_columns
@@ -123,33 +123,34 @@ build_spans pic region = do
123123
124124type MRowOps s = STArray s Word SpanOps
125125
126−ops_for_row :: MRowOps s -> Background -> DisplayRegion -> Image -> Word -> Word -> Word -> Word -> ST s Word
127−ops_for_row mrow_ops bg region image skip_row skip_col y remaining_columns
128− | remaining_columns == 0 = return skip_row
129− | y >= region_height region = return skip_row
126+ops_for_row :: MRowOps s -> Background -> DisplayRegion -> Image -> (Word, Word) -> Word -> Word -> ST s (Word, Word)
127+ops_for_row mrow_ops bg region image skip_dim@(skip_row,skip_col) y remaining_columns
128+ | remaining_columns == 0 = return skip_dim
129+ | y >= region_height region = return skip_dim
130130 | otherwise = case image of
131− EmptyImage -> return skip_row
131+ EmptyImage -> return skip_dim
132132 -- The width provided is the number of columns this text span will occupy when displayed.
133133 -- if this is greater than the number of remaining columsn the output has to be produced a
134134 -- character at a time.
135135 HorizText a text_str _ _ -> do
136136 if skip_row > 0
137− then return $ skip_row - 1
137+ then return (skip_row - 1, skip_col)
138138 else do
139− snoc_text_span a text_str mrow_ops skip_col y remaining_columns
140− return skip_row
139+ skip_col' <- snoc_text_span a text_str mrow_ops skip_col y remaining_columns
140+ return (skip_row, skip_col')
141141 VertJoin t b _ _ -> do
142− skip_row' <- ops_for_row mrow_ops bg region t skip_row skip_col y remaining_columns
143− ops_for_row mrow_ops bg region b skip_row' skip_col (y + image_height t - (skip_row - skip_row')) remaining_columns
142+ (skip_row',skip_col') <- ops_for_row mrow_ops bg region t skip_dim y remaining_columns
143+ (skip_row'',skip_col'') <- ops_for_row mrow_ops bg region b (skip_row', skip_col) (y + image_height t - (skip_row - skip_row')) remaining_columns
144+ return (skip_row'', min skip_col' skip_col'')
144145 HorizJoin l r _ _ -> do
145− skip_row' <- ops_for_row mrow_ops bg region l skip_row skip_col y remaining_columns
146+ (skip_row',skip_col') <- ops_for_row mrow_ops bg region l skip_dim y remaining_columns
146147 -- Don't output the right part unless there is at least a single column left after
147148 -- outputting the left part.
148− if image_width l > remaining_columns
149− then return skip_row'
149+ if image_width l - (skip_col - skip_col') > remaining_columns
150+ then return (skip_row,skip_col')
150151 else do
151− skip_row'' <- ops_for_row mrow_ops bg region r skip_row skip_col y (remaining_columns - image_width l)
152− return $ min skip_row' skip_row''
152+ (skip_row'',skip_col'') <- ops_for_row mrow_ops bg region r (skip_row, skip_col') y (remaining_columns - image_width l + (skip_col - skip_col'))
153+ return (min skip_row' skip_row'', skip_col'')
153154 BGFill width height -> do
154155 let min_height = if y + height > region_height region
155156 then region_height region - y
@@ -164,23 +165,27 @@ ops_for_row mrow_ops bg region image skip_row skip_col y remaining_columns
164165 then 0
165166 else min_width - skip_col
166167 forM_ [y .. y + actual_height - 1] $ \y' -> snoc_bg_fill mrow_ops bg actual_width y'
167− if actual_height > skip_row
168− then return 0
169− else return $ skip_row - min_height
168+ let skip_row' = if actual_height > skip_row
169+ then 0
170+ else skip_row - min_height
171+ skip_col' = if actual_width > skip_col
172+ then 0
173+ else skip_col - min_width
174+ return (skip_row',skip_col')
170175 Translation (dx,dy) i -> do
171176 if dx < 0
172177 -- Translation left
173178 -- Extract the delta and add it to skip_col.
174− then ops_for_row mrow_ops bg region (translate (0, dy) i) skip_row (skip_col + dw) y remaining_columns
179+ then ops_for_row mrow_ops bg region (translate (0, dy) i) (skip_row, skip_col + dw) y remaining_columns
175180 -- Translation right
176181 else if dy < 0
177182 -- Translation up
178183 -- Extract the delta and add it to skip_row.
179− then ops_for_row mrow_ops bg region (translate (dx, 0) i) (skip_row + dh) skip_col y remaining_columns
184+ then ops_for_row mrow_ops bg region (translate (dx, 0) i) (skip_row + dh, skip_col) y remaining_columns
180185 -- Translation down
181186 -- Pad the start of lines and above the image with a
182187 -- background_fill image.
183− else ops_for_row mrow_ops bg region (background_fill ow dh <-> (background_fill dw ih <|> i)) skip_row skip_col y remaining_columns
188+ else ops_for_row mrow_ops bg region (background_fill ow dh <-> (background_fill dw ih <|> i)) skip_dim y remaining_columns
184189 where
185190 dw = toEnum $ abs dx
186191 dh = toEnum $ abs dy
@@ -194,14 +199,15 @@ snoc_text_span :: (Foldable.Foldable t)
194199 -> Word
195200 -> Word
196201 -> Word
197− -> ST s ()
202+ -> ST s Word
198203snoc_text_span a text_str mrow_ops skip_col y remaining_columns = do
199204 snoc_op mrow_ops y $ AttributeChange a
200− let (ow', _, cw', txt) = Foldable.foldl'
205+ let (ow', dw', cw', txt) = Foldable.foldl'
201206 build_cropped_txt
202207 ( 0, 0, 0, B.empty )
203208 text_str
204209 snoc_op mrow_ops y $ TextSpan ow' cw' (UTF8.fromRep txt)
210+ return $ skip_col - dw'
205211 where
206212 build_cropped_txt (ow', dw', char_count', b0) c = {-# SCC "build_cropped_txt" #-}
207213 let w = wcwidth c