text_wrapper.rs

 1use gpui::*;
 2
 3struct HelloWorld {}
 4
 5impl Render for HelloWorld {
 6    fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
 7        let text = "The longest word in any of the major English language δ»₯εŠδΈ­ζ–‡ηš„ζ΅‹θ―• dictionaries is pneumonoultramicroscopicsilicovolcanoconiosis, a word that refers to a lung disease contracted from the inhalation of very fine silica particles, specifically from a volcano; medically, it is the same as silicosis.";
 8        div()
 9            .id("page")
10            .size_full()
11            .flex()
12            .flex_col()
13            .p_2()
14            .gap_2()
15            .bg(gpui::white())
16            .child(
17                div()
18                    .text_xl()
19                    .overflow_hidden()
20                    .text_ellipsis()
21                    .border_1()
22                    .border_color(gpui::red())
23                    .child("ELLIPSIS: ".to_owned() + text),
24            )
25            .child(
26                div()
27                    .text_xl()
28                    .overflow_hidden()
29                    .truncate()
30                    .border_1()
31                    .border_color(gpui::green())
32                    .child("TRUNCATE: ".to_owned() + text),
33            )
34            .child(
35                div()
36                    .text_xl()
37                    .whitespace_nowrap()
38                    .overflow_hidden()
39                    .border_1()
40                    .border_color(gpui::blue())
41                    .child("NOWRAP: ".to_owned() + text),
42            )
43            .child(div().text_xl().w_full().child(text))
44    }
45}
46
47fn main() {
48    App::new().run(|cx: &mut AppContext| {
49        let bounds = Bounds::centered(None, size(px(600.0), px(480.0)), cx);
50        cx.open_window(
51            WindowOptions {
52                window_bounds: Some(WindowBounds::Windowed(bounds)),
53                ..Default::default()
54            },
55            |cx| cx.new_view(|_cx| HelloWorld {}),
56        )
57        .unwrap();
58    });
59}