text_layout.rs

 1use gpui::{
 2    App, Application, Bounds, Context, Window, WindowBounds, WindowOptions, div, prelude::*, px,
 3    size,
 4};
 5
 6struct HelloWorld {}
 7
 8impl Render for HelloWorld {
 9    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
10        div()
11            .bg(gpui::white())
12            .flex()
13            .flex_col()
14            .gap_2()
15            .p_4()
16            .size_full()
17            .child(div().child("Text left"))
18            .child(div().text_center().child("Text center"))
19            .child(div().text_right().child("Text right"))
20            .child(div().text_decoration_1().child("Text left (underline)"))
21            .child(
22                div()
23                    .text_center()
24                    .text_decoration_1()
25                    .child("Text center (underline)"),
26            )
27            .child(
28                div()
29                    .text_right()
30                    .text_decoration_1()
31                    .child("Text right (underline)"),
32            )
33            .child(div().line_through().child("Text left (line_through)"))
34            .child(
35                div()
36                    .text_center()
37                    .line_through()
38                    .child("Text center (line_through)"),
39            )
40            .child(
41                div()
42                    .text_right()
43                    .line_through()
44                    .child("Text right (line_through)"),
45            )
46            .child(
47                div()
48                    .flex()
49                    .gap_2()
50                    .justify_between()
51                    .child(
52                        div()
53                            .w(px(400.))
54                            .border_1()
55                            .border_color(gpui::blue())
56                            .p_1()
57                            .whitespace_nowrap()
58                            .overflow_hidden()
59                            .text_center()
60                            .child("A long non-wrapping text align center"),
61                    )
62                    .child(
63                        div()
64                            .w_32()
65                            .border_1()
66                            .border_color(gpui::blue())
67                            .p_1()
68                            .whitespace_nowrap()
69                            .overflow_hidden()
70                            .text_right()
71                            .child("100%"),
72                    ),
73            )
74    }
75}
76
77fn main() {
78    Application::new().run(|cx: &mut App| {
79        let bounds = Bounds::centered(None, size(px(800.0), px(600.0)), cx);
80        cx.open_window(
81            WindowOptions {
82                window_bounds: Some(WindowBounds::Windowed(bounds)),
83                ..Default::default()
84            },
85            |_, cx| cx.new(|_| HelloWorld {}),
86        )
87        .unwrap();
88        cx.activate(true);
89    });
90}