Просмотр исходного кода

MenuItem SetIcon() removes/disposes previous icon

leonsal 8 лет назад
Родитель
Сommit
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()