Skip to content

Commit e378c34

Browse files
feat(lib/html): adding vertical slides to export to html (#602)
1 parent 33f20fe commit e378c34

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
(unreleased)=
1111
## [Unreleased](https://github.com/jeertmans/manim-slides/compare/v5.5.4...HEAD)
1212

13+
### Added
14+
15+
- Added vertical slide implementation to html exports of presentations. [@DaughterOfSpring](https://github.com/daughterOfSpring) [#602](https://github.com/jeertmans/manim-slides/pull/602)
16+
1317
(v5.5.4)=
1418
## [v5.5.4](https://github.com/jeertmans/manim-slides/compare/v5.5.3...v5.5.4)
1519

docs/source/reference/html.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,72 @@ or printed with the `--show-template` option.
3535
If you wish to use another template, you can do so with the
3636
`--use-template FILE` option.
3737

38+
## Vertical Slides
39+
40+
Slides default to a "horizontal" arrangement by default. This means that each
41+
slide follows the next in a linear progression. If you instead wish to add
42+
an additional dimension to your slides and have "vertical" groupings under a
43+
given "horizontal" slide, you may pass the keyword argument "direction" to the
44+
{meth}`next_slide<manim_slides.slide.Slide.next_slide>`
45+
method and give it the argument "vertical". The "horizontal" slides
46+
will be the main progression of your presentation accessible by tabbing left
47+
or right using those arrow keys. For "vertical" slides you move to the "horizontal"
48+
parent slide and use the up and down keys to navigate through the slides that are
49+
grouped under the initial slide. You may still use the left/right navigation to
50+
move from any slide in the vertical stack to the next "horizontal" slide.
51+
52+
In the following example we have only the linear "horizontal" slides.
53+
Note that no direction argument is passed to
54+
{meth}`self.next_slide()<manim_slides.slide.Slide.next_slide>`.
55+
56+
```{eval-rst}
57+
.. manim-slides:: HorizontalSlides
58+
:config_options: slide_number=true
59+
60+
from manim import *
61+
from manim_slides import Slide
62+
63+
class HorizontalSlides(Slide):
64+
def construct(self):
65+
circle = Circle(radius=3, color=BLUE)
66+
dot = Dot()
67+
68+
self.play(GrowFromCenter(circle))
69+
70+
self.next_slide(loop=True)
71+
self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
72+
self.next_slide()
73+
74+
self.play(dot.animate.move_to(ORIGIN))
75+
```
76+
77+
In this example the second slide is a "vertical" slide so the left right progression
78+
moves from slide 1 to slide 3, while to access slide 2 you must be on slide 1 and
79+
press the down key.
80+
81+
```{eval-rst}
82+
.. manim-slides:: VerticalAndHorizontalSlides
83+
:config_options: slide_number=true
84+
85+
from manim import *
86+
from manim_slides import Slide
87+
88+
class VerticalAndHorizontalSlides(Slide):
89+
def construct(self):
90+
circle = Circle(radius=3, color=BLUE)
91+
dot = Dot()
92+
93+
self.play(GrowFromCenter(circle))
94+
95+
self.next_slide(direction="vertical", loop=True)
96+
self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
97+
self.next_slide(direction="vertical")
98+
99+
self.play(dot.animate.move_to(ORIGIN))
100+
```
101+
102+
For more information about vertical slides see <https://revealjs.com/vertical-slides/>.
103+
38104
## More about HTML Slides
39105

40106
You can read more about HTML slides in the [sharing](/reference/sharing) section.

manim_slides/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from inspect import Parameter, signature
55
from pathlib import Path
66
from textwrap import dedent
7-
from typing import Any, Callable, Optional
7+
from typing import Any, Callable, Literal, Optional
88

99
import rtoml
1010
from pydantic import (
@@ -162,6 +162,7 @@ class BaseSlideConfig(BaseModel): # type: ignore
162162
dedent_notes: bool = True
163163
skip_animations: bool = False
164164
src: Optional[FilePath] = None
165+
direction: Literal["horizontal", "vertical"] = "horizontal"
165166

166167
@classmethod
167168
def wrapper(cls, arg_name: str) -> Callable[..., Any]:

manim_slides/slide/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ def next_slide(
353353
354354
The video will be copied into the output folder, but no rescaling
355355
is applied.
356+
:param direction:
357+
Optional variable used to set slide direction.
358+
359+
.. warning::
360+
361+
Only supported by ``manim-slides convert --to=html``.
356362
:param kwargs:
357363
Keyword arguments passed to
358364
:meth:`Scene.next_section<manim.scene.scene.Scene.next_section>`,

manim_slides/templates/revealjs.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@
1919
<div class="reveal">
2020
<div class="slides">
2121
{% for presentation_config in presentation_configs -%}
22+
{% set ns = namespace(open_stack=false) %}
2223
{%- set outer_loop = loop %}
2324
{% for slide_config in presentation_config.slides %}
2425
{% if one_file %}
2526
{% set file = file_to_data_uri(slide_config.file) %}
2627
{% else %}
2728
{% set file = assets_dir / (prefix(outer_loop.index0) + slide_config.file.name) %}
2829
{% endif %}
30+
{% if slide_config.direction == "vertical" %}
31+
{% if not ns.open_stack %}
32+
<section>
33+
{% set ns.open_stack = true %}
34+
{% endif %}
35+
{% else %}
36+
{% if ns.open_stack %}
37+
</section>
38+
{% set ns.open_stack = false %}
39+
{% endif %}
40+
{% endif %}
2941
<section
3042
data-background-size={{ background_size }}
3143
data-background-color="{{ presentation_config.background_color }}"
@@ -45,6 +57,9 @@
4557
{% endif %}
4658
</section>
4759
{% endfor %}
60+
{% if ns.open_stack %}
61+
</section>
62+
{% endif %}
4863
{% endfor %}
4964
</div>
5065
</div>

0 commit comments

Comments
 (0)