widget/material: better disabled color calculation

Use desaturation in combination with alpha multiplication.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2020-12-16 19:06:24 +02:00
committed by Elias Naur
parent 9cc90d9695
commit e383e6d6be
7 changed files with 40 additions and 7 deletions
+2 -2
View File
@@ -129,7 +129,7 @@ func (b ButtonLayoutStyle) Layout(gtx layout.Context, w layout.Widget) layout.Di
}}, rr).Add(gtx.Ops)
background := b.Background
if gtx.Queue == nil {
background = f32color.MulAlpha(b.Background, 150)
background = f32color.Disabled(b.Background)
}
paint.Fill(gtx.Ops, background)
for _, c := range b.Button.History() {
@@ -156,7 +156,7 @@ func (b IconButtonStyle) Layout(gtx layout.Context) layout.Dimensions {
}, rr).Add(gtx.Ops)
background := b.Background
if gtx.Queue == nil {
background = f32color.MulAlpha(b.Background, 150)
background = f32color.Disabled(b.Background)
}
paint.Fill(gtx.Ops, background)
for _, c := range b.Button.History() {
+1 -1
View File
@@ -43,7 +43,7 @@ func (c *checkable) layout(gtx layout.Context, checked bool) layout.Dimensions {
size := gtx.Px(c.Size)
icon.Color = c.IconColor
if gtx.Queue == nil {
icon.Color = f32color.MulAlpha(icon.Color, 150)
icon.Color = f32color.Disabled(icon.Color)
}
icon.Layout(gtx, unit.Px(float32(size)))
return layout.Dimensions{
+1 -1
View File
@@ -61,7 +61,7 @@ func (e EditorStyle) Layout(gtx layout.Context) layout.Dimensions {
if e.Editor.Len() > 0 {
textColor := e.Color
if disabled {
textColor = f32color.MulAlpha(textColor, 150)
textColor = f32color.Disabled(textColor)
}
paint.ColorOp{Color: textColor}.Add(gtx.Ops)
e.Editor.PaintText(gtx)
+1 -1
View File
@@ -55,7 +55,7 @@ func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
fillWidth := progressBarWidth * clamp1(p.Progress)
fillColor := p.Color
if gtx.Queue == nil {
fillColor = f32color.MulAlpha(fillColor, 200)
fillColor = f32color.Disabled(fillColor)
}
return shader(fillWidth, fillColor)
}),
+1 -1
View File
@@ -68,7 +68,7 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
color := s.Color
if gtx.Queue == nil {
color = f32color.MulAlpha(color, 150)
color = f32color.Disabled(color)
}
// Draw track before thumb.
+1 -1
View File
@@ -55,7 +55,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
col = s.Color.Enabled
}
if gtx.Queue == nil {
col = f32color.MulAlpha(col, 150)
col = f32color.Disabled(col)
}
trackColor := s.Color.Track
op.Offset(f32.Point{Y: trackOff}).Add(gtx.Ops)