Awesome icon indicating copy to clipboard operation
Awesome copied to clipboard

Reorganize Awesome

Open ghowen opened this issue 6 years ago • 8 comments

The issue #33 triggered a thought that is nagging me for a while already. Currently the library is structured like this

Awesome - Style - Icon

This is probably due to how FontAwesome structured their fonts. But I feel it would be much more natural to structure the library like this

Awesome - Icon - Style

This way one could much more easily switch between different styles (like when picking an icon from a list).

Basically we might be able to have one enum called for example Awesome and this would have a name, description and style property like .regular, .solid, light, .brand or so.

The .asImage methods would then be attached to the style, so a bold car icon would be

Awesome.car.light

If an icon is not available for a certain style, the factory methods could return nil. Also maybe we could allow for a way to iterate over the available styles per icon by checking the font?

As far as I can see the same icon has the same unicode value across different styles, so we could drastically downsize the library even more as we would only need on alphabetical enum with all icon names.

Looking forward to your thoughts and comments.

ghowen avatar Nov 24 '18 18:11 ghowen

I think it does make sense but would like to hear more opinions from the current users

rafiki270 avatar Nov 24 '18 18:11 rafiki270

I have to say... I upvote this! The only drawback is the availability for a style. It means every references will be optional and thus forcing us to to unwrap somehow

ipodishima avatar Dec 13 '18 01:12 ipodishima

This would make things a lot easier

beamercola avatar Jan 30 '19 06:01 beamercola

Well, I would like to keep the original style but maybe we could create two enums which would live side by side. Potentialy in separate modules? The drawback on that one would be a dual interface making the system less clear ... thoughts?

rafiki270 avatar Jan 30 '19 10:01 rafiki270

Maybe we could leverage the parser to create an intermediate file with the extracted icon information and then have a another script that creates each enum out of this. This way we would not need to mix the different enum creations in one script.

ghowen avatar Jan 30 '19 12:01 ghowen

I'm good with this. It's a little confusing to have both, but it seems like it's the right direction. This would kill the need for the Amazing protocol, correct?

beamercola avatar Jan 30 '19 17:01 beamercola

I don't think supporting two competing styles at once is the right way. If there's reasons to choose one over the other, remove the other. If the current one is good enough and the other one just also looks nice, don't adopt the other one. Having two adds unnecessary bloat and feels like one's undecisive.

padarom avatar Feb 07 '19 22:02 padarom

What about to add something like this for that case?

extension Awesome {
    
    public enum AwesomeStyle: String {
        case brand, solid, regular
    }
    
    static func getAwesomeImage(for brand: Brand, style: AwesomeStyle = .brand, size: CGSize, color: Color, backgroundColor: Color) -> Image? {
        return getAwesomeImage(for: brand.rawValue, style: style, size: size, color: color, backgroundColor: backgroundColor)
    }
    
    static func getAwesomeImage(for solid: Solid, style: AwesomeStyle = .solid, size: CGSize, color: Color, backgroundColor: Color) -> Image? {
        return getAwesomeImage(for: solid.rawValue, style: style, size: size, color: color, backgroundColor: backgroundColor)
    }
    
    static func getAwesomeImage(for regular: Regular, style: AwesomeStyle = .regular, size: CGSize, color: Color, backgroundColor: Color) -> Image? {
        return getAwesomeImage(for: regular.rawValue, style: style, size: size, color: color, backgroundColor: backgroundColor)
    }
    
    static func getAwesomeImage(for name: String, style: AwesomeStyle, size: CGSize, color: Color, backgroundColor: Color) -> Image? {
        
        switch style {
        case .brand:
            guard let amazing = Brand(rawValue: name) else { return nil }
            return amazing.asImage(size: size, color: color, backgroundColor: backgroundColor)
        case .solid:
            guard let amazing = Solid(rawValue: name) else { return nil }
            return amazing.asImage(size: size, color: color, backgroundColor: backgroundColor)
        case .regular:
            guard let amazing = Regular(rawValue: name) else { return nil }
            return amazing.asImage(size: size, color: color, backgroundColor: backgroundColor)
        }
    }
}

vytick avatar Mar 27 '19 04:03 vytick