From 36f4267a6c235f476346de132fc05aa7bac71757 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 8 Jun 2020 21:57:29 +0200 Subject: [PATCH] widget/material: fade in inkwells When a clickable is pressed and dragged any enclosing List will grab and cancels the press. To minimize visual dicontinuity, smoothly fade in the inkwell. Signed-off-by: Elias Naur --- widget/material/button.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/widget/material/button.go b/widget/material/button.go index f69d30fe..b1598a85 100644 --- a/widget/material/button.go +++ b/widget/material/button.go @@ -189,17 +189,19 @@ func (b IconButtonStyle) Layout(gtx layout.Context) layout.Dimensions { } func drawInk(gtx layout.Context, c widget.Press) { - d := gtx.Now().Sub(c.Time) - t := float32(d.Seconds()) + now := gtx.Now() + age := now.Sub(c.Time) + t := float32(age.Seconds()) const duration = 0.5 if t > duration { + // Too old. return } t = t / duration - stack := op.Push(gtx.Ops) + defer op.Push(gtx.Ops).Pop() size := float32(gtx.Px(unit.Dp(700))) * t rr := size * .5 - col := byte(0xaa * (1 - t*t)) + col := byte(0xcc * t * t) ink := paint.ColorOp{Color: color.RGBA{A: col, R: col, G: col, B: col}} ink.Add(gtx.Ops) op.TransformOp{}.Offset(c.Position).Offset(f32.Point{ @@ -214,6 +216,5 @@ func drawInk(gtx layout.Context, c widget.Press) { NE: rr, NW: rr, SE: rr, SW: rr, }.Op(gtx.Ops).Add(gtx.Ops) paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{X: float32(size), Y: float32(size)}}}.Add(gtx.Ops) - stack.Pop() op.InvalidateOp{}.Add(gtx.Ops) }