Skip to content

Commit a75cbc2

Browse files
authored
Merge pull request #6 from firefly-zero/menu
Menu
2 parents b6b75b2 + baec8c5 commit a75cbc2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod fs;
1111
pub mod graphics;
1212
mod input;
1313
pub mod math;
14+
mod menu;
1415
mod misc;
1516
mod net;
1617
pub mod shapes;
@@ -20,6 +21,7 @@ pub mod sudo;
2021
pub use fs::*;
2122
pub use graphics::*;
2223
pub use input::*;
24+
pub use menu::*;
2325
pub use misc::*;
2426
pub use net::*;
2527

src/menu.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.
6+
pub 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(i as u32, ptr, len);
11+
}
12+
}
13+
14+
/// Remove a custom menu item with the given index.
15+
pub fn remove_menu_item(i: u8) {
16+
unsafe {
17+
bindings::remove_menu_item(i as u32);
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.
25+
pub fn open_menu() {
26+
unsafe {
27+
bindings::open_menu();
28+
}
29+
}
30+
31+
mod 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+
}

0 commit comments

Comments
 (0)