ZIm/crates/gpui/examples/set_menus.rs
someone13574 0c94bdc8e4
gpui: Update docs to reflect removal of View, ViewContext, WindowContext (#24008)
This PR updates function signatures, docstrings, and gpui's other
documentation to reflect it's new state following the merge of `Model`
and `View` into `Entity` as well as the removal of `WindowContext`.

Release Notes:

- N/A
2025-01-31 11:40:42 -08:00

44 lines
1.3 KiB
Rust

use gpui::{
actions, div, prelude::*, rgb, App, Application, Context, Menu, MenuItem, Window, WindowOptions,
};
struct SetMenus;
impl Render for SetMenus {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div()
.flex()
.bg(rgb(0x2e7d32))
.size_full()
.justify_center()
.items_center()
.text_xl()
.text_color(rgb(0xffffff))
.child("Set Menus Example")
}
}
fn main() {
Application::new().run(|cx: &mut App| {
// Bring the menu bar to the foreground (so you can see the menu bar)
cx.activate(true);
// Register the `quit` function so it can be referenced by the `MenuItem::action` in the menu bar
cx.on_action(quit);
// Add menu items
cx.set_menus(vec![Menu {
name: "set_menus".into(),
items: vec![MenuItem::action("Quit", Quit)],
}]);
cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| SetMenus {}))
.unwrap();
});
}
// Associate actions using the `actions!` macro (or `impl_actions!` macro)
actions!(set_menus, [Quit]);
// Define the quit function that is registered with the App
fn quit(_: &Quit, cx: &mut App) {
println!("Gracefully quitting the application . . .");
cx.quit();
}