mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget/material: replace deprecated clip.Circle with clip.Ellipse
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -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
|
||||
}),
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
|
||||
+10
-15
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user