widget/material: use clip.UniformRRect

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
pierre
2021-01-21 08:41:09 +01:00
committed by Elias Naur
parent 9bede80a3d
commit b24df0aa6e
3 changed files with 7 additions and 31 deletions
+2 -11
View File
@@ -91,10 +91,7 @@ func Clickable(gtx layout.Context, button *widget.Clickable, w layout.Widget) la
layout.Expanded(button.Layout),
layout.Expanded(func(gtx layout.Context) layout.Dimensions {
clip.RRect{
Rect: f32.Rectangle{Max: f32.Point{
X: float32(gtx.Constraints.Min.X),
Y: float32(gtx.Constraints.Min.Y),
}},
Rect: f32.Rectangle{Max: layout.FPt(gtx.Constraints.Min)},
}.Add(gtx.Ops)
for _, c := range button.History() {
drawInk(gtx, c)
@@ -286,12 +283,6 @@ func drawInk(gtx layout.Context, c widget.Press) {
X: -rr,
Y: -rr,
})).Add(gtx.Ops)
clip.RRect{
Rect: f32.Rectangle{Max: f32.Point{
X: float32(size),
Y: float32(size),
}},
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(gtx.Ops)
clip.UniformRRect(f32.Rectangle{Max: f32.Pt(size, size)}, rr).Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
}
+2 -5
View File
@@ -35,11 +35,8 @@ func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
d := image.Point{X: int(width), Y: gtx.Px(maxHeight)}
clip.RRect{
Rect: f32.Rectangle{Max: f32.Point{X: width, Y: float32(gtx.Px(maxHeight))}},
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(gtx.Ops)
height := float32(gtx.Px(maxHeight))
clip.UniformRRect(f32.Rectangle{Max: f32.Pt(width, height)}, rr).Add(gtx.Ops)
paint.ColorOp{Color: color}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
+3 -15
View File
@@ -60,10 +60,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
}
trackColor := s.Color.Track
op.Offset(f32.Point{Y: trackOff}).Add(gtx.Ops)
clip.RRect{
Rect: trackRect,
NE: trackCorner, NW: trackCorner, SE: trackCorner, SW: trackCorner,
}.Add(gtx.Ops)
clip.UniformRRect(trackRect, trackCorner).Add(gtx.Ops)
paint.ColorOp{Color: trackColor}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
stack.Load()
@@ -78,12 +75,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
}
op.Offset(inkOff).Add(gtx.Ops)
gtx.Constraints.Min = image.Pt(inkSize, inkSize)
clip.RRect{
Rect: f32.Rectangle{
Max: layout.FPt(gtx.Constraints.Min),
},
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(gtx.Ops)
clip.UniformRRect(f32.Rectangle{Max: layout.FPt(gtx.Constraints.Min)}, rr).Add(gtx.Ops)
for _, p := range s.Switch.History() {
drawInk(gtx, p)
}
@@ -142,11 +134,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
func drawDisc(ops *op.Ops, sz float32, col color.NRGBA) {
defer op.Save(ops).Load()
rr := sz / 2
r := f32.Rectangle{Max: f32.Point{X: sz, Y: sz}}
clip.RRect{
Rect: r,
NE: rr, NW: rr, SE: rr, SW: rr,
}.Add(ops)
clip.UniformRRect(f32.Rectangle{Max: f32.Pt(sz, sz)}, rr).Add(ops)
paint.ColorOp{Color: col}.Add(ops)
paint.PaintOp{}.Add(ops)
}