motion_canvas_rs/runtime/mod.rs
1//! Runtime modules for rendering and interacting with animations.
2//!
3//! This module provides the glue between the core animation engine and the
4//! physical output devices (Window/Screen) or files (Export).
5
6pub mod renderer;
7pub mod window;
8
9#[cfg(feature = "export")]
10pub mod export;
11
12use crate::Project;
13
14/// Extension trait to provide ergonomic runtime methods to [`Project`].
15///
16/// This trait keeps the core `Project` struct free of side-effects while
17/// allowing for a simple `.show()` or `.export()` API.
18pub trait ProjectRuntimeExt {
19 /// Opens the playback window for the project.
20 ///
21 /// This will initialize a `winit` event loop and a Vello renderer to
22 /// provide an interactive preview of the animation.
23 ///
24 /// ### Example
25 /// ```no_run
26 /// # use motion_canvas_rs::prelude::*;
27 /// # let project = Project::default();
28 /// project.show().expect("Failed to open window");
29 /// ```
30 fn show(self) -> crate::Result<()>;
31
32 /// Starts an export session for the project.
33 ///
34 /// This will render every frame of the project at full resolution and save
35 /// them to the configured output path.
36 ///
37 /// ### Example
38 /// ```no_run
39 /// # use motion_canvas_rs::prelude::*;
40 /// # let mut project = Project::default();
41 /// project.export().expect("Failed to export project");
42 /// ```
43 #[cfg(feature = "export")]
44 fn export(&mut self) -> crate::Result<()>;
45}
46
47impl ProjectRuntimeExt for Project {
48 fn show(self) -> crate::Result<()> {
49 self::window::run_window_session(self)
50 }
51
52 #[cfg(feature = "export")]
53 fn export(&mut self) -> crate::Result<()> {
54 self::export::run_export_session(self)
55 }
56}