| 1 | use gpui::{ |
| 2 | App, Application, Context, Menu, MenuItem, SystemMenuType, Window, WindowOptions, actions, div, |
| 3 | prelude::*, rgb, |
| 4 | }; |
| 5 | |
| 6 | struct SetMenus; |
| 7 | |
| 8 | impl Render for SetMenus { |
| 9 | fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement { |
| 10 | div() |
| 11 | .flex() |
| 12 | .bg(rgb(0x2e7d32)) |
| 13 | .size_full() |
| 14 | .justify_center() |
| 15 | .items_center() |
| 16 | .text_xl() |
| 17 | .text_color(rgb(0xffffff)) |
| 18 | .child("Set Menus Example") |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | fn main() { |
| 23 | Application::new().run(|cx: &mut App| { |
| 24 | |
| 25 | cx.activate(true); |
| 26 | |
| 27 | cx.on_action(quit); |
| 28 | |
| 29 | cx.set_menus(vec![Menu { |
| 30 | name: "set_menus".into(), |
| 31 | items: vec![ |
| 32 | MenuItem::os_submenu("Services", SystemMenuType::Services), |
| 33 | MenuItem::separator(), |
| 34 | MenuItem::action("Quit", Quit), |
| 35 | ], |
| 36 | }]); |
| 37 | cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| SetMenus {})) |
| 38 | .unwrap(); |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | actions!(set_menus, [Quit]); |
| 44 | |
| 45 | |
| 46 | fn quit(_: &Quit, cx: &mut App) { |
| 47 | println!("Gracefully quitting the application . . ."); |
| 48 | cx.quit(); |
| 49 | } |