From 205f3ae75b9f4087f5ee9bdc6da6cdef3e191592 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 1 Mar 2024 12:13:42 +1300 Subject: [PATCH] Layout inline blocks NOTE: Replaced elements can be implemented via a wrapper. --- Graphics/Layout/Inline.hs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Graphics/Layout/Inline.hs b/Graphics/Layout/Inline.hs index 4c6e8a3..0c11afa 100644 --- a/Graphics/Layout/Inline.hs +++ b/Graphics/Layout/Inline.hs @@ -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 -- 2.30.2