op/paint: add NewImageOp, unexport ImageOp fields

With public ImageOp fields there was no way to mark an image.Image as modified.
Replace them with NewImageOp that always make a copy, and use the opportunity
to ensure the copy is ready to upload to a GPU texture.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-10-14 17:37:18 +02:00
parent 2e22edbb99
commit 74407a50d5
4 changed files with 77 additions and 74 deletions
+1 -4
View File
@@ -15,8 +15,6 @@ import (
type Image struct {
// Src is the image to display.
Src image.Image
// Rect is the source rectangle.
Rect image.Rectangle
// Scale is the ratio of image pixels to
// dps.
Scale float32
@@ -25,7 +23,6 @@ type Image struct {
func (t *Theme) Image(img image.Image) Image {
return Image{
Src: img,
Rect: img.Bounds(),
Scale: 160 / 72, // About 72 DPI.
}
}
@@ -47,7 +44,7 @@ func (im Image) Layout(gtx *layout.Context) {
dr := f32.Rectangle{
Max: f32.Point{X: float32(d.X), Y: float32(d.Y)},
}
paint.ImageOp{Src: im.Src, Rect: im.Rect}.Add(gtx.Ops)
paint.NewImageOp(im.Src).Add(gtx.Ops)
paint.PaintOp{Rect: dr}.Add(gtx.Ops)
gtx.Dimensions = layout.Dimensions{Size: d, Baseline: d.Y}
}