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, FocusHandle, KeyBinding, Window, WindowBounds, |
| 3 | WindowOptions, actions, div, prelude::*, px, rgb, size, |
| 4 | }; |
| 5 | |
| 6 | actions!(example, [CloseWindow]); |
| 7 | |
| 8 | struct ExampleWindow { |
| 9 | focus_handle: FocusHandle, |
| 10 | } |
| 11 | |
| 12 | impl Render for ExampleWindow { |
| 13 | fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement { |
| 14 | div() |
| 15 | .on_action(|_: &CloseWindow, window, _| { |
| 16 | window.remove_window(); |
| 17 | }) |
| 18 | .track_focus(&self.focus_handle) |
| 19 | .flex() |
| 20 | .flex_col() |
| 21 | .gap_3() |
| 22 | .bg(rgb(0x505050)) |
| 23 | .size(px(500.0)) |
| 24 | .justify_center() |
| 25 | .items_center() |
| 26 | .shadow_lg() |
| 27 | .border_1() |
| 28 | .border_color(rgb(0x0000ff)) |
| 29 | .text_xl() |
| 30 | .text_color(rgb(0xffffff)) |
| 31 | .child( |
| 32 | "Closing this window with cmd-w or the traffic lights should quit the application!", |
| 33 | ) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | fn main() { |
| 38 | Application::new().run(|cx: &mut App| { |
| 39 | let mut bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx); |
| 40 | |
| 41 | cx.bind_keys([KeyBinding::new("cmd-w", CloseWindow, None)]); |
| 42 | cx.on_window_closed(|cx| { |
| 43 | if cx.windows().is_empty() { |
| 44 | cx.quit(); |
| 45 | } |
| 46 | }) |
| 47 | .detach(); |
| 48 | |
| 49 | cx.open_window( |
| 50 | WindowOptions { |
| 51 | window_bounds: Some(WindowBounds::Windowed(bounds)), |
| 52 | ..Default::default() |
| 53 | }, |
| 54 | |window, cx| { |
| 55 | cx.activate(false); |
| 56 | cx.new(|cx| { |
| 57 | let focus_handle = cx.focus_handle(); |
| 58 | focus_handle.focus(window); |
| 59 | ExampleWindow { focus_handle } |
| 60 | }) |
| 61 | }, |
| 62 | ) |
| 63 | .unwrap(); |
| 64 | |
| 65 | bounds.origin.x += bounds.size.width; |
| 66 | |
| 67 | cx.open_window( |
| 68 | WindowOptions { |
| 69 | window_bounds: Some(WindowBounds::Windowed(bounds)), |
| 70 | ..Default::default() |
| 71 | }, |
| 72 | |window, cx| { |
| 73 | cx.new(|cx| { |
| 74 | let focus_handle = cx.focus_handle(); |
| 75 | focus_handle.focus(window); |
| 76 | ExampleWindow { focus_handle } |
| 77 | }) |
| 78 | }, |
| 79 | ) |
| 80 | .unwrap(); |
| 81 | }); |
| 82 | } |