Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Image by system symbol name #144

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/image/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading