From 991f48dc1fd965a4faf91a55dfce4bd40f8de3fa Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 16 Jan 2022 18:27:26 +0800 Subject: [PATCH] macro-ize the emoji menu --- services/ime-frontend/src/emoji.rs | 53 ++++++++++-------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/services/ime-frontend/src/emoji.rs b/services/ime-frontend/src/emoji.rs index 095e66ebb..b5b70235c 100644 --- a/services/ime-frontend/src/emoji.rs +++ b/services/ime-frontend/src/emoji.rs @@ -6,6 +6,19 @@ use gam::*; use crate::EMOJI_MENU_NAME; +// 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) { @@ -15,41 +28,11 @@ pub(crate) fn emoji_menu(imef_conn: xous::CID) { move || { menu_matic( vec![ - MenuItem { - name: String::from_str("😃"), - action_conn: Some(imef_conn), - action_opcode: ImefOpcode::ProcessKeys.to_u32().unwrap(), - action_payload: MenuPayload::Scalar(['😃'.into(), '\u{0000}'.into(), '\u{0000}'.into(), '\u{0000}'.into(), ]), - close_on_select: true, - }, - MenuItem { - name: String::from_str("😒"), - action_conn: Some(imef_conn), - action_opcode: ImefOpcode::ProcessKeys.to_u32().unwrap(), - action_payload: MenuPayload::Scalar(['😒'.into(), '\u{0000}'.into(), '\u{0000}'.into(), '\u{0000}'.into(), ]), - close_on_select: true, - }, - MenuItem { - name: String::from_str("🤔"), - action_conn: Some(imef_conn), - action_opcode: ImefOpcode::ProcessKeys.to_u32().unwrap(), - action_payload: MenuPayload::Scalar(['🤔'.into(), '\u{0000}'.into(), '\u{0000}'.into(), '\u{0000}'.into(), ]), - close_on_select: true, - }, - MenuItem { - name: String::from_str("😅"), - action_conn: Some(imef_conn), - action_opcode: ImefOpcode::ProcessKeys.to_u32().unwrap(), - action_payload: MenuPayload::Scalar(['😅'.into(), '\u{0000}'.into(), '\u{0000}'.into(), '\u{0000}'.into(), ]), - close_on_select: true, - }, - MenuItem { - name: String::from_str("🤣"), - action_conn: Some(imef_conn), - action_opcode: ImefOpcode::ProcessKeys.to_u32().unwrap(), - action_payload: MenuPayload::Scalar(['🤣'.into(), '\u{0000}'.into(), '\u{0000}'.into(), '\u{0000}'.into(), ]), - close_on_select: true, - }, + 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,