Skip to main content

wisp_storybook/stories/
s_graphics_rounded.rs

1//! Story: rounded-rect graphics primitive with SDF anti-aliasing (M0.12).
2
3use wisp::application::Application;
4use wisp::math::Rect;
5use wisp::{Color, Fill, Graphics, Stage, Stroke};
6
7use crate::story::Story;
8
9pub fn story() -> Story {
10    Story {
11        id: "graphics-rounded",
12        category: "Graphics",
13        title: "Rounded rect with stroke",
14        milestone: "M0.12 / M0.13",
15        writeup: include_str!("writeups/graphics_rounded.md"),
16        build,
17        tick: None,
18    }
19}
20
21fn build(_app: &Application, stage: &mut Stage) {
22    let mut g = Graphics::new();
23
24    // Filled rounded rect (no stroke).
25    g.fill(Fill::Solid(Color::rgba_u8(80, 200, 255, 255)));
26    g.draw_rounded_rect(Rect::new(-0.7, -0.6, 0.6, 0.6), 0.18);
27
28    // Outlined rounded rect — fill + stroke.
29    g.fill(Fill::Solid(Color::rgba_u8(255, 100, 80, 200)));
30    g.stroke(Some(Stroke::new(0.04, Color::rgba_u8(40, 20, 30, 255))));
31    g.draw_rounded_rect(Rect::new(0.1, -0.6, 0.6, 0.6), 0.12);
32
33    // Sharp rect (radius=0).
34    g.stroke(None);
35    g.fill(Fill::Solid(Color::rgba_u8(140, 220, 140, 255)));
36    g.draw_rect(Rect::new(-0.3, 0.2, 0.6, 0.4));
37
38    let _ = stage.add_child(stage.root(), g);
39}