~jaro/balkon

ae2fb11e89078608bbc1722b8b4096e5b20edf8b — Jaro 1 year, 6 months ago 4c1db0d
Separate WithSpan for sharing with other modules.
M balkon.cabal => balkon.cabal +1 -0
@@ 127,6 127,7 @@ library balkon-internal
        Data.Text.ParagraphLayout.Internal.TextOptions,
        Data.Text.ParagraphLayout.Internal.Tree,
        Data.Text.ParagraphLayout.Internal.TreeOfTexts,
        Data.Text.ParagraphLayout.Internal.WithSpan,
        Data.Text.ParagraphLayout.Internal.Zipper

    -- Modules used purely internally and not in any tests.

M src/Data/Text/ParagraphLayout/Internal/Layout.hs => src/Data/Text/ParagraphLayout/Internal/Layout.hs +1 -1
@@ 32,11 32,11 @@ import Data.Text.ParagraphLayout.Internal.LineHeight
import Data.Text.ParagraphLayout.Internal.ParagraphExtents
import qualified Data.Text.ParagraphLayout.Internal.ProtoFragment as PF
import Data.Text.ParagraphLayout.Internal.Rect
import Data.Text.ParagraphLayout.Internal.ResolvedSpan (WithSpan (WithSpan))
import qualified Data.Text.ParagraphLayout.Internal.ResolvedSpan as RS
import Data.Text.ParagraphLayout.Internal.Run
import Data.Text.ParagraphLayout.Internal.TextContainer
import Data.Text.ParagraphLayout.Internal.TextOptions
import Data.Text.ParagraphLayout.Internal.WithSpan

-- This is redundant.
-- TODO: Consider using `ResolvedSpan` as `fragmentUserData`, then swapping it

M src/Data/Text/ParagraphLayout/Internal/ResolvedSpan.hs => src/Data/Text/ParagraphLayout/Internal/ResolvedSpan.hs +1 -23
@@ 1,13 1,9 @@
module Data.Text.ParagraphLayout.Internal.ResolvedSpan
    ( ResolvedSpan (..)
    , WithSpan (WithSpan)
    )
module Data.Text.ParagraphLayout.Internal.ResolvedSpan (ResolvedSpan (..))
where

import Data.Text (Text)
import qualified Data.Text.ICU as BreakStatus (Line)

import Data.Text.ParagraphLayout.Internal.BiDiReorder
import Data.Text.ParagraphLayout.Internal.TextContainer
import Data.Text.ParagraphLayout.Internal.TextOptions



@@ 29,21 25,3 @@ instance Eq (ResolvedSpan d) where

instance TextContainer (ResolvedSpan d) where
    getText = spanText

-- | Wrapper for temporarily mapping the relationship to a `ResolvedSpan`.
data WithSpan d a = WithSpan (ResolvedSpan d) a

instance Functor (WithSpan d) where
    fmap f (WithSpan s a) = WithSpan s (f a)

instance TextContainer a => TextContainer (WithSpan d a) where
    getText (WithSpan _ c) = getText c

instance SeparableTextContainer a => SeparableTextContainer (WithSpan d a) where
    splitTextAt8 n (WithSpan rs c) = (WithSpan rs c1, WithSpan rs c2)
        where (c1, c2) = splitTextAt8 n c
    dropWhileStart p (WithSpan rs c) = WithSpan rs (dropWhileStart p c)
    dropWhileEnd p (WithSpan rs c) = WithSpan rs (dropWhileEnd p c)

instance WithLevel a => WithLevel (WithSpan d a) where
    level (WithSpan _ x) = level x

M src/Data/Text/ParagraphLayout/Internal/Rich.hs => src/Data/Text/ParagraphLayout/Internal/Rich.hs +1 -1
@@ 11,13 11,13 @@ import Data.Text.ParagraphLayout.Internal.Break
import Data.Text.ParagraphLayout.Internal.Fragment
import Data.Text.ParagraphLayout.Internal.Layout
import Data.Text.ParagraphLayout.Internal.ParagraphOptions
import Data.Text.ParagraphLayout.Internal.ResolvedSpan (WithSpan (WithSpan))
import qualified Data.Text.ParagraphLayout.Internal.ResolvedSpan as RS
import Data.Text.ParagraphLayout.Internal.Rich.Paragraph
import Data.Text.ParagraphLayout.Internal.Rich.ParagraphLayout
import Data.Text.ParagraphLayout.Internal.Run
import Data.Text.ParagraphLayout.Internal.TextOptions
import Data.Text.ParagraphLayout.Internal.Tree
import Data.Text.ParagraphLayout.Internal.WithSpan

-- | Lay out a rich text paragraph.
layoutRich :: Paragraph d -> ParagraphLayout d

A src/Data/Text/ParagraphLayout/Internal/WithSpan.hs => src/Data/Text/ParagraphLayout/Internal/WithSpan.hs +24 -0
@@ 0,0 1,24 @@
module Data.Text.ParagraphLayout.Internal.WithSpan (WithSpan (WithSpan))
where

import Data.Text.ParagraphLayout.Internal.BiDiReorder
import Data.Text.ParagraphLayout.Internal.ResolvedSpan
import Data.Text.ParagraphLayout.Internal.TextContainer

-- | Wrapper for temporarily mapping the relationship to a `ResolvedSpan`.
data WithSpan d a = WithSpan (ResolvedSpan d) a

instance Functor (WithSpan d) where
    fmap f (WithSpan s a) = WithSpan s (f a)

instance TextContainer a => TextContainer (WithSpan d a) where
    getText (WithSpan _ c) = getText c

instance SeparableTextContainer a => SeparableTextContainer (WithSpan d a) where
    splitTextAt8 n (WithSpan rs c) = (WithSpan rs c1, WithSpan rs c2)
        where (c1, c2) = splitTextAt8 n c
    dropWhileStart p (WithSpan rs c) = WithSpan rs (dropWhileStart p c)
    dropWhileEnd p (WithSpan rs c) = WithSpan rs (dropWhileEnd p c)

instance WithLevel a => WithLevel (WithSpan d a) where
    level (WithSpan _ x) = level x