text.rs

 1use gpui::{
 2    blue, div, red, white, Div, ParentElement, Render, Styled, View, VisualContext, WindowContext,
 3};
 4use ui::v_stack;
 5
 6pub struct TextStory;
 7
 8impl TextStory {
 9    pub fn view(cx: &mut WindowContext) -> View<Self> {
10        cx.build_view(|cx| Self)
11    }
12}
13
14impl Render for TextStory {
15    type Element = Div;
16
17    fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {
18        v_stack()
19            .bg(blue())
20            .child(
21                div()
22                    .flex()
23                    .child(div().max_w_96().bg(white()).child(concat!(
24        "max-width: 96. The quick brown fox jumps over the lazy dog. ",
25        "Meanwhile, the lazy dog decided it was time for a change. ",
26        "He started daily workout routines, ate healthier and became the fastest dog in town.",
27    ))),
28            )
29            .child(div().h_5())
30            .child(div().flex().flex_col().w_96().bg(white()).child(concat!(
31        "flex-col. width: 96; The quick brown fox jumps over the lazy dog. ",
32        "Meanwhile, the lazy dog decided it was time for a change. ",
33        "He started daily workout routines, ate healthier and became the fastest dog in town.",
34    )))
35            .child(div().h_5())
36            .child(
37                div()
38                    .flex()
39                    .child(div().min_w_96().bg(white()).child(concat!(
40    "min-width: 96. The quick brown fox jumps over the lazy dog. ",
41    "Meanwhile, the lazy dog decided it was time for a change. ",
42    "He started daily workout routines, ate healthier and became the fastest dog in town.",
43))))
44            .child(div().h_5())
45            .child(div().flex().w_96().bg(white()).child(div().overflow_hidden().child(concat!(
46        "flex-row. width 96. overflow-hidden. The quick brown fox jumps over the lazy dog. ",
47        "Meanwhile, the lazy dog decided it was time for a change. ",
48        "He started daily workout routines, ate healthier and became the fastest dog in town.",
49    ))))
50            // NOTE: When rendering text in a horizonal flex container,
51            // Taffy will not pass width constraints down from the parent.
52            // To fix this, render text in a praent with overflow: hidden, which
53                    .child(div().h_5())
54                    .child(div().flex().w_96().bg(red()).child(concat!(
55                "flex-row. width 96. The quick brown fox jumps over the lazy dog. ",
56                "Meanwhile, the lazy dog decided it was time for a change. ",
57                "He started daily workout routines, ate healthier and became the fastest dog in town.",
58            )))
59    }
60}