Explorar o código

MenuItem SetIcon() removes/disposes previous icon

leonsal %!s(int64=8) %!d(string=hai) anos
pai
achega
e34d066794
Modificáronse 1 ficheiros con 7 adicións e 0 borrados
  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()