mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 08:55:35 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user