(image Image)
| 79 | } |
| 80 | |
| 81 | func (b *Button) SetImage(image Image) error { |
| 82 | var typ, handle uintptr |
| 83 | switch img := image.(type) { |
| 84 | case nil: |
| 85 | |
| 86 | case *Bitmap: |
| 87 | typ = win.IMAGE_BITMAP |
| 88 | handle = uintptr(img.hBmp) |
| 89 | |
| 90 | case *Icon: |
| 91 | typ = win.IMAGE_ICON |
| 92 | handle = uintptr(img.handleForDPI(b.DPI())) |
| 93 | |
| 94 | default: |
| 95 | bmp, err := iconCache.Bitmap(image, b.DPI()) |
| 96 | if err != nil { |
| 97 | return err |
| 98 | } |
| 99 | |
| 100 | typ = win.IMAGE_BITMAP |
| 101 | handle = uintptr(bmp.hBmp) |
| 102 | } |
| 103 | |
| 104 | b.SendMessage(win.BM_SETIMAGE, typ, handle) |
| 105 | |
| 106 | b.image = image |
| 107 | |
| 108 | b.RequestLayout() |
| 109 | |
| 110 | b.imageChangedPublisher.Publish() |
| 111 | |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | func (b *Button) ImageChanged() *Event { |
| 116 | return b.imageChangedPublisher.Event() |
no test coverage detected