label.rs

 1use std::time::Duration;
 2
 3use crate::{prelude::*, HighlightedLabel, Label};
 4use gpui::{pulsating_between, Animation, AnimationExt, Render};
 5use story::Story;
 6
 7pub struct LabelStory;
 8
 9impl Render for LabelStory {
10    fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
11        Story::container()
12            .child(Story::title_for::<Label>())
13            .child(Story::label("Default"))
14            .child(Label::new("Hello, world!"))
15            .child(Story::label("Highlighted"))
16            .child(HighlightedLabel::new(
17                "Hello, world!",
18                vec![0, 1, 2, 7, 8, 12],
19            ))
20            .child(HighlightedLabel::new(
21                "Héllo, world!",
22                vec![0, 1, 3, 8, 9, 13],
23            ))
24            .child(Story::label("Highlighted with `color`"))
25            .child(
26                HighlightedLabel::new("Hello, world!", vec![0, 1, 2, 7, 8, 12]).color(Color::Error),
27            )
28            .child(
29                Label::new("This text is pulsating").with_animation(
30                    "pulsating-label",
31                    Animation::new(Duration::from_secs(2))
32                        .repeat()
33                        .with_easing(pulsating_between(0.4, 0.8)),
34                    |label, delta| label.alpha(delta),
35                ),
36            )
37    }
38}