-
Notifications
You must be signed in to change notification settings - Fork 38
Conversation
Only drawback of using a protocol (to support multiple enums) instead of the enum directly is that it's not possible anymore to use the shorthand syntax of the enums ( Note that we have the same problem with the string template, it's not new. But in the 90% case where there's only one palette seems like a sad situation. Maybe we could improve that later on all templates having that problem? Not sure how though (as using a protocol for cases where we have multiple palettes is still the best option imho) |
Well, users can always use the other creation methods, such as Or we could do some advanced trickery where we check the number of tables/palettes/catalogs/... and not use protocols in those cases. |
Yeah the We could indeed use protocols only if multiple palettes and direct enum if only one. Might be an improvement for later. But in the meantime why do we still have to do |
Right now I've left it there because each case can have 2 values: a |
Ah right. I'm not sure a lot of people query the rgbaValue. Maybe keep this variant with the enum as an alternate template and make the main one direct constants? |
Hmmm, we can always add alternative templates if people ask for them, I'd say leave it out for now. |
So, the result would be: (swift 2) enum ColorName {
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#339666"></span>
/// Alpha: 100% <br/> (0x339666ff)
static let ArticleBody = Color(rgbaValue: 0x339666ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
/// Alpha: 100% <br/> (0xff66ccff)
static let ArticleFootnote = Color(rgbaValue: 0xff66ccff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#33fe66"></span>
/// Alpha: 100% <br/> (0x33fe66ff)
static let ArticleTitle = Color(rgbaValue: 0x33fe66ff)
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
/// Alpha: 80% <br/> (0xffffffcc)
static let Private = Color(rgbaValue: 0xffffffcc)
} |
Btw enum cases should only be used for things you'll likely need to |
Yup pretty much 👍 |
Do you want to do this in this PR, or a separate one? |
Maybe this can fit in there if it's not too much changes yeah. |
Sure thing, on it. |
7453b3d
to
3e077fa
Compare
You're gonna hate me be in fact the idea I had was more like this below. Maybe provide this variant as alternate template? struct ColorName {
let rgbaValue: UInt32
var color: Color { return Color.init(named: self) }
static let ArticleBody = ColorName(rgbaValue: 0x339666ff)
static let ArticleFootnote = ColorName(rgbaValue: 0xff66ccff)
…
}
extension Color {
convenience init(named color: ColorName) {
self.init(rgbaValue: color.rgbaValue)
}
} Usage: let c1: UIColor = ColorName.ArticleBody.color
let c2 = UIColor(named: .ArticleBody) Still requires the extra |
3e077fa
to
a8864ef
Compare
Lemme know if it's ok now, if so, I'll update the documentation samples. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any unit test containing multiple color palettes in the Expected fixtures here? Did I miss them?
enum XCTColors { | ||
struct XCTColors { | ||
let rgbaValue: UInt32 | ||
var color: Color { return Color.init(named: self) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why I used .init
there when I gave you my example, Color(named: self)
should work I guess
ec0c794
to
fdb3112
Compare
e4e6ed6
to
5ec47f9
Compare
Refs SwiftGen/SwiftGenKit#40.
Updates the templates to support multiple color palettes (one for each file).