Open avh4 opened 6 years ago
withAlpha
seems like a useful and low-cost thing to include. It solves the rgb255
question, and ommitting rgba255
hints at the fact that floats are the preferred way to specify color channels.
Plus, I can use it for other things!
Feels like good API to me.
As was brought up in #4, there are options for the best name for this (setAlpha
, etc), and more such functions (for things besides alpha) are planned to be added in 1.1.0 for color manipulation. Given that, I'm thinking it's best to not add this yet to ensure we don't pick the wrong name and have to do a major version bump.
Does anyone need to create colors this way?
I create colors this way for use in CSS and in an SVG icon builder program.
When doing this, would the alpha value want to be specified in [0,255], or [0,1.0] ?
I only use [0, 1.0]
range for alpha.
Is this common enough that it merits an additional convenience function?
I use it maybe 1/10th as often as rgb255
without alpha.
It would be slightly less discoverable to use withAlpha
than rgba255
, but it would keep the the public API smaller. It would certainly hint that Float
s are preferred as @2mol mentioned. I would withhold it for 1.0.0
since it's easier to add it later than to take it away.
My biggest concern personally is that it might make it tough to provide support for it with the Atom pigments plugin.
I was so happy when this just worked:
@absynce why do you use [0,1.0] range for alpha instead of [0,255] ?
@avh4 good question...CSS/web legacy mostly.
The [0, 1.0]
alpha range has been in most of the examples I've seen on SO and MDN within CSS/Sass-land, it was in the previous Color
module, and fits with my mental model (I convert to a percentage in my head, but I guess I should be using % when in CSS).
Alternatively, in a world without rgba255 : Int -> Int -> Int -> Float -> Color
nor withAlpha
but including rgba : Float -> Float -> Float -> Float -> Color
I might just do:
rgba (250 / 255) (251 / 255) (245 / 255) 0.95
If it were rgba255 : Int -> Int -> Int -> Int -> Color
I could do this:
rgba255 250 251 245 <| round (0.95 * 255)
I'd be okay without this in the package and writing my own function to handle it too: Color.Custom.rgba
.
How would this design appear to folks coming from a web development background? I didn't think of the pattern above until I read the source you're working on now. 😅 Maybe some similar examples would be enough to guide people along.
How do you typically specify alpha?
I have a web development background and was a bit confused that the API did not include a rgba255 : Int -> Int -> Int -> Float -> Color
method. In my experience this is the most common way to define rgba colors. I strongly believe this should be included in the next release.
Meaning, using r,g,b values in the range [0,255], and also using an alpha value != 1.0.
Questions:
Currently that could be done with
But we could possibly make something more concise. Possibilities might be: