Skip to main content

wisp_storybook/stories/
s_vector_gallery.rs

1//! Story: vector primitive examples gallery (M-VEC.12 / AUT-64).
2//!
3//! Single-canvas overview of the M-VEC catalog. Each existing
4//! storybook entry deep-dives one primitive; this one shows the
5//! whole stack in one glance so reviewers can scan the surface
6//! quickly before clicking through.
7
8use glam::Vec2;
9use wisp::application::Application;
10use wisp::math::Rect;
11use wisp::{Callout, Color, Fill, Highlight, PathBuilder, Stage, VectorShape, VectorStroke};
12
13use crate::story::Story;
14
15pub fn story() -> Story {
16    Story {
17        id: "vector-gallery",
18        category: "Vector",
19        title: "Examples gallery",
20        milestone: "M-VEC.12 / AUT-64",
21        writeup: include_str!("writeups/vector_gallery.md"),
22        build,
23        tick: None,
24    }
25}
26
27fn build(_app: &Application, stage: &mut Stage) {
28    let root = stage.root();
29
30    // Top row — basic shape primitives.
31    add_shape_tile(
32        stage,
33        root,
34        VectorShape::rect(Rect::new(-1.0, -1.0, 2.0, 2.0)),
35        Color::rgba_u8(80, 180, 200, 255),
36        Vec2::new(-0.7, 0.55),
37        0.08,
38    );
39    add_shape_tile(
40        stage,
41        root,
42        VectorShape::rounded_rect(Rect::new(-1.0, -1.0, 2.0, 2.0), 0.25),
43        Color::rgba_u8(220, 170, 80, 255),
44        Vec2::new(-0.4, 0.55),
45        0.08,
46    );
47    add_shape_tile(
48        stage,
49        root,
50        VectorShape::circle(Vec2::ZERO, 1.0),
51        Color::rgba_u8(220, 80, 130, 255),
52        Vec2::new(-0.1, 0.55),
53        0.08,
54    );
55    add_shape_tile(
56        stage,
57        root,
58        VectorShape::ellipse(Vec2::ZERO, Vec2::new(1.0, 0.55)),
59        Color::rgba_u8(120, 200, 130, 255),
60        Vec2::new(0.2, 0.55),
61        0.08,
62    );
63
64    // Top right — highlight outline.
65    let outline = Highlight::outline(
66        VectorShape::rounded_rect(Rect::new(0.45, 0.45, 0.25, 0.20), 0.05),
67        Color::rgba_u8(255, 230, 80, 255),
68        0.018,
69    );
70    let _ = outline.add_to_stage(stage, root);
71
72    // Middle row — arrow + Bezier curve.
73    let arrow = Callout::arrow_to(
74        Vec2::new(-0.7, 0.15),
75        Vec2::new(-0.1, 0.15),
76        0.022,
77        Color::rgba_u8(255, 230, 80, 255),
78    );
79    let _ = stage.add_child(root, arrow);
80
81    let curve = PathBuilder::new()
82        .move_to(Vec2::new(0.05, 0.1))
83        .quad_to(Vec2::new(0.35, 0.3), Vec2::new(0.65, 0.1))
84        .build()
85        .stroke_to_graphics(0.022, Color::rgba_u8(80, 200, 240, 255), 0.005);
86    let _ = stage.add_child(root, curve);
87
88    // Lower row — callout label box + badge.
89    let label = Callout::label_box(
90        Rect::new(-0.7, -0.35, 0.55, 0.18),
91        Color::rgba_u8(220, 170, 80, 230),
92        Some(VectorStroke::new(0.01, Color::WHITE)),
93        0.04,
94    );
95    let _ = label.add_to_stage(stage, root);
96
97    let badge = Callout::badge(
98        Vec2::new(0.0, -0.26),
99        0.085,
100        Color::rgba_u8(220, 60, 50, 255),
101    );
102    let _ = badge.add_to_stage(stage, root);
103
104    // Translucent pill highlight.
105    let pill = Highlight::pill(
106        Rect::new(0.2, -0.32, 0.55, 0.13),
107        Color::rgba_u8(80, 220, 240, 255),
108        0.5,
109    );
110    let _ = pill.add_to_stage(stage, root);
111
112    // Bottom — caption pill.
113    let caption = Callout::caption_pill(
114        Rect::new(-0.5, -0.7, 1.0, 0.08),
115        Color::rgba_u8(40, 50, 70, 240),
116    );
117    let _ = caption.add_to_stage(stage, root);
118}
119
120fn add_shape_tile(
121    stage: &mut Stage,
122    parent: wisp::NodeId,
123    shape: VectorShape,
124    color: Color,
125    pos: Vec2,
126    scale: f32,
127) {
128    let v = wisp::Vector::new(shape)
129        .with_fill(Fill::Solid(color))
130        .with_transform(wisp::Transform {
131            position: pos,
132            scale: Vec2::splat(scale),
133            ..wisp::Transform::default()
134        });
135    let _ = v.add_to_stage(stage, parent);
136}