From e6066cc262e1f209cd3b829b07e1aa756844d7af Mon Sep 17 00:00:00 2001 From: Tiramisu <165537498+darwinx64@users.noreply.github.com> Date: Tue, 24 Dec 2024 11:43:40 -0600 Subject: [PATCH] Add support for Image by system symbol name --- src/image/image.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/image/image.rs b/src/image/image.rs index 1dcd2ebc..82fd0a5e 100644 --- a/src/image/image.rs +++ b/src/image/image.rs @@ -165,6 +165,30 @@ impl Image { }) } + /// Given a name of an SF Symbol, will return an Image with that symbol + /// If said symbol doesn't exist, returns a blank Image + /// macOS 11.0+, (i/tv)OS 13.0+ + pub fn with_system_symbol_name(system_name: &str) -> Self { + #[cfg(feature = "appkit")] + let image = Image(unsafe { + let icon = NSString::new(system_name); + let desc = NSString::new(""); + msg_send_id![ + Self::class(), + imageWithSystemSymbolName: &*icon.objc, + accessibilityDescription: &*desc.objc + ] + }); + + #[cfg(all(feature = "uikit", not(feature = "appkit")))] + let image = Image(unsafe { + let icon = NSString::new(system_name); + msg_send_id![Self::class(), systemImageNamed: &*icon.objc] + }); + + image + } + // @TODO: for Airyx, unsure if this is supported - and it's somewhat modern macOS-specific, so // let's keep the os flag here for now. /// Returns a stock system icon. These are guaranteed to exist across all versions of macOS