From a94e9e6dd2a089a6ec0b6a2e30374aa803086f3c Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Sun, 21 Aug 2022 15:55:31 -0700 Subject: [PATCH 1/2] Potential fix for Issue #36 - SFSymbols doesn't need to be blocked off (panic) in iOS --- src/image/image.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/image/image.rs b/src/image/image.rs index 2c5b01b..0219557 100644 --- a/src/image/image.rs +++ b/src/image/image.rs @@ -192,11 +192,24 @@ impl Image { } /// Creates and returns an Image with the specified `SFSymbol`. Note that `SFSymbol` is - /// supported on 11.0+; as such, this will panic if called on a lower system. Take care to - /// provide a fallback image or user experience if you need to support an older OS. + /// supported on macOS 11.0+ and iOS 13.0+; as such, this will panic if called on a + /// lower system. Take care to provide a fallback image or user experience if you + /// need to support an older OS. + /// + /// This is `target_os` gated as SFSymbols is fairly Apple-specific. If another runtime + /// ever exposes a compatible API, this can be tweaked in a PR. + #[cfg(any(target_os = "macos", target_os = "ios"))] pub fn symbol(symbol: SFSymbol, accessibility_description: &str) -> Self { + // SFSymbols is macOS 11.0+ + #[cfg(feature = "appkit")] + let min_version = 11; + + // SFSymbols is iOS 13.0+. + #[cfg(all(feature = "uikit", not(feature = "appkit")))] + let min_version = 13; + Image(unsafe { - ShareId::from_ptr(match os::is_minimum_version(11) { + ShareId::from_ptr(match os::is_minimum_version(min_version) { true => { let icon = NSString::new(symbol.to_str()); let desc = NSString::new(accessibility_description); @@ -205,7 +218,10 @@ impl Image { }, false => { - #[cfg(target_os = "macos")] + #[cfg(feature = "appkit")] + panic!("SFSymbols are only supported on macOS 11.0 and up."); + + #[cfg(all(feature = "uikit", not(feature = "appkit")))] panic!("SFSymbols are only supported on macOS 11.0 and up."); } }) @@ -213,6 +229,10 @@ impl Image { } /// Draw a custom image and get it back as a returned `Image`. + /// + /// This is currently only supported on AppKit-based backends, and has + /// only been tested on macOS. + #[cfg(feature = "appkit")] pub fn draw(config: DrawConfig, handler: F) -> Self where F: Fn(CGRect, &CGContextRef) -> bool + 'static From 71c107e0706f2c336a570d0dd020c50149c36bfd Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Sun, 21 Aug 2022 16:04:20 -0700 Subject: [PATCH 2/2] Formatting fix --- src/image/image.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/image/image.rs b/src/image/image.rs index 0219557..3aeba50 100644 --- a/src/image/image.rs +++ b/src/image/image.rs @@ -192,8 +192,8 @@ impl Image { } /// Creates and returns an Image with the specified `SFSymbol`. Note that `SFSymbol` is - /// supported on macOS 11.0+ and iOS 13.0+; as such, this will panic if called on a - /// lower system. Take care to provide a fallback image or user experience if you + /// supported on macOS 11.0+ and iOS 13.0+; as such, this will panic if called on a + /// lower system. Take care to provide a fallback image or user experience if you /// need to support an older OS. /// /// This is `target_os` gated as SFSymbols is fairly Apple-specific. If another runtime @@ -220,7 +220,7 @@ impl Image { false => { #[cfg(feature = "appkit")] panic!("SFSymbols are only supported on macOS 11.0 and up."); - + #[cfg(all(feature = "uikit", not(feature = "appkit")))] panic!("SFSymbols are only supported on macOS 11.0 and up."); }