tauri_macros

Macro do_menu_item

Source
do_menu_item!() { /* proc-macro */ }
Expand description

Accepts a closure-like syntax to call arbitrary code on a menu item after matching against kind and retrieving it from resources_table using rid.

You can optionally pass a 5th parameter to select which item kinds to match against, by providing a | separated list of item kinds

do_menu_item!(resources_table, rid, kind, |i| i.set_text(text), Check | Submenu);

You could also provide a negated list

do_menu_item!(resources_table, rid, kind, |i| i.set_text(text), !Check);
do_menu_item!(resources_table, rid, kind, |i| i.set_text(text), !Check | !Submenu);

but you can’t have mixed negations and positive kinds.

do_menu_item!(resources_table, rid, kind, |i| i.set_text(text), !Check | Submenu);
§Example
 let rid = 23;
 let kind = ItemKind::Check;
 let resources_table = app.resources_table();
 do_menu_item!(resources_table, rid, kind, |i| i.set_text(text))

which will expand into:

 let rid = 23;
 let kind = ItemKind::Check;
 let resources_table = app.resources_table();
 match kind {
 ItemKind::Submenu => {
   let i = resources_table.get::<Submenu<R>>(rid)?;
   i.set_text(text)
 }
 ItemKind::MenuItem => {
   let i = resources_table.get::<MenuItem<R>>(rid)?;
   i.set_text(text)
 }
 ItemKind::Predefined => {
   let i = resources_table.get::<PredefinedMenuItem<R>>(rid)?;
   i.set_text(text)
 }
 ItemKind::Check => {
   let i = resources_table.get::<CheckMenuItem<R>>(rid)?;
   i.set_text(text)
 }
 ItemKind::Icon => {
   let i = resources_table.get::<IconMenuItem<R>>(rid)?;
   i.set_text(text)
 }
 _ => unreachable!(),
 }