Skip to content

Commit

Permalink
Rename fragment to reveal
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Feb 5, 2025
1 parent ebb8ce5 commit 635d474
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 116 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ Now, we will only see one slide, which contains a nested header.

### Fragmented slides

By default, slides are always displayed "all at once". If you want to display
By default, slides are always displayed "all at once". If you want to reveal
them fragment by fragment, there are two ways to do that. The most common
case is that lists should be displayed incrementally.

Expand Down
16 changes: 8 additions & 8 deletions lib/Patat/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ evalBlock settings orig@(CodeBlock attr@(_, classes, _) txt)
(False, True) -> pure [VarBlock var]
(False, False) -> pure [orig, VarBlock var]
(True, True) -> do
counterID <- CounterID <$> state freshUnique
pure $ pure $ Fragmented ConcatWrapper $ Fragment
counterID
[counterID]
revealID <- RevealID <$> state freshUnique
pure $ pure $ Reveal ConcatWrapper $ RevealSequence
revealID
[revealID]
[ (S.singleton 0, [orig])
, (S.singleton 1, [VarBlock var])
]
(True, False) -> do
counterID <- CounterID <$> state freshUnique
pure $ pure $ Fragmented ConcatWrapper $ Fragment
counterID
[counterID]
revealID <- RevealID <$> state freshUnique
pure $ pure $ Reveal ConcatWrapper $ RevealSequence
revealID
[revealID]
[ (S.fromList [0, 1], [orig])
, (S.fromList [1], [VarBlock var])
]
Expand Down
17 changes: 8 additions & 9 deletions lib/Patat/Presentation/Display.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ displayWithBorders (Size rows columns) pres@Presentation {..} f =
, dsTheme = fromMaybe Theme.defaultTheme (psTheme settings)
, dsSyntaxMap = pSyntaxMap
, dsResolve = \var -> fromMaybe [] $ HMS.lookup var pVars
, dsCounters = counters
, dsRevealState = revealState
}

counters = case activeFragment pres of
revealState = case activeFragment pres of
Just (ActiveContent _ _ c) -> c
_ -> mempty

Expand Down Expand Up @@ -196,11 +196,10 @@ prettyMargins ds blocks = vertical $
Margins {..} = dsMargins ds

-- For every block, calculate the size based on its last fragment.
-- We find the last fragment by looking at all counters.
blockSize block =
let counters = triggersToCounters $ blocksTriggers [block] in
let revealState = blocksRevealLastStep [block] in
PP.dimensions $ deindent $ horizontalWrap $
prettyBlock ds {dsCounters = counters} block
prettyBlock ds {dsRevealState = revealState} block

-- Vertically align some blocks by adding spaces in front of it.
-- We also take in the number of rows for every block so we don't
Expand Down Expand Up @@ -228,12 +227,12 @@ prettyMargins ds blocks = vertical $

-- Render and horizontally align a block. Also returns the desired rows.
horizontal :: Block -> (PP.Doc, Int)
horizontal b@(Fragmented ConcatWrapper fragment) =
horizontal b@(Reveal ConcatWrapper reveal) =
-- Horizontally aligning a fragment with a ConcatWrapper is a special
-- case, as we want to horizontal align all the things inside
-- individually.
let (fblocks, _) = unzip $ map horizontal $
fragmentToBlocks (dsCounters ds) ConcatWrapper fragment in
revealToBlocks (dsRevealState ds) ConcatWrapper reveal in
(PP.vcat fblocks, fst (blockSize b))
horizontal block =
let size@(r, _) = blockSize block in
Expand Down Expand Up @@ -372,8 +371,8 @@ prettyBlock ds (LineBlock inliness) =

prettyBlock ds (Figure _attr blocks) = prettyBlocks ds blocks

prettyBlock ds (Fragmented w fragment) = prettyBlocks ds $
fragmentToBlocks (dsCounters ds) w fragment
prettyBlock ds (Reveal w fragment) = prettyBlocks ds $
revealToBlocks (dsRevealState ds) w fragment

prettyBlock ds (VarBlock var) = prettyBlocks ds $ dsResolve ds var

Expand Down
18 changes: 9 additions & 9 deletions lib/Patat/Presentation/Display/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Patat.Presentation.Display.Internal
--------------------------------------------------------------------------------
import Patat.Presentation.Internal (Margins)
import Patat.Presentation.Settings (Wrap)
import Patat.Presentation.Syntax (Block, Counters, Var)
import Patat.Presentation.Syntax (Block, RevealState, Var)
import qualified Patat.PrettyPrint as PP
import Patat.Size (Size)
import qualified Patat.Theme as Theme
Expand All @@ -17,14 +17,14 @@ import qualified Skylighting as Skylighting

--------------------------------------------------------------------------------
data DisplaySettings = DisplaySettings
{ dsSize :: !Size
, dsWrap :: !Wrap
, dsTabStop :: !Int
, dsMargins :: !Margins
, dsTheme :: !Theme.Theme
, dsSyntaxMap :: !Skylighting.SyntaxMap
, dsResolve :: !(Var -> [Block])
, dsCounters :: !Counters
{ dsSize :: !Size
, dsWrap :: !Wrap
, dsTabStop :: !Int
, dsMargins :: !Margins
, dsTheme :: !Theme.Theme
, dsSyntaxMap :: !Skylighting.SyntaxMap
, dsResolve :: !(Var -> [Block])
, dsRevealState :: !RevealState
}


Expand Down
38 changes: 19 additions & 19 deletions lib/Patat/Presentation/Fragment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ fragmentBlocks fs blocks = (>>= fragmentAgainAfterLists) $
[] -> pure []
[_] -> concat <$> traverse (fragmentBlock fs) blocks
sections0@(_ : _) -> do
counterID <- CounterID <$> state freshUnique
revealID <- RevealID <$> state freshUnique
sections1 <- traverse (fragmentBlocks fs) sections0
let pauses = length sections1 - 1
triggers = case sections1 of
[] -> replicate pauses counterID
(sh : st) -> blocksTriggers sh ++
[c | s <- st, c <- counterID : blocksTriggers s]
pure $ pure $ Fragmented ConcatWrapper $ Fragment
counterID
[] -> replicate pauses revealID
(sh : st) -> blocksRevealOrder sh ++
[c | s <- st, c <- revealID : blocksRevealOrder s]
pure $ pure $ Reveal ConcatWrapper $ RevealSequence
revealID
triggers
[(S.fromList [i .. pauses], s) | (i, s) <- zip [0 ..] sections1]

Expand Down Expand Up @@ -104,24 +104,24 @@ fragmentBlock _ block@(Figure {}) = pure [block]
fragmentBlock _ block@(VarBlock {}) = pure [block]
fragmentBlock _ block@(SpeakerNote {}) = pure [block]
fragmentBlock _ block@(Config {}) = pure [block]
fragmentBlock _ block@(Fragmented {}) = pure [block] -- Should not happen
fragmentBlock _ block@(Reveal {}) = pure [block] -- Should not happen

fragmentList
:: FragmentSettings -- ^ Global settings
-> Bool -- ^ Fragment THIS list?
-> FragmentWrapper -- ^ List constructor
-> RevealWrapper -- ^ List constructor
-> [[Block]] -- ^ List items
-> FragmentM [Block] -- ^ Resulting list
fragmentList fs fragmentThisList fw items0 = do
fragmentList fs fragmentThisList rw items0 = do
items1 <- traverse (fragmentBlocks fs) items0
case fragmentThisList of
False -> pure $ fragmentWrapper fw items1
False -> pure $ revealWrapper rw items1
True -> do
counterID <- CounterID <$> state freshUnique
let triggers = [c | s <- items1, c <- counterID : blocksTriggers s]
revealID <- RevealID <$> state freshUnique
let triggers = [c | s <- items1, c <- revealID : blocksRevealOrder s]
pauses = length items1
pure $ pure $ Fragmented fw $ Fragment
counterID
pure $ pure $ Reveal rw $ RevealSequence
revealID
triggers
[ (S.fromList [i .. pauses], s)
| (i, s) <- zip [1 ..] items1
Expand All @@ -134,21 +134,21 @@ fragmentAgainAfterLists blocks = case splitAfterLists [] blocks of
[] -> pure []
[_] -> pure blocks
sections@(_ : _) -> do
counterID <- CounterID <$> state freshUnique
revealID <- RevealID <$> state freshUnique
let pauses = length sections - 1
triggers = init
-- Use init to skip the final counter (we don't want to add
-- a pause at the very end since everything is displayed at
-- that point).
[c | s <- sections, c <- blocksTriggers s ++ [counterID]]
pure $ pure $ Fragmented ConcatWrapper $ Fragment
counterID
[c | s <- sections, c <- blocksRevealOrder s ++ [revealID]]
pure $ pure $ Reveal ConcatWrapper $ RevealSequence
revealID
triggers
[(S.fromList [i .. pauses + 1], s) | (i, s) <- zip [0 ..] sections]
where
splitAfterLists :: [Block] -> [Block] -> [[Block]]
splitAfterLists acc [] = [reverse acc]
splitAfterLists acc (b@(Fragmented w _) : bs)
splitAfterLists acc (b@(Reveal w _) : bs)
| isListWrapper w, not (null bs) =
reverse (b : acc) : splitAfterLists [] bs
splitAfterLists acc (b : bs) = splitAfterLists (b : acc) bs
Expand Down
11 changes: 5 additions & 6 deletions lib/Patat/Presentation/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ getSlide sidx = (`Seq.safeIndex` sidx) . pSlides
--------------------------------------------------------------------------------
numFragments :: Slide -> Int
numFragments slide = case slideContent slide of
ContentSlide blocks -> 1 + length (blocksTriggers blocks)
ContentSlide blocks -> blocksRevealSteps blocks
TitleSlide _ _ -> 1


Expand All @@ -143,7 +143,7 @@ data ActiveFragment
= ActiveContent
[Block]
(HS.HashSet Var)
Counters
RevealState
| ActiveTitle Block
deriving (Show)

Expand All @@ -157,10 +157,9 @@ activeFragment presentation = do
TitleSlide lvl is -> ActiveTitle $
Header lvl Pandoc.nullAttr is
ContentSlide blocks ->
let vars = variables $ blocksApplyFragments counters blocks
counters = triggersToCounters $ take fidx $
blocksTriggers blocks in
ActiveContent blocks vars counters
let vars = variables $ blocksReveal revealState blocks
revealState = blocksRevealStep fidx blocks in
ActiveContent blocks vars revealState


--------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 635d474

Please sign in to comment.