瀏覽代碼

MenuItem SetIcon() removes/disposes previous icon

leonsal 8 年之前
父節點
當前提交
e34d066794
共有 1 個文件被更改,包括 7 次插入0 次删除
  1. 7 0
      gui/menu.go

+ 7 - 0
gui/menu.go

@@ -597,6 +597,13 @@ func newMenuItem(text string, styles *MenuItemStyles) *MenuItem {
 // If an image was previously set it is replaced by this icon
 func (mi *MenuItem) SetIcon(icode int) *MenuItem {
 
+	// Remove and dispose previous icon
+	if mi.licon != nil {
+		mi.Panel.Remove(mi.licon)
+		mi.Dispose()
+		mi.licon = nil
+	}
+	// Sets the new icon
 	mi.licon = NewIconLabel(string(icode))
 	mi.Panel.Add(mi.licon)
 	mi.update()