forked from lxn/walk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageview.go
52 lines (37 loc) · 1013 Bytes
/
imageview.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package walk
type ImageView struct {
*CustomWidget
image Image
}
func NewImageView(parent Container) (*ImageView, error) {
iv := new(ImageView)
cw, err := NewCustomWidget(parent, 0, func(canvas *Canvas, updateBounds Rectangle) error {
return iv.drawImage(canvas, updateBounds)
})
if err != nil {
return nil, err
}
iv.CustomWidget = cw
iv.window = iv
iv.SetInvalidatesOnResize(true)
return iv, nil
}
func (iv *ImageView) Image() Image {
return iv.image
}
func (iv *ImageView) SetImage(value Image) error {
iv.image = value
_, isMetafile := value.(*Metafile)
iv.SetClearsBackground(isMetafile)
return iv.Invalidate()
}
func (iv *ImageView) drawImage(canvas *Canvas, updateBounds Rectangle) error {
if iv.image == nil {
return nil
}
bounds := iv.ClientBounds()
return canvas.DrawImageStretched(iv.image, bounds)
}