1use gpui::{
2 App, Application, Context, Menu, MenuItem, Window, WindowOptions, actions, div, prelude::*, rgb,
3};
4
5struct SetMenus;
6
7impl Render for SetMenus {
8 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
9 div()
10 .flex()
11 .bg(rgb(0x2e7d32))
12 .size_full()
13 .justify_center()
14 .items_center()
15 .text_xl()
16 .text_color(rgb(0xffffff))
17 .child("Set Menus Example")
18 }
19}
20
21fn main() {
22 Application::new().run(|cx: &mut App| {
23 // Bring the menu bar to the foreground (so you can see the menu bar)
24 cx.activate(true);
25 // Register the `quit` function so it can be referenced by the `MenuItem::action` in the menu bar
26 cx.on_action(quit);
27 // Add menu items
28 cx.set_menus(vec![Menu {
29 name: "set_menus".into(),
30 items: vec![MenuItem::action("Quit", Quit)],
31 }]);
32 cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| SetMenus {}))
33 .unwrap();
34 });
35}
36
37// Associate actions using the `actions!` macro (or `Action` derive macro)
38actions!(set_menus, [Quit]);
39
40// Define the quit function that is registered with the App
41fn quit(_: &Quit, cx: &mut App) {
42 println!("Gracefully quitting the application . . .");
43 cx.quit();
44}