diff options
author | Alexander Neumann <alexander.neumann@picos-software.com> | 2019-10-24 10:27:15 +0200 |
---|---|---|
committer | Alexander Neumann <alexander.neumann@picos-software.com> | 2019-10-24 10:27:15 +0200 |
commit | 0421c2c73f2c0e96ac6e5ca803db0dad4cf510d0 (patch) | |
tree | ec0abde09a01cc308db9eca8ecfa5b30f337c6e5 | |
parent | ImageList: Add AddIcon and AddImage (diff) | |
download | wireguard-windows-0421c2c73f2c0e96ac6e5ca803db0dad4cf510d0.tar.xz wireguard-windows-0421c2c73f2c0e96ac6e5ca803db0dad4cf510d0.zip |
ToolBar: Use ImageList.AddImage to avoid icon to bitmap conversion + small fix and cleanup
-rw-r--r-- | toolbar.go | 17 |
1 files changed, 5 insertions, 12 deletions
@@ -240,7 +240,7 @@ func (tb *ToolBar) SetImageList(value *ImageList) { tb.imageList = value } -func (tb *ToolBar) imageIndex(image *Bitmap) (imageIndex int32, err error) { +func (tb *ToolBar) imageIndex(image Image) (imageIndex int32, err error) { if tb.imageList == nil { dpi := tb.DPI() iml, err := NewImageListForDPI(SizeFrom96DPI(Size{16, 16}, dpi), 0, dpi) @@ -253,7 +253,7 @@ func (tb *ToolBar) imageIndex(image *Bitmap) (imageIndex int32, err error) { imageIndex = -1 if image != nil { - if imageIndex, err = tb.imageList.AddMasked(image); err != nil { + if imageIndex, err = tb.imageList.AddImage(image); err != nil { return } } @@ -266,9 +266,6 @@ func (tb *ToolBar) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) ui case win.WM_MOUSEMOVE, win.WM_MOUSELEAVE, win.WM_LBUTTONDOWN: tb.Invalidate() - // case win.WM_PAINT: - // tb.Invalidate() - case win.WM_COMMAND: switch win.HIWORD(uint32(wParam)) { case win.BN_CLICKED: @@ -365,13 +362,7 @@ func (tb *ToolBar) initButtonForAction(action *Action, state, style *byte, image } if tb.buttonStyle != ToolBarButtonTextOnly { - var bmp *Bitmap - - if action.image != nil { - bmp, _ = iconCache.Bitmap(action.image, tb.DPI()) - } - - if *image, err = tb.imageIndex(bmp); err != nil { + if *image, err = tb.imageIndex(action.image); err != nil { return err } } @@ -418,6 +409,8 @@ func (tb *ToolBar) onActionChanged(action *Action) error { return newError("SendMessage(TB_SETBUTTONINFO) failed") } + tb.RequestLayout() + return nil } |