Selaa lähdekoodia

Merge pull request #1 from tgreiser/tng-working

dropdown/list - SelectedPos method
Tim Greiser 7 vuotta sitten
vanhempi
commit
ff955d63f8
2 muutettua tiedostoa jossa 16 lisäystä ja 8 poistoa
  1. 8 1
      gui/dropdown.go
  2. 8 7
      gui/list.go

+ 8 - 1
gui/dropdown.go

@@ -113,10 +113,17 @@ func (dd *DropDown) Selected() *ImageLabel {
 	return dd.selItem
 }
 
+// SelectedPos returns the currently selected position or -1 if no item was selected
+func (dd *DropDown) SelectedPos() int {
+	return dd.list.selected()
+}
+
 // SetSelected sets the selected item
 func (dd *DropDown) SetSelected(item *ImageLabel) {
-
+	dd.list.SetSelected(dd.selItem, false)
 	dd.list.SetSelected(item, true)
+	dd.copySelected()
+	dd.update()
 }
 
 // SelectPos selects the item at the specified position

+ 8 - 7
gui/list.go

@@ -10,13 +10,13 @@ import (
 
 // List represents a list GUI element
 type List struct {
-	ItemScroller         // Embedded scroller
-	styles   *ListStyles // Pointer to styles
-	single   bool        // Single selection flag (default is true)
-	focus    bool        // has keyboard focus
-	dropdown bool        // this is used as dropdown
-	keyNext  window.Key  // Code of key to select next item
-	keyPrev  window.Key  // Code of key to select previous item
+	ItemScroller             // Embedded scroller
+	styles       *ListStyles // Pointer to styles
+	single       bool        // Single selection flag (default is true)
+	focus        bool        // has keyboard focus
+	dropdown     bool        // this is used as dropdown
+	keyNext      window.Key  // Code of key to select next item
+	keyPrev      window.Key  // Code of key to select previous item
 }
 
 // ListItem encapsulates each item inserted into the list
@@ -440,6 +440,7 @@ func (li *List) setSelection(litem *ListItem, state bool, force bool, dispatch b
 		for _, curr := range li.items {
 			if curr.(*ListItem) != litem {
 				curr.(*ListItem).SetSelected(false)
+				curr.(*ListItem).SetHighlighted(false)
 			}
 		}
 	}