~eliasnaur/gio

b24df0aa6e67f8724f3c276844b582f29d43c8a2 — pierre 5 months ago 9bede80
widget/material: use clip.UniformRRect

Signed-off-by: pierre <pierre.curto@gmail.com>
3 files changed, 7 insertions(+), 31 deletions(-)

M widget/material/button.go
M widget/material/progressbar.go
M widget/material/switch.go
M widget/material/button.go => widget/material/button.go +2 -11
@@ 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)
}

M widget/material/progressbar.go => widget/material/progressbar.go +2 -5
@@ 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)


M widget/material/switch.go => widget/material/switch.go +3 -15
@@ 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)
}