widget/material: make Switch disabled color configurable

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-06-10 20:20:07 +02:00
parent bb8bb504d8
commit 5fe3785bbd
+10 -5
View File
@@ -17,15 +17,20 @@ import (
) )
type SwitchStyle struct { type SwitchStyle struct {
Color color.RGBA Color struct {
Enabled color.RGBA
Disabled color.RGBA
}
Switch *widget.Bool Switch *widget.Bool
} }
func Switch(th *Theme, swtch *widget.Bool) SwitchStyle { func Switch(th *Theme, swtch *widget.Bool) SwitchStyle {
return SwitchStyle{ sw := SwitchStyle{
Switch: swtch, Switch: swtch,
Color: th.Color.Primary,
} }
sw.Color.Enabled = th.Color.Primary
sw.Color.Disabled = rgb(0xffffff)
return sw
} }
// Layout updates the checkBox and displays it. // Layout updates the checkBox and displays it.
@@ -74,11 +79,11 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
// Compute thumb offset and color. // Compute thumb offset and color.
stack = op.Push(gtx.Ops) stack = op.Push(gtx.Ops)
col := rgb(0xffffff) col := s.Color.Disabled
if s.Switch.Value { if s.Switch.Value {
off := trackWidth - thumbSize off := trackWidth - thumbSize
op.TransformOp{}.Offset(f32.Point{X: float32(off)}).Add(gtx.Ops) op.TransformOp{}.Offset(f32.Point{X: float32(off)}).Add(gtx.Ops)
col = s.Color col = s.Color.Enabled
} }
// Draw thumb shadow, a translucent disc slightly larger than the // Draw thumb shadow, a translucent disc slightly larger than the