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

Provide proper SF symbol support #143

Open
darwinx64 opened this issue Dec 24, 2024 · 2 comments
Open

Provide proper SF symbol support #143

darwinx64 opened this issue Dec 24, 2024 · 2 comments

Comments

@darwinx64
Copy link

darwinx64 commented Dec 24, 2024

Right now in cacao all symbols are hardcoded and I personally believe there's no real reason for this, and if a symbol doesn't exist; you could just do it like how SwiftUI does it where it's just a blank image and it warns you that it doesn't exist if the OS doesn't support it

image

Because of this, this is currently how I am having to do SF symbols (if anyone does use this, please note that this isn't safe and will crash if the OS doesn't support it, in my app this doesn't really matter to me though)

pub fn symbol_from(system_name: &str) -> Image {
    Image(unsafe {
        let icon = NSString::new(system_name);
        let desc = NSString::new("");
        msg_send![class!(NSImage), imageWithSystemSymbolName:&*icon
                    accessibilityDescription:&*desc]
    })
}

Which works nicely, I can use symbols from Sequoia now in my Cacao app:

image

I am requesting that something similar to my function could maybe be included in Cacao to prevent any confusion; I'm not really sure what the best and cleanest way of integrating this would be but I think it could be discussed a little here; I personally like how SwiftUI does it again but ofcourse this isn't very rust-y

Image(systemName: "house.fill")
@ryanmcgrath
Copy link
Owner

I personally believe there's no real reason for this

I mean, this is a bit personal - I'll take an enum variant over a string littering the codebase any day. ;)

That said...

I am requesting that something similar to my function could maybe be included in Cacao to prevent any confusion

I think your desired functionality is entirely appropriate and I'd welcome a PR. It might sit for a small bit since I've got a number of things to merge here - and I'm currently on a boat in Antarctica - but I'll get to it eventually. :)

Re: functionality, it could either be a method on SFSymbol or Image for now (e.g SFSymbol::image_from("symbol")) or Image could be rearchitected to be more of a builder type. I'm open to ideas as well.

@darwinx64
Copy link
Author

I came up with Image::with_system_symbol_name("icon.name"). I guess this is a little subjective but i went ahead and PR'd this, can be discussed more there if needed

#144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants