cacao icon indicating copy to clipboard operation
cacao copied to clipboard

Provide proper SF symbol support

Open ghost opened this issue 11 months ago • 2 comments

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")

ghost avatar Dec 24 '24 15:12 ghost

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.

ryanmcgrath avatar Dec 24 '24 15:12 ryanmcgrath

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

ghost avatar Dec 24 '24 17:12 ghost