mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
widget/material: correctly apply alpha to ProgressBar color
color.RGBA values are pre-multiplied, so transparency must be applied to all components. Fixes gio#117 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -55,10 +55,9 @@ func (b ProgressBarStyle) Layout(gtx *layout.Context, progress int) {
|
|||||||
layout.Stack{Alignment: layout.W}.Layout(gtx,
|
layout.Stack{Alignment: layout.W}.Layout(gtx,
|
||||||
layout.Stacked(func() {
|
layout.Stacked(func() {
|
||||||
// Use a transparent equivalent of progress color.
|
// Use a transparent equivalent of progress color.
|
||||||
backgroundColor := b.Color
|
bgCol := mulAlpha(b.Color, 150)
|
||||||
backgroundColor.A = 100
|
|
||||||
|
|
||||||
shader(progressBarWidth, backgroundColor)
|
shader(progressBarWidth, bgCol)
|
||||||
}),
|
}),
|
||||||
layout.Stacked(func() {
|
layout.Stacked(func() {
|
||||||
fillWidth := (progressBarWidth / 100) * float32(progress)
|
fillWidth := (progressBarWidth / 100) * float32(progress)
|
||||||
@@ -66,3 +65,14 @@ func (b ProgressBarStyle) Layout(gtx *layout.Context, progress int) {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mulAlpha scales all color components by alpha/255.
|
||||||
|
func mulAlpha(c color.RGBA, alpha uint8) color.RGBA {
|
||||||
|
a := uint16(alpha)
|
||||||
|
return color.RGBA{
|
||||||
|
A: uint8(uint16(c.A) * a / 255),
|
||||||
|
R: uint8(uint16(c.R) * a / 255),
|
||||||
|
G: uint8(uint16(c.G) * a / 255),
|
||||||
|
B: uint8(uint16(c.B) * a / 255),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user