-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and implement autoAnimateSlides template
- Loading branch information
1 parent
cbecb1e
commit 9960246
Showing
3 changed files
with
37 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |