From 170d24bdcd5557152a267dc4eb29a6b6b4e8efa6 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 20 Dec 2021 16:22:39 +0100 Subject: [PATCH] widget/material: replace deprecated clip.Circle with clip.Ellipse Signed-off-by: Elias Naur --- widget/material/checkable.go | 8 ++------ widget/material/slider.go | 10 +++++----- widget/material/switch.go | 25 ++++++++++--------------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/widget/material/checkable.go b/widget/material/checkable.go index 4922a023..a1da1197 100644 --- a/widget/material/checkable.go +++ b/widget/material/checkable.go @@ -50,12 +50,8 @@ func (c *checkable) layout(gtx layout.Context, checked, hovered bool) layout.Dim background := f32color.MulAlpha(c.IconColor, 70) - radius := float32(size) / 2 - paint.FillShape(gtx.Ops, background, - clip.Circle{ - Center: f32.Point{X: radius, Y: radius}, - Radius: radius, - }.Op(gtx.Ops)) + b := f32.Rectangle{Max: f32.Pt(float32(size), float32(size))} + paint.FillShape(gtx.Ops, background, clip.Ellipse(b).Op(gtx.Ops)) return dims }), diff --git a/widget/material/slider.go b/widget/material/slider.go index 0c817fb8..c8835d92 100644 --- a/widget/material/slider.go +++ b/widget/material/slider.go @@ -78,11 +78,11 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions { // Draw thumb. pt := axis.Convert(image.Pt(thumbPos, sizeCross/2)) - paint.FillShape(gtx.Ops, color, - clip.Circle{ - Center: f32.Point{X: float32(pt.X), Y: float32(pt.Y)}, - Radius: float32(thumbRadius), - }.Op(gtx.Ops)) + thumb := f32.Rectangle{ + Min: f32.Pt(float32(pt.X-thumbRadius), float32(pt.Y-thumbRadius)), + Max: f32.Pt(float32(pt.X+thumbRadius), float32(pt.Y+thumbRadius)), + } + paint.FillShape(gtx.Ops, color, clip.Ellipse(thumb).Op(gtx.Ops)) return layout.Dimensions{Size: size} } diff --git a/widget/material/switch.go b/widget/material/switch.go index f68e63a7..76f469f1 100644 --- a/widget/material/switch.go +++ b/widget/material/switch.go @@ -91,32 +91,27 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions { thumbRadius := float32(thumbSize) / 2 + circle := func(x, y, r float32) clip.Op { + b := f32.Rectangle{ + Min: f32.Pt(x-r, y-r), + Max: f32.Pt(x+r, y+r), + } + return clip.Ellipse(b).Op(gtx.Ops) + } // Draw hover. if s.Switch.Hovered() { r := 1.7 * thumbRadius background := f32color.MulAlpha(s.Color.Enabled, 70) - paint.FillShape(gtx.Ops, background, - clip.Circle{ - Center: f32.Point{X: thumbRadius, Y: thumbRadius}, - Radius: r, - }.Op(gtx.Ops)) + paint.FillShape(gtx.Ops, background, circle(thumbRadius, thumbRadius, r)) } // Draw thumb shadow, a translucent disc slightly larger than the // thumb itself. // Center shadow horizontally and slightly adjust its Y. - paint.FillShape(gtx.Ops, argb(0x55000000), - clip.Circle{ - Center: f32.Point{X: thumbRadius, Y: thumbRadius + .25}, - Radius: thumbRadius + 1, - }.Op(gtx.Ops)) + paint.FillShape(gtx.Ops, argb(0x55000000), circle(thumbRadius, thumbRadius+.25, thumbRadius+1)) // Draw thumb. - paint.FillShape(gtx.Ops, col, - clip.Circle{ - Center: f32.Point{X: thumbRadius, Y: thumbRadius}, - Radius: thumbRadius, - }.Op(gtx.Ops)) + paint.FillShape(gtx.Ops, col, circle(thumbRadius, thumbRadius, thumbRadius)) // Set up click area. clickSize := gtx.Px(unit.Dp(40))