on master help sign in
Return the new number of columns to skip as well
4c218b7Ben Boeckel
src/Graphics/Vty/Span.hs+30−24
@@ -111,7 +111,7 @@ build_spans pic region = do
111 -- The ops builder recursively descends the image and outputs span ops that would
111 -- The ops builder recursively descends the image and outputs span ops that would
112 -- display that image. The number of columns remaining in this row before exceeding the
112 -- display that image. The number of columns remaining in this row before exceeding the
113 -- bounds is also provided. This is used to clip the span ops produced.
113 -- 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)
115 -- Fill in any unspecified columns with the background pattern.
115 -- Fill in any unspecified columns with the background pattern.
116 forM_ [0 .. region_height region - 1] $ \row -> do
116 forM_ [0 .. region_height region - 1] $ \row -> do
117 end_x <- readSTArray mrow_ops row >>= return . span_ops_effected_columns
117 end_x <- readSTArray mrow_ops row >>= return . span_ops_effected_columns
@@ -123,33 +123,34 @@ build_spans pic region = do
123
123
124type MRowOps s = STArray s Word SpanOps
124type MRowOps s = STArray s Word SpanOps
125
125
126−ops_for_row :: MRowOps s -> Background -> DisplayRegion -> Image -> Word -> Word -> Word -> Word -> ST s Word
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_row skip_col y remaining_columns
127+ops_for_row mrow_ops bg region image skip_dim@(skip_row,skip_col) y remaining_columns
128− | remaining_columns == 0 = return skip_row
128+ | remaining_columns == 0 = return skip_dim
129− | y >= region_height region = return skip_row
129+ | y >= region_height region = return skip_dim
130 | otherwise = case image of
130 | otherwise = case image of
131− EmptyImage -> return skip_row
131+ EmptyImage -> return skip_dim
132 -- The width provided is the number of columns this text span will occupy when displayed.
132 -- The width provided is the number of columns this text span will occupy when displayed.
133 -- if this is greater than the number of remaining columsn the output has to be produced a
133 -- if this is greater than the number of remaining columsn the output has to be produced a
134 -- character at a time.
134 -- character at a time.
135 HorizText a text_str _ _ -> do
135 HorizText a text_str _ _ -> do
136 if skip_row > 0
136 if skip_row > 0
137− then return $ skip_row - 1
137+ then return (skip_row - 1, skip_col)
138 else do
138 else do
139− snoc_text_span a text_str mrow_ops skip_col y remaining_columns
139+ skip_col' <- snoc_text_span a text_str mrow_ops skip_col y remaining_columns
140− return skip_row
140+ return (skip_row, skip_col')
141 VertJoin t b _ _ -> do
141 VertJoin t b _ _ -> do
142− skip_row' <- ops_for_row mrow_ops bg region t skip_row skip_col y remaining_columns
142+ (skip_row',skip_col') <- ops_for_row mrow_ops bg region t skip_dim 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
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'')
144 HorizJoin l r _ _ -> do
145 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
146 -- Don't output the right part unless there is at least a single column left after
147 -- Don't output the right part unless there is at least a single column left after
147 -- outputting the left part.
148 -- outputting the left part.
148− if image_width l > remaining_columns
149+ if image_width l - (skip_col - skip_col') > remaining_columns
149− then return skip_row'
150+ then return (skip_row,skip_col')
150 else do
151 else do
151− skip_row'' <- ops_for_row mrow_ops bg region r skip_row skip_col y (remaining_columns - image_width l)
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'))
152− return $ min skip_row' skip_row''
153+ return (min skip_row' skip_row'', skip_col'')
153 BGFill width height -> do
154 BGFill width height -> do
154 let min_height = if y + height > region_height region
155 let min_height = if y + height > region_height region
155 then region_height region - y
156 then region_height region - y
@@ -164,23 +165,27 @@ ops_for_row mrow_ops bg region image skip_row skip_col y remaining_columns
164 then 0
165 then 0
165 else min_width - skip_col
166 else min_width - skip_col
166 forM_ [y .. y + actual_height - 1] $ \y' -> snoc_bg_fill mrow_ops bg actual_width y'
167 forM_ [y .. y + actual_height - 1] $ \y' -> snoc_bg_fill mrow_ops bg actual_width y'
167− if actual_height > skip_row
168+ let skip_row' = if actual_height > skip_row
168− then return 0
169+ then 0
169− else return $ skip_row - min_height
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')
170 Translation (dx,dy) i -> do
175 Translation (dx,dy) i -> do
171 if dx < 0
176 if dx < 0
172 -- Translation left
177 -- Translation left
173 -- Extract the delta and add it to skip_col.
178 -- 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
175 -- Translation right
180 -- Translation right
176 else if dy < 0
181 else if dy < 0
177 -- Translation up
182 -- Translation up
178 -- Extract the delta and add it to skip_row.
183 -- 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
180 -- Translation down
185 -- Translation down
181 -- Pad the start of lines and above the image with a
186 -- Pad the start of lines and above the image with a
182 -- background_fill image.
187 -- 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
184 where
189 where
185 dw = toEnum $ abs dx
190 dw = toEnum $ abs dx
186 dh = toEnum $ abs dy
191 dh = toEnum $ abs dy
@@ -194,14 +199,15 @@ snoc_text_span :: (Foldable.Foldable t)
194 -> Word
199 -> Word
195 -> Word
200 -> Word
196 -> Word
201 -> Word
197− -> ST s ()
202+ -> ST s Word
198snoc_text_span a text_str mrow_ops skip_col y remaining_columns = do
203snoc_text_span a text_str mrow_ops skip_col y remaining_columns = do
199 snoc_op mrow_ops y $ AttributeChange a
204 snoc_op mrow_ops y $ AttributeChange a
200− let (ow', _, cw', txt) = Foldable.foldl'
205+ let (ow', dw', cw', txt) = Foldable.foldl'
201 build_cropped_txt
206 build_cropped_txt
202 ( 0, 0, 0, B.empty )
207 ( 0, 0, 0, B.empty )
203 text_str
208 text_str
204 snoc_op mrow_ops y $ TextSpan ow' cw' (UTF8.fromRep txt)
209 snoc_op mrow_ops y $ TextSpan ow' cw' (UTF8.fromRep txt)
210+ return $ skip_col - dw'
205 where
211 where
206 build_cropped_txt (ow', dw', char_count', b0) c = {-# SCC "build_cropped_txt" #-}
212 build_cropped_txt (ow', dw', char_count', b0) c = {-# SCC "build_cropped_txt" #-}
207 let w = wcwidth c
213 let w = wcwidth c