firefly_rust/
menu.rs

1/// Add a custom item on the app menu.
2///
3/// The `i` index is the value passed into the `handle_menu` callback
4/// when the menu item is selected by the user.
5/// Its value doesn't have to be unique or continious.
6pub fn add_menu_item(i: u8, t: &str) {
7    let ptr = t.as_ptr() as u32;
8    let len = t.len() as u32;
9    unsafe {
10        bindings::add_menu_item(u32::from(i), ptr, len);
11    }
12}
13
14/// Remove a custom menu item with the given index.
15pub fn remove_menu_item(i: u8) {
16    unsafe {
17        bindings::remove_menu_item(u32::from(i));
18    }
19}
20
21/// Open the app menu.
22///
23/// It will be opened before the next update.
24/// The current update and then render will proceed as planned.
25pub fn open_menu() {
26    unsafe {
27        bindings::open_menu();
28    }
29}
30
31mod bindings {
32    #[link(wasm_import_module = "menu")]
33    extern {
34        pub(crate) fn add_menu_item(index: u32, text_ptr: u32, text_len: u32);
35        pub(crate) fn remove_menu_item(index: u32);
36        pub(crate) fn open_menu();
37    }
38}