~eliasnaur/gio

eea1dbc176204c722a4c9832c043d7dcf9b96c89 — Egon Elbre 5 months ago bc6798c
widget/material: add hover to Switch

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
1 files changed, 12 insertions(+), 0 deletions(-)

M widget/material/switch.go
M widget/material/switch.go => widget/material/switch.go +12 -0
@@ 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)