all: use new rectangle and point convenience functions

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-19 10:39:20 +02:00
parent d82eb8fc66
commit 013ea395b4
11 changed files with 26 additions and 46 deletions
+2 -2
View File
@@ -332,7 +332,7 @@ func (e *Editor) PaintText(gtx *layout.Context) {
stack.Push(gtx.Ops)
op.TransformOp{}.Offset(shape.offset).Add(gtx.Ops)
shape.clip.Add(gtx.Ops)
paint.PaintOp{Rect: toRectF(clip).Sub(shape.offset)}.Add(gtx.Ops)
paint.PaintOp{Rect: layout.FRect(clip).Sub(shape.offset)}.Add(gtx.Ops)
stack.Pop()
}
}
@@ -368,7 +368,7 @@ func (e *Editor) PaintCaret(gtx *layout.Context) {
clip.Max = clip.Max.Add(e.viewSize)
carRect = clip.Intersect(carRect)
if !carRect.Empty() {
paint.PaintOp{Rect: toRectF(carRect)}.Add(gtx.Ops)
paint.PaintOp{Rect: layout.FRect(carRect)}.Add(gtx.Ops)
}
stack.Pop()
}
+1 -1
View File
@@ -37,7 +37,7 @@ func (ic *Icon) Layout(gtx *layout.Context, sz unit.Value) {
ico.Add(gtx.Ops)
paint.PaintOp{
Rect: f32.Rectangle{
Max: toPointF(ico.Size()),
Max: layout.FPt(ico.Size()),
},
}.Add(gtx.Ops)
gtx.Dimensions = layout.Dimensions{
+1 -5
View File
@@ -35,13 +35,9 @@ func (im Image) Layout(gtx *layout.Context) {
d := cs.Constrain(image.Pt(w, h))
var s op.StackOp
s.Push(gtx.Ops)
clip.Rect{Rect: f32.Rectangle{Max: toPointF(d)}}.Op(gtx.Ops).Add(gtx.Ops)
clip.Rect{Rect: f32.Rectangle{Max: layout.FPt(d)}}.Op(gtx.Ops).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()
gtx.Dimensions = layout.Dimensions{Size: d}
}
func toPointF(p image.Point) f32.Point {
return f32.Point{X: float32(p.X), Y: float32(p.Y)}
}
+3 -10
View File
@@ -102,29 +102,22 @@ func (l Label) Layout(gtx *layout.Context, s text.Shaper, font text.Font, size u
Width: dims.Size.X,
}
for {
start, end, layout, off, ok := it.Next()
start, end, l, off, ok := it.Next()
if !ok {
break
}
lclip := toRectF(clip).Sub(off)
lclip := layout.FRect(clip).Sub(off)
var stack op.StackOp
stack.Push(gtx.Ops)
op.TransformOp{}.Offset(off).Add(gtx.Ops)
str := txt[start:end]
s.ShapeString(font, textSize, str, layout).Add(gtx.Ops)
s.ShapeString(font, textSize, str, l).Add(gtx.Ops)
paint.PaintOp{Rect: lclip}.Add(gtx.Ops)
stack.Pop()
}
gtx.Dimensions = 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)},
}
}
func textPadding(lines []text.Line) (padding image.Rectangle) {
if len(lines) == 0 {
return
-4
View File
@@ -175,10 +175,6 @@ func (b IconButtonStyle) Layout(gtx *layout.Context, button *widget.Clickable) {
)
}
func toPointF(p image.Point) f32.Point {
return f32.Point{X: float32(p.X), Y: float32(p.Y)}
}
func drawInk(gtx *layout.Context, c widget.Click) {
d := gtx.Now().Sub(c.Time)
t := float32(d.Seconds())