From 2db7d32290bc20ee29469a9edf0d64d3dbad93c9 Mon Sep 17 00:00:00 2001 From: Jaro Date: Sun, 7 May 2023 22:51:12 +0200 Subject: [PATCH] Allow extracting spacing from ResolvedBox. --- .../ParagraphLayout/Internal/ResolvedBox.hs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs b/src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs index 87f1eb3..61f679c 100644 --- a/src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs +++ b/src/Data/Text/ParagraphLayout/Internal/ResolvedBox.hs @@ -1,7 +1,14 @@ -module Data.Text.ParagraphLayout.Internal.ResolvedBox (ResolvedBox (..)) +module Data.Text.ParagraphLayout.Internal.ResolvedBox + ( ResolvedBox (..) + , boxEndSpacing + , boxLeftSpacing + , boxRightSpacing + , boxStartSpacing + ) where -import Data.Text.Glyphize (Direction) +import Data.Int (Int32) +import Data.Text.Glyphize (Direction (DirLTR, DirRTL)) import Data.Text.ParagraphLayout.Internal.BoxOptions @@ -16,3 +23,25 @@ data ResolvedBox d = ResolvedBox instance Eq (ResolvedBox d) where a == b = boxIndex a == boxIndex b + +boxLeftSpacing :: ResolvedBox d -> Int32 +boxLeftSpacing rb = case boxSpacing $ boxOptions rb of + BoxSpacingLeftRight s _ -> s + +boxRightSpacing :: ResolvedBox d -> Int32 +boxRightSpacing rb = case boxSpacing $ boxOptions rb of + BoxSpacingLeftRight _ s -> s + +-- | Spacing at the start of the given box. +boxStartSpacing :: ResolvedBox d -> Int32 +boxStartSpacing rb = case (boxDirection rb, boxSpacing $ boxOptions rb) of + (DirLTR, BoxSpacingLeftRight s _) -> s + (DirRTL, BoxSpacingLeftRight _ s) -> s + (_, _) -> 0 + +-- | Spacing at the end of the given box. +boxEndSpacing :: ResolvedBox d -> Int32 +boxEndSpacing rb = case (boxDirection rb, boxSpacing $ boxOptions rb) of + (DirLTR, BoxSpacingLeftRight _ s) -> s + (DirRTL, BoxSpacingLeftRight s _) -> s + (_, _) -> 0 -- 2.30.2