~jaro/balkon

d77ca1f36721e33e0d6ab8839a9ae718aee64b6f — Jaro 1 year, 6 months ago d967aa9
Make paginateAll generic.
M src/Data/Text/ParagraphLayout/Internal/Paginable.hs => src/Data/Text/ParagraphLayout/Internal/Paginable.hs +10 -0
@@ 2,6 2,7 @@ module Data.Text.ParagraphLayout.Internal.Paginable
    ( PageOptions (..)
    , Paginable
    , paginate
    , paginateAll
    )
where



@@ 78,3 79,12 @@ instance Paginable (ParagraphLayout d) where
    paginate opts pl = case paginate opts (cutLines pl) of
        (c, p, Nothing) -> (c, mergeLines p, Nothing)
        (c, p, Just rest) -> (c, mergeLines p, Just (mergeLines rest))

-- | Perform page breaking on the entire input, returning a list of pages.
paginateAll :: Paginable a => PageOptions -> a -> [(PageContinuity, a)]
paginateAll opts pl = case paginate opts pl of
    (c, pl1, next) -> (c, pl1) : case next of
        Just pl2 -> paginateAll opts' pl2
        Nothing -> []
    where
        opts' = opts { pageCurrentHeight = pageNextHeight opts }

M test/Data/Text/ParagraphLayout/PlainSpec.hs => test/Data/Text/ParagraphLayout/PlainSpec.hs +1 -10
@@ 5,6 5,7 @@ import Test.Hspec
import System.FilePath ((</>))
import Data.Text.ParagraphLayout
import Data.Text.ParagraphLayout.FontLoader
import Data.Text.ParagraphLayout.Internal.Paginable
import Data.Text.ParagraphLayout.Internal.Plain.ParagraphLayout
import Data.Text.ParagraphLayout.Plain
import Data.Text.ParagraphLayout.Plain.ParagraphData


@@ 12,22 13,12 @@ import Data.Text.ParagraphLayout.PrettyShow
import Data.Text.ParagraphLayout.PrettyShow.Golden
import Data.Text.ParagraphLayout.Rect

type Page d = (PageContinuity, ParagraphLayout d)

emptyLayout :: ParagraphLayout d
emptyLayout = ParagraphLayout (Rect 0 0 0 0) []

emptySpanLayout :: ParagraphLayout d
emptySpanLayout = ParagraphLayout (Rect 0 0 0 0) [SpanLayout []]

paginateAll :: PageOptions -> ParagraphLayout d -> [Page d]
paginateAll opts pl = case paginate opts pl of
    (c, pl1, next) -> (c, pl1) : case next of
        Just pl2 -> paginateAll opts' pl2
        Nothing -> []
    where
        opts' = opts { pageCurrentHeight = pageNextHeight opts }

spec :: Spec
spec = do