~alcinnz/CatTrap

205f3ae75b9f4087f5ee9bdc6da6cdef3e191592 — Adrian Cochrane 8 months ago c4626b0
Layout inline blocks

NOTE: Replaced elements can be implemented via a wrapper.
1 files changed, 9 insertions(+), 11 deletions(-)

M Graphics/Layout/Inline.hs
M Graphics/Layout/Inline.hs => Graphics/Layout/Inline.hs +9 -11
@@ 10,7 10,7 @@ import Data.Text.ParagraphLayout.Rich (Paragraph(..), ParagraphOptions(..),
                                Fragment(..), ParagraphLayout(..), AncestorBox(..),
                                InnerNode(..), Box(..), RootNode(..),
                                layoutRich, boxSpacing, BoxSpacing(..),
                                activateBoxSpacing, paragraphSafeWidth)
                                activateBoxSpacing, paragraphSafeWidth, textAscender)
import Data.Text.ParagraphLayout.Rect (Rect(..),
                                width, height, x_max, x_min, y_min, y_max)
import qualified Data.Text.Glyphize as HB


@@ 75,11 75,16 @@ lowerSpacing :: (CastDouble m, CastDouble n) => (x -> PaddedBox m n) ->
lowerSpacing cb (Paragraph a b (RootBox c) d) = Paragraph a b (RootBox $ inner c) d
  where
    inner (Box childs opts) = flip Box opts $ map inner' childs
    inner' (InlineBox e@(_, f, _) child opts) = InlineBox e (inner child) $
    inner' (InlineBox e@(_, Left box, _) child opts) = inlineBox e box child opts
    inner' (InlineBox e@(_, Right k, _) (Box childs opts') opts) =
        let box = cb k in inlineBox e box (Box childs opts' {
            textAscender = Just $ Box.height $ mapY' unscale box
          }) opts
    inner' self@(TextSequence _ _) = self
    inlineBox dat f child opts = InlineBox dat (inner child) $
        flip activateBoxSpacing opts $
            BoxSpacingLeftRight (leftSpace box) (rightSpace box)
      where box = mapX' unscale $ mapY' unscale $ mapRight cb f
    inner' self@(TextSequence _ _) = self
      where box = mapX' unscale $ mapY' unscale f


-- | A tree extracted from Balkón's inline layout.


@@ 235,10 240,3 @@ union a b = Rect x_low y_high dx (-dy) where
    y_high = y_max a `max` y_max b
    dx = x_high - x_low
    dy = y_high - y_low

------
--- Supporting utils
------

mapRight cb (Right self) = cb self
mapRight _ (Left ret) = ret