wisp_storybook/story.rs
1//! `Story` trait + helper types.
2
3use wisp::Stage;
4use wisp::application::Application;
5
6/// One interactive demo registered in the storybook.
7///
8/// Each story is responsible for building a fresh `Stage` when its scene is
9/// requested. The optional `tick` hook lets a story animate per-frame (called
10/// before each render).
11pub struct Story {
12 /// Stable identifier — reserved for future URL-style navigation and
13 /// cross-session story bookmarking.
14 #[allow(
15 dead_code,
16 reason = "reserved for upcoming URL navigation + bookmark state"
17 )]
18 pub id: &'static str,
19 /// Category — groups stories in the picker (e.g. "Renderer Foundation",
20 /// "Scene Graph", "Graphics", "Filters").
21 pub category: &'static str,
22 /// Display title.
23 pub title: &'static str,
24 /// Milestone tag (e.g. "M0.5").
25 pub milestone: &'static str,
26 /// Markdown-flavored write-up shown in the right sidebar.
27 pub writeup: &'static str,
28 /// Build the scene from scratch. Called when the story is first selected.
29 pub build: fn(&Application, &mut Stage),
30 /// Optional per-frame animation hook. `t` is seconds since story start.
31 pub tick: Option<fn(&mut Stage, f32)>,
32}
33
34impl Story {
35 /// Resolve the per-frame hook, treating `None` as a no-op.
36 pub fn tick(&self, stage: &mut Stage, t: f32) {
37 if let Some(f) = self.tick {
38 f(stage, t);
39 }
40 }
41}