wisp_storybook/stories/
s_text_texture.rs1use glam::Vec2;
5use wisp::application::Application;
6use wisp::text::{TextTexturePipeline, WispText, WispTextStyle};
7use wisp::{Color, Sprite, Stage, WispFontWeight};
8
9use crate::story::Story;
10
11pub fn story() -> Story {
12 Story {
13 id: "text-texture",
14 category: "Scene Graph",
15 title: "Text → RenderTexture → Sprite",
16 milestone: "M-TEXT.5",
17 writeup: include_str!("writeups/text_texture.md"),
18 build,
19 tick: None,
20 }
21}
22
23fn build(app: &Application, stage: &mut Stage) {
24 let pipeline = TextTexturePipeline::new(app, wgpu::TextureFormat::Rgba8UnormSrgb);
27
28 let hero = WispText::new("Text → texture").with_style(
31 WispTextStyle::default()
32 .with_size(0.20)
33 .with_weight(WispFontWeight::Bold)
34 .with_color(Color::rgba(1.0, 0.9, 0.4, 1.0)),
35 );
36
37 let rt = pipeline.render(app, &hero, 1536, 320);
38 let texture = rt.as_texture();
39
40 let mut sprite = Sprite::from_texture(texture).with_anchor(Vec2::new(0.5, 0.5));
45 sprite.container.transform.position = Vec2::new(0.0, 0.3);
46 sprite.container.transform.scale = Vec2::new(1.7, -0.85);
47 let _ = stage.add_child(stage.root(), sprite);
48
49 let caption = WispText::new("cached + composed").with_style(
53 WispTextStyle::default()
54 .with_size(0.30)
55 .with_color(Color::rgba(0.55, 0.85, 1.0, 1.0)),
56 );
57 let caption_rt = pipeline.render(app, &caption, 768, 256);
58 let caption_tex = caption_rt.as_texture();
59 let mut caption_sprite = Sprite::from_texture(caption_tex).with_anchor(Vec2::new(0.5, 0.5));
60 caption_sprite.container.transform.position = Vec2::new(0.0, -0.55);
61 caption_sprite.container.transform.scale = Vec2::new(1.5, -0.5);
62 let _ = stage.add_child(stage.root(), caption_sprite);
63}