From eea1dbc176204c722a4c9832c043d7dcf9b96c89 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Sun, 17 Jan 2021 18:43:20 +0200 Subject: [PATCH] widget/material: add hover to Switch Signed-off-by: Egon Elbre --- widget/material/switch.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/widget/material/switch.go b/widget/material/switch.go index 50158c43..7f6b937d 100644 --- a/widget/material/switch.go +++ b/widget/material/switch.go @@ -96,6 +96,18 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions { op.Offset(f32.Point{X: float32(off)}).Add(gtx.Ops) } + // Draw hover. + if s.Switch.Hovered() { + var p clip.Path + r := 1.7 * float32(thumbSize) / 2 + p.Begin(gtx.Ops) + //p.Move(f32.Pt(-float32(thumbSize)/2, -float32(thumbSize)/2)) + p.Move(f32.Pt(-r+float32(thumbSize)/2, -r+float32(thumbSize)/2)) + addCircle(&p, r) + background := f32color.MulAlpha(s.Color.Enabled, 70) + paint.FillShape(gtx.Ops, background, clip.Outline{Path: p.End()}.Op()) + } + // Draw thumb shadow, a translucent disc slightly larger than the // thumb itself. shadowStack := op.Save(gtx.Ops)