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