From 521e47b687f7c518aa69d86818adb784a7a2702f Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sun, 8 Dec 2024 16:29:08 +0900 Subject: [PATCH] feat: add new macro to easily get id and message --- iced_layershell/tests/test_macro.rs | 12 ++++++++++++ iced_layershell_macros/src/lib.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/iced_layershell/tests/test_macro.rs b/iced_layershell/tests/test_macro.rs index 671cf2a..3328490 100644 --- a/iced_layershell/tests/test_macro.rs +++ b/iced_layershell/tests/test_macro.rs @@ -10,3 +10,15 @@ fn test_layer_message_macro() { let e = TestEnum::SizeChange((10, 10)); let _ = e.clone(); } + +#[test] +fn test_layer_message_macro_multi() { + #[to_layer_message(multi)] + #[derive(Debug, Clone)] + enum TestEnum { + TestA, + } + use layershellev::*; + let (_id, message) = TestEnum::layershell_open(NewLayerShellSettings::default()); + assert!(matches!(message, TestEnum::NewLayerShell { .. })) +} diff --git a/iced_layershell_macros/src/lib.rs b/iced_layershell_macros/src/lib.rs index ecd33cf..0435972 100644 --- a/iced_layershell_macros/src/lib.rs +++ b/iced_layershell_macros/src/lib.rs @@ -79,6 +79,32 @@ pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Res } } } + impl #ident #ty_gen #where_gen { + fn layershell_open(settings: iced_layershell::reexport::NewLayerShellSettings) -> (iced::window::Id, Self) { + let id = iced::window::Id::unique(); + ( + id, + Self::NewLayerShell { settings, id } + ) + + } + fn popup_open(settings: iced_layershell::actions::IcedNewPopupSettings) -> (iced::window::Id, Self) { + let id = iced::window::Id::unique(); + ( + id, + Self::NewPopUp { settings, id } + ) + + } + fn menu_open(settings: iced_layershell::actions::IcedNewMenuSettings) -> (iced::window::Id, Self) { + let id = iced::window::Id::unique(); + ( + id, + Self::NewMenu { settings, id } + ) + + } + } }; (additional_variants, try_into_impl) }