clip: change Rect argument to f32.Rectangle

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-11-09 19:42:19 +01:00
parent 4f30b985eb
commit 65c783179d
3 changed files with 21 additions and 5 deletions
+9 -1
View File
@@ -5,6 +5,7 @@ package layout
import (
"image"
"gioui.org/f32"
"gioui.org/gesture"
"gioui.org/io/pointer"
"gioui.org/op"
@@ -248,7 +249,7 @@ func (l *List) layout() Dimensions {
}
var stack op.StackOp
stack.Push(ops)
clip.Rect(r).Add(ops)
clip.Rect(ops, toRectF(r)).Add(ops)
op.TransformOp{}.Offset(toPointF(axisPoint(l.Axis, pos, cross))).Add(ops)
child.macro.Add(ops)
stack.Pop()
@@ -267,3 +268,10 @@ func (l *List) layout() Dimensions {
l.macro.Add(ops)
return Dimensions{Size: dims}
}
func toRectF(r image.Rectangle) f32.Rectangle {
return f32.Rectangle{
Min: f32.Point{X: float32(r.Min.X), Y: float32(r.Min.Y)},
Max: f32.Point{X: float32(r.Max.X), Y: float32(r.Max.Y)},
}
}
+11 -3
View File
@@ -284,9 +284,17 @@ func (p *Path) End() Op {
}
}
// Rect returns the clip area of a pixel aligned rectangular area.
func Rect(r image.Rectangle) Op {
return Op{bounds: toRectF(r)}
// Rect returns the clip area of a rectangle.
func Rect(ops *op.Ops, r f32.Rectangle) Op {
ri := image.Rectangle{
Min: image.Point{X: int(r.Min.X), Y: int(r.Min.Y)},
Max: image.Point{X: int(r.Max.X), Y: int(r.Max.Y)},
}
// Optimize pixel-aligned rectangles to just its bounds.
if r == toRectF(ri) {
return Op{bounds: r}
}
return RoundRect(ops, r, 0, 0, 0, 0)
}
// RoundRect returns the clip area of a rectangle with rounded
+1 -1
View File
@@ -37,7 +37,7 @@ func (im Image) Layout(gtx *layout.Context) {
d := image.Point{X: cs.Width.Constrain(w), Y: cs.Height.Constrain(h)}
var s op.StackOp
s.Push(gtx.Ops)
clip.Rect(image.Rectangle{Max: d}).Add(gtx.Ops)
clip.Rect(gtx.Ops, f32.Rectangle{Max: toPointF(d)}).Add(gtx.Ops)
im.Src.Add(gtx.Ops)
paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{X: float32(w), Y: float32(h)}}}.Add(gtx.Ops)
s.Pop()