all: use color.NRGBA in public API

color.RGBA has two problems with regards to using it.

First the color values need to be premultiplied, whereas most APIs
have non-premultiplied values. This is mainly to preserve color components
with low alpha values.

Second there are two ways to premultiply with sRGB. One is to premultiply
after sRGB conversion, the other is before. This makes using the API more
confusing.

Using color.NRGBA in sRGB makes it align with CSS.e

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2020-11-18 20:21:26 +02:00
committed by Elias Naur
parent 9469d18907
commit 21ef492cc9
23 changed files with 200 additions and 157 deletions
+7 -7
View File
@@ -14,10 +14,10 @@ import (
type Theme struct {
Shaper text.Shaper
Color struct {
Primary color.RGBA
Text color.RGBA
Hint color.RGBA
InvText color.RGBA
Primary color.NRGBA
Text color.NRGBA
Hint color.NRGBA
InvText color.NRGBA
}
TextSize unit.Value
Icon struct {
@@ -53,10 +53,10 @@ func mustIcon(ic *widget.Icon, err error) *widget.Icon {
return ic
}
func rgb(c uint32) color.RGBA {
func rgb(c uint32) color.NRGBA {
return argb(0xff000000 | c)
}
func argb(c uint32) color.RGBA {
return color.RGBA{A: uint8(c >> 24), R: uint8(c >> 16), G: uint8(c >> 8), B: uint8(c)}
func argb(c uint32) color.NRGBA {
return color.NRGBA{A: uint8(c >> 24), R: uint8(c >> 16), G: uint8(c >> 8), B: uint8(c)}
}