Skip to content

Commit

Permalink
refactor and implement autoAnimateSlides template
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoGranstrom committed Nov 15, 2023
1 parent cbecb1e commit 9960246
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/nimiSlides.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import nimib
import nimib/[capture, config]
import markdown

import nimiSlides/[autoAnimation, conversions]
export autoAnimation, conversions

type
FragmentAnimation* = enum
fadeIn = "fade-in" # the default
Expand Down Expand Up @@ -396,24 +399,6 @@ template listItem*(animation: FragmentAnimation, body: untyped) =

template listItem*(body: untyped) =
listItem(fadeInThenSemiOut, body)


proc toHSlice*(h: HSlice[int, int]): HSlice[int, int] = h
proc toHSlice*(h: int): HSlice[int, int] = h .. h


proc toSet*(x: set[range[0..65535]]): set[range[0..65535]] = x
proc toSet*(x: int): set[range[0..65535]] = {x}
proc toSet*(x: Slice[int]): set[range[0..65535]] =
for y in x:
result.incl y
proc toSet*(x: seq[Slice[int]]): set[range[0..65535]] =
for s in x:
result.incl s.toSet()
proc toSet*(x: set[range[0..255]]): set[range[0..65535]] =
for y in x:
result.incl y


template animateCode*(lines: string, body: untyped) =
newNbCodeBlock("animateCode", body):
Expand Down
19 changes: 19 additions & 0 deletions src/nimiSlides/autoAnimation.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import nimib
import ./[conversions]

template autoAnimateSlides*(nSlides: int, body: untyped) =
for autoAnimateCounter {.inject.} in 1 .. nSlides:
slide(slideOptions(autoAnimate=true)):
body

template showOn*(showOnSlides: varargs[set[range[0..65535]], toSet], body: untyped) = # how to auto convert to set like in varargs?
# use vararg and union all results!
# This way you don't need to use the set syntax but can pass in `showOn(1, 2, 3)` instead.
var totalSet: set[range[0..65535]]
for x in showOnSlides:
totalSet.incl x

if autoAnimateCounter in totalSet:
body
# The if-statement will cause some troubles for some code if it assumes it will be run in the same scope :/
# To fix that we would need to require static inputs
15 changes: 15 additions & 0 deletions src/nimiSlides/conversions.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
proc toHSlice*(h: HSlice[int, int]): HSlice[int, int] = h
proc toHSlice*(h: int): HSlice[int, int] = h .. h


proc toSet*(x: set[range[0..65535]]): set[range[0..65535]] = x
proc toSet*(x: int): set[range[0..65535]] = {x}
proc toSet*(x: Slice[int]): set[range[0..65535]] =
for y in x:
result.incl y
proc toSet*(x: seq[Slice[int]]): set[range[0..65535]] =
for s in x:
result.incl s.toSet()
proc toSet*(x: set[range[0..255]]): set[range[0..65535]] =
for y in x:
result.incl y

0 comments on commit 9960246

Please sign in to comment.