edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching·0 forks·Rust·18.3 MiB·ff99ad6·Tahinli·6 days ago·1055 commits
| 1 | use gpui::{ |
| 2 | App, Application, Bounds, Context, TextOverflow, Window, WindowBounds, WindowOptions, div, |
| 3 | prelude::*, px, size, |
| 4 | }; |
| 5 | |
| 6 | struct HelloWorld {} |
| 7 | |
| 8 | impl 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 \ |
| 11 | English language dictionaries is pneumonoultramicroscopicsilicovolcanoconiosis, a word that \ |
| 12 | refers to a lung disease contracted from the inhalation of very fine silica particles, \ |
| 13 | a url https://github.com/zed-industries/zed/pull/35724?query=foo&bar=2, \ |
| 14 | specifically from a volcano; medically, it is the same as silicosis."; |
| 15 | div() |
| 16 | .id("page") |
| 17 | .size_full() |
| 18 | .flex() |
| 19 | .flex_col() |
| 20 | .p_2() |
| 21 | .gap_2() |
| 22 | .bg(gpui::white()) |
| 23 | .child( |
| 24 | div() |
| 25 | .flex() |
| 26 | .flex_row() |
| 27 | .flex_shrink_0() |
| 28 | .gap_2() |
| 29 | .child( |
| 30 | div() |
| 31 | .flex() |
| 32 | .border_1() |
| 33 | .border_color(gpui::red()) |
| 34 | .text_ellipsis() |
| 35 | .child("longer text in flex 1"), |
| 36 | ) |
| 37 | .child( |
| 38 | div() |
| 39 | .flex() |
| 40 | .border_1() |
| 41 | .border_color(gpui::red()) |
| 42 | .text_ellipsis() |
| 43 | .child("short flex"), |
| 44 | ) |
| 45 | .child( |
| 46 | div() |
| 47 | .overflow_hidden() |
| 48 | .border_1() |
| 49 | .border_color(gpui::red()) |
| 50 | .text_ellipsis() |
| 51 | .w_full() |
| 52 | .child("A short text in normal div"), |
| 53 | ), |
| 54 | ) |
| 55 | .child( |
| 56 | div() |
| 57 | .flex_shrink_0() |
| 58 | .text_xl() |
| 59 | .truncate() |
| 60 | .border_1() |
| 61 | .border_color(gpui::blue()) |
| 62 | .child("ELLIPSIS: ".to_owned() + text), |
| 63 | ) |
| 64 | .child( |
| 65 | div() |
| 66 | .flex_shrink_0() |
| 67 | .text_xl() |
| 68 | .overflow_hidden() |
| 69 | .text_ellipsis() |
| 70 | .line_clamp(2) |
| 71 | .border_1() |
| 72 | .border_color(gpui::blue()) |
| 73 | .child("ELLIPSIS 2 lines: ".to_owned() + text), |
| 74 | ) |
| 75 | .child( |
| 76 | div() |
| 77 | .flex_shrink_0() |
| 78 | .text_xl() |
| 79 | .overflow_hidden() |
| 80 | .text_overflow(TextOverflow::Truncate("".into())) |
| 81 | .border_1() |
| 82 | .border_color(gpui::green()) |
| 83 | .child("TRUNCATE: ".to_owned() + text), |
| 84 | ) |
| 85 | .child( |
| 86 | div() |
| 87 | .flex_shrink_0() |
| 88 | .text_xl() |
| 89 | .overflow_hidden() |
| 90 | .text_overflow(TextOverflow::Truncate("".into())) |
| 91 | .line_clamp(3) |
| 92 | .border_1() |
| 93 | .border_color(gpui::green()) |
| 94 | .child("TRUNCATE 3 lines: ".to_owned() + text), |
| 95 | ) |
| 96 | .child( |
| 97 | div() |
| 98 | .flex_shrink_0() |
| 99 | .text_xl() |
| 100 | .whitespace_nowrap() |
| 101 | .overflow_hidden() |
| 102 | .border_1() |
| 103 | .border_color(gpui::black()) |
| 104 | .child("NOWRAP: ".to_owned() + text), |
| 105 | ) |
| 106 | .child(div().text_xl().w_full().child(text)) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | fn main() { |
| 111 | Application::new().run(|cx: &mut App| { |
| 112 | let bounds = Bounds::centered(None, size(px(800.0), px(600.0)), cx); |
| 113 | cx.open_window( |
| 114 | WindowOptions { |
| 115 | window_bounds: Some(WindowBounds::Windowed(bounds)), |
| 116 | ..Default::default() |
| 117 | }, |
| 118 | |_, cx| cx.new(|_| HelloWorld {}), |
| 119 | ) |
| 120 | .unwrap(); |
| 121 | cx.activate(true); |
| 122 | }); |
| 123 | } |