1use gpui::{
2 App, Application, Bounds, Context, TextOverflow, Window, WindowBounds, WindowOptions, div,
3 prelude::*, px, 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 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 .flex_shrink_0()
24 .gap_2()
25 .child(
26 div()
27 .flex()
28 .border_1()
29 .border_color(gpui::red())
30 .text_ellipsis()
31 .child("longer text in flex 1"),
32 )
33 .child(
34 div()
35 .flex()
36 .border_1()
37 .border_color(gpui::red())
38 .text_ellipsis()
39 .child("short flex"),
40 )
41 .child(
42 div()
43 .overflow_hidden()
44 .border_1()
45 .border_color(gpui::red())
46 .text_ellipsis()
47 .w_full()
48 .child("A short text in normal div"),
49 ),
50 )
51 .child(
52 div()
53 .flex_shrink_0()
54 .text_xl()
55 .truncate()
56 .border_1()
57 .border_color(gpui::blue())
58 .child("ELLIPSIS: ".to_owned() + text),
59 )
60 .child(
61 div()
62 .flex_shrink_0()
63 .text_xl()
64 .overflow_hidden()
65 .text_ellipsis()
66 .line_clamp(2)
67 .border_1()
68 .border_color(gpui::blue())
69 .child("ELLIPSIS 2 lines: ".to_owned() + text),
70 )
71 .child(
72 div()
73 .flex_shrink_0()
74 .text_xl()
75 .overflow_hidden()
76 .text_overflow(TextOverflow::Truncate("".into()))
77 .border_1()
78 .border_color(gpui::green())
79 .child("TRUNCATE: ".to_owned() + text),
80 )
81 .child(
82 div()
83 .flex_shrink_0()
84 .text_xl()
85 .overflow_hidden()
86 .text_overflow(TextOverflow::Truncate("".into()))
87 .line_clamp(3)
88 .border_1()
89 .border_color(gpui::green())
90 .child("TRUNCATE 3 lines: ".to_owned() + text),
91 )
92 .child(
93 div()
94 .flex_shrink_0()
95 .text_xl()
96 .whitespace_nowrap()
97 .overflow_hidden()
98 .border_1()
99 .border_color(gpui::black())
100 .child("NOWRAP: ".to_owned() + text),
101 )
102 .child(div().text_xl().w_full().child(text))
103 }
104}
105
106fn main() {
107 Application::new().run(|cx: &mut App| {
108 let bounds = Bounds::centered(None, size(px(800.0), px(600.0)), cx);
109 cx.open_window(
110 WindowOptions {
111 window_bounds: Some(WindowBounds::Windowed(bounds)),
112 ..Default::default()
113 },
114 |_, cx| cx.new(|_| HelloWorld {}),
115 )
116 .unwrap();
117 cx.activate(true);
118 });
119}