xous-core/services/ime-frontend/src/emoji.rs
bunnie 6653d42114 cleanup UX context registry
it's now a much smaller nightmare to maintain the registry, as all
the items are concentrated into a single location
2022-01-23 14:31:21 +08:00

47 lines
1.8 KiB
Rust

use ime_plugin_api::ImefOpcode;
use num_traits::*;
use xous_ipc::String;
use gam::*;
// imef_conn must come from outside the scope of the macro because of hygeine rules.
macro_rules! emoji_item {
($emoji: expr, $imef_conn: ident) => {
MenuItem {
name: String::from_str(&$emoji.to_string()),
action_conn: Some($imef_conn),
action_opcode: ImefOpcode::ProcessKeys.to_u32().unwrap(),
action_payload: MenuPayload::Scalar([$emoji.into(), '\u{0000}'.into(), '\u{0000}'.into(), '\u{0000}'.into(), ]),
close_on_select: true,
}
}
}
// clearly, this does not scale. but, it's a good demo of the menu system.
// probably what this will need to turn into is a menu-of-menus....
pub(crate) fn emoji_menu(imef_conn: xous::CID) {
// the menu-matic for the emoji menu has to be encapsulated in a thread otherwise we get a deadlock
// while creating the menu items, because of the IMEF's unique place in the graphics hierarchy.
let _ = std::thread::spawn({
move || {
menu_matic(
vec![
emoji_item!('😃', imef_conn),
emoji_item!('😒', imef_conn),
emoji_item!('🤔', imef_conn),
emoji_item!('😅', imef_conn),
emoji_item!('🤣', imef_conn),
MenuItem {
name: String::from_str("Close Menu"),
action_conn: None,
action_opcode: 0,
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
close_on_select: true,
},
],
gam::EMOJI_MENU_NAME,
None
);
}
});
}