zed/crates/gpui/examples/set_menus.rs
Mikayla Maki 80c14c9198
Some checks are pending
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Pull app / OS info out of GPUI, add Linux information, make fallible window initialization (#12869)
TODO:
- [x] Finish GPUI changes on other operating systems 

This is a largely internal change to how we report data to our
diagnostics and telemetry. This PR also includes an update to our blade
backend which allows us to report errors in a more useful way when
failing to initialize blade.


Release Notes:

- N/A

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
2024-06-11 11:43:12 -07:00

44 lines
1.2 KiB
Rust

use gpui::*;
struct SetMenus;
impl Render for SetMenus {
fn render(&mut self, _cx: &mut ViewContext<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() {
App::new().run(|cx: &mut AppContext| {
// 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",
items: vec![MenuItem::action("Quit", Quit)],
}]);
cx.open_window(WindowOptions::default(), |cx| {
cx.new_view(|_cx| 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 AppContext
fn quit(_: &Quit, cx: &mut AppContext) {
println!("Gracefully quitting the application . . .");
cx.quit();
}