text_wrapper.rs

 1use gpui::{
 2    div, prelude::*, px, size, App, Application, Bounds, Context, Window, WindowBounds,
 3    WindowOptions,
 4};
 5
 6struct HelloWorld {}
 7
 8impl Render for HelloWorld {
 9    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
10        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.";
11        div()
12            .id("page")
13            .size_full()
14            .flex()
15            .flex_col()
16            .p_2()
17            .gap_2()
18            .bg(gpui::white())
19            .child(
20                div()
21                    .flex()
22                    .flex_row()
23                    .gap_2()
24                    .child(
25                        div()
26                            .flex()
27                            .border_1()
28                            .border_color(gpui::red())
29                            .text_ellipsis()
30                            .child("longer text in flex 1"),
31                    )
32                    .child(
33                        div()
34                            .flex()
35                            .border_1()
36                            .border_color(gpui::red())
37                            .text_ellipsis()
38                            .child("short flex"),
39                    )
40                    .child(
41                        div()
42                            .overflow_hidden()
43                            .border_1()
44                            .border_color(gpui::red())
45                            .text_ellipsis()
46                            .w_full()
47                            .child("A short text in normal div"),
48                    ),
49            )
50            .child(
51                div()
52                    .text_xl()
53                    .overflow_hidden()
54                    .text_ellipsis()
55                    .border_1()
56                    .border_color(gpui::red())
57                    .child("ELLIPSIS: ".to_owned() + text),
58            )
59            .child(
60                div()
61                    .text_xl()
62                    .overflow_hidden()
63                    .truncate()
64                    .border_1()
65                    .border_color(gpui::green())
66                    .child("TRUNCATE: ".to_owned() + text),
67            )
68            .child(
69                div()
70                    .text_xl()
71                    .whitespace_nowrap()
72                    .overflow_hidden()
73                    .border_1()
74                    .border_color(gpui::blue())
75                    .child("NOWRAP: ".to_owned() + text),
76            )
77            .child(div().text_xl().w_full().child(text))
78    }
79}
80
81fn main() {
82    Application::new().run(|cx: &mut App| {
83        let bounds = Bounds::centered(None, size(px(600.0), px(480.0)), cx);
84        cx.open_window(
85            WindowOptions {
86                window_bounds: Some(WindowBounds::Windowed(bounds)),
87                ..Default::default()
88            },
89            |_, cx| cx.new(|_| HelloWorld {}),
90        )
91        .unwrap();
92    });
93}