diff --git a/src/nimiSlides.nim b/src/nimiSlides.nim index 73346cd..b680491 100644 --- a/src/nimiSlides.nim +++ b/src/nimiSlides.nim @@ -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 @@ -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): diff --git a/src/nimiSlides/autoAnimation.nim b/src/nimiSlides/autoAnimation.nim new file mode 100644 index 0000000..de7898b --- /dev/null +++ b/src/nimiSlides/autoAnimation.nim @@ -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 \ No newline at end of file diff --git a/src/nimiSlides/conversions.nim b/src/nimiSlides/conversions.nim new file mode 100644 index 0000000..bee2850 --- /dev/null +++ b/src/nimiSlides/conversions.nim @@ -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 \ No newline at end of file