widget/material: manage widget colors with Palette type

This introduces a new material.Palette type that captures the color information
necessary to render a widget. This type is embedded in the material.Theme to
make it easier to swap to a different palette for part of the UI by reassinging
the Palette field.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2020-12-05 21:59:49 -05:00
committed by Elias Naur
parent 47ba975899
commit a87a520ae8
10 changed files with 57 additions and 35 deletions
+5 -3
View File
@@ -21,6 +21,7 @@ type SwitchStyle struct {
Color struct {
Enabled color.NRGBA
Disabled color.NRGBA
Track color.NRGBA
}
Switch *widget.Bool
}
@@ -29,8 +30,9 @@ func Switch(th *Theme, swtch *widget.Bool) SwitchStyle {
sw := SwitchStyle{
Switch: swtch,
}
sw.Color.Enabled = th.Color.Primary
sw.Color.Disabled = rgb(0xffffff)
sw.Color.Enabled = th.Palette.ContrastBg
sw.Color.Disabled = th.Palette.Bg
sw.Color.Track = f32color.MulAlpha(th.Palette.Fg, 0x88)
return sw
}
@@ -55,7 +57,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
if gtx.Queue == nil {
col = f32color.MulAlpha(col, 150)
}
trackColor := f32color.MulAlpha(col, 150)
trackColor := s.Color.Track
op.Offset(f32.Point{Y: trackOff}).Add(gtx.Ops)
clip.RRect{
Rect: trackRect,