widget: use correct color in Icon

iconvg seems to expect a linear premultiplied color.

Fixes gio#132

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2021-01-11 11:04:02 +02:00
committed by Elias Naur
parent 0e3e446393
commit f114acdb02
4 changed files with 103 additions and 1 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ func (ic *Icon) image(sz int) paint.ImageOp {
img := image.NewRGBA(image.Rectangle{Max: image.Point{X: sz, Y: int(float32(sz) * dy / dx)}})
var ico iconvg.Rasterizer
ico.SetDstImage(img, img.Bounds(), draw.Src)
m.Palette[0] = f32color.NRGBAToRGBA(ic.Color)
m.Palette[0] = f32color.NRGBAToLinearRGBA(ic.Color)
iconvg.Decode(&ico, ic.src, &iconvg.DecodeOptions{
Palette: &m.Palette,
})
+30
View File
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: Unlicense OR MIT
package widget
import (
"image"
"image/color"
"testing"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/unit"
"golang.org/x/exp/shiny/materialdesign/icons"
)
func TestIcon_Alpha(t *testing.T) {
icon, err := NewIcon(icons.ToggleCheckBox)
if err != nil {
t.Fatal(err)
}
icon.Color = color.NRGBA{B: 0xff, A: 0x40}
gtx := layout.Context{
Ops: new(op.Ops),
Constraints: layout.Exact(image.Pt(100, 100)),
}
_ = icon.Layout(gtx, unit.Sp(18))
}