edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching·0 forks·Rust·18.3 MiB·bcb4dc5·Tahinli·21 days ago·1034 commits
| 1 | use gpui::{ |
| 2 | App, AppContext, Application, Bounds, Context, Window, WindowBounds, WindowOptions, div, |
| 3 | linear_color_stop, linear_gradient, pattern_slash, prelude::*, px, rgb, size, |
| 4 | }; |
| 5 | |
| 6 | struct PatternExample; |
| 7 | |
| 8 | impl Render for PatternExample { |
| 9 | fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement { |
| 10 | div() |
| 11 | .flex() |
| 12 | .flex_col() |
| 13 | .gap_3() |
| 14 | .bg(rgb(0xffffff)) |
| 15 | .size(px(600.0)) |
| 16 | .justify_center() |
| 17 | .items_center() |
| 18 | .shadow_lg() |
| 19 | .text_xl() |
| 20 | .text_color(rgb(0x000000)) |
| 21 | .child("Pattern Example") |
| 22 | .child( |
| 23 | div() |
| 24 | .flex() |
| 25 | .flex_col() |
| 26 | .border_1() |
| 27 | .border_color(gpui::blue()) |
| 28 | .child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash( |
| 29 | gpui::red(), |
| 30 | 18.0 / 4.0, |
| 31 | 18.0 / 4.0, |
| 32 | ))) |
| 33 | .child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash( |
| 34 | gpui::red(), |
| 35 | 18.0 / 4.0, |
| 36 | 18.0 / 4.0, |
| 37 | ))) |
| 38 | .child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash( |
| 39 | gpui::red(), |
| 40 | 18.0 / 4.0, |
| 41 | 18.0 / 4.0, |
| 42 | ))) |
| 43 | .child(div().w(px(54.0)).h(px(18.0)).bg(pattern_slash( |
| 44 | gpui::red(), |
| 45 | 18.0 / 4.0, |
| 46 | 18.0 / 2.0, |
| 47 | ))), |
| 48 | ) |
| 49 | .child( |
| 50 | div() |
| 51 | .flex() |
| 52 | .flex_col() |
| 53 | .border_1() |
| 54 | .border_color(gpui::blue()) |
| 55 | .bg(gpui::green().opacity(0.16)) |
| 56 | .child("Elements the same height should align") |
| 57 | .child(div().w(px(256.0)).h(px(56.0)).bg(pattern_slash( |
| 58 | gpui::red(), |
| 59 | 56.0 / 6.0, |
| 60 | 56.0 / 6.0, |
| 61 | ))) |
| 62 | .child(div().w(px(256.0)).h(px(56.0)).bg(pattern_slash( |
| 63 | gpui::green(), |
| 64 | 56.0 / 6.0, |
| 65 | 56.0 / 6.0, |
| 66 | ))) |
| 67 | .child(div().w(px(256.0)).h(px(56.0)).bg(pattern_slash( |
| 68 | gpui::blue(), |
| 69 | 56.0 / 6.0, |
| 70 | 56.0 / 6.0, |
| 71 | ))) |
| 72 | .child(div().w(px(256.0)).h(px(26.0)).bg(pattern_slash( |
| 73 | gpui::yellow(), |
| 74 | 56.0 / 6.0, |
| 75 | 56.0 / 6.0, |
| 76 | ))), |
| 77 | ) |
| 78 | .child( |
| 79 | div() |
| 80 | .border_1() |
| 81 | .border_color(gpui::blue()) |
| 82 | .w(px(240.0)) |
| 83 | .h(px(40.0)) |
| 84 | .bg(gpui::red()), |
| 85 | ) |
| 86 | .child( |
| 87 | div() |
| 88 | .border_1() |
| 89 | .border_color(gpui::blue()) |
| 90 | .w(px(240.0)) |
| 91 | .h(px(40.0)) |
| 92 | .bg(linear_gradient( |
| 93 | 45., |
| 94 | linear_color_stop(gpui::red(), 0.), |
| 95 | linear_color_stop(gpui::blue(), 1.), |
| 96 | )), |
| 97 | ) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | fn main() { |
| 102 | Application::new().run(|cx: &mut App| { |
| 103 | let bounds = Bounds::centered(None, size(px(600.0), px(600.0)), cx); |
| 104 | cx.open_window( |
| 105 | WindowOptions { |
| 106 | window_bounds: Some(WindowBounds::Windowed(bounds)), |
| 107 | ..Default::default() |
| 108 | }, |
| 109 | |_window, cx| cx.new(|_cx| PatternExample), |
| 110 | ) |
| 111 | .unwrap(); |
| 112 | |
| 113 | cx.activate(true); |
| 114 | }); |
| 115 | } |