op/paint: add support for efficient ImageOp subimages

The new field ImageOp.Rect is initialized to cover the entire source
image, but can be modified to draw only a section of it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-02-13 13:02:41 +01:00
parent fd5dfacb40
commit 69dfd2e3a5
4 changed files with 22 additions and 8 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ func (t *Theme) Image(img paint.ImageOp) Image {
}
func (im Image) Layout(gtx *layout.Context) {
size := im.Src.Size()
size := im.Src.Rect.Size()
wf, hf := float32(size.X), float32(size.Y)
w, h := gtx.Px(unit.Dp(wf*im.Scale)), gtx.Px(unit.Dp(hf*im.Scale))
cs := gtx.Constraints