~jaro/balkon

ref: ba1e5a040d130d35a16a7d9a0146cec41262cbff balkon/src/Data/Text/ParagraphLayout/Internal/AncestorBox.hs -rw-r--r-- 2.4 KiB
ba1e5a04Jaro Test line breaking in boxes. 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Data.Text.ParagraphLayout.Internal.AncestorBox
    ( AncestorBox (..)
    , totalLeftSpacing
    , totalRightSpacing
    )
where

import Data.Int (Int32)
import Data.Maybe (catMaybes)

-- | Describes the relationship of a fragment to an inline box that contains it.
--
-- A box can have many fragments, and a fragment contained by a box is also
-- contained by all ancestors of that box.
--
-- The root inline box, which forms the basis of each paragraph, is implied
-- and not described by this type of record.
data AncestorBox d = AncestorBox

    { boxUserData :: d
    -- ^ User-defined data associated with the inline box.

    , boxLeftSpacing :: Maybe Int32
    -- ^ `Just` an amount of empty space to add to the left side
    -- of the fragment on account of this inline box, or `Nothing`
    -- if this is not the leftmost fragment of this inline box.
    --
    -- Equal to `boxStartSpacing` for LTR boxes.
    --
    -- Equal to `boxEndSpacing` for RTL boxes.

    , boxRightSpacing :: Maybe Int32
    -- ^ `Just` an amount of empty space to add to the right side
    -- of the fragment on account of this inline box, or `Nothing`
    -- if this is not the rightmost fragment of this inline box.
    --
    -- Equal to `boxStartSpacing` for RTL boxes.
    --
    -- Equal to `boxEndSpacing` for LTR boxes.

    , boxStartSpacing :: Maybe Int32
    -- ^ `Just` an amount of empty space to add to the start side
    -- of the fragment on account of this inline box, or `Nothing`
    -- if this is not the startmost fragment of this inline box.
    --
    -- Equal to `boxLeftSpacing` for LTR boxes.
    --
    -- Equal to `boxRightSpacing` for RTL boxes.

    , boxEndSpacing :: Maybe Int32
    -- ^ `Just` an amount of empty space to add to the end side
    -- of the fragment on account of this inline box, or `Nothing`
    -- if this is not the endmost fragment of this inline box.
    --
    -- Equal to `boxLeftSpacing` for RTL boxes.
    --
    -- Equal to `boxRightSpacing` for LTR boxes.

    }
    deriving (Eq, Read, Show)

-- | Amount of empty space to add to the left side
-- on account of all given boxes in sum.
totalLeftSpacing :: [AncestorBox d] -> Int32
totalLeftSpacing bs = sum $ catMaybes $ map boxLeftSpacing bs

-- | Amount of empty space to add to the right side
-- on account of all given boxes in sum.
totalRightSpacing :: [AncestorBox d] -> Int32
totalRightSpacing bs = sum $ catMaybes $ map boxRightSpacing bs