Skip to content

Commit

Permalink
feat: add new macro to easily get id and message
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Dec 8, 2024
1 parent 6e3f6a6 commit 521e47b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions iced_layershell/tests/test_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { .. }))
}
26 changes: 26 additions & 0 deletions iced_layershell_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 521e47b

Please sign in to comment.