예제 #1
0
// makes the menu inside the contacts window
func makeContactsMenu(contacts []ts.Contact, contactsWin *gc.Window) ([]*gc.MenuItem, *gc.Menu, *gc.Window) {
	menu_items := make([]*gc.MenuItem, len(contacts))
	var err error
	for i, val := range contacts {
		menu_items[i], err = gc.NewItem((val.Name), "")
		if err != nil {
			log.Fatal("Error making item for contact menu... ", err)
		}
	}
	contactMenu, err := gc.NewMenu(menu_items)
	if err != nil {
		log.Fatal("Error creating contact menu from menu_items... ", err)
	}
	contactsWinSizeY, contactsWinSizeX := contactsWin.MaxYX()
	contactsWin.Keypad(true)
	contactsMenuWin := contactsWin.Derived((contactsWinSizeY - 5), (contactsWinSizeX - 2), 3, 1)
	contactMenu.SetWindow(contactsMenuWin)
	contactMenu.Format(len(contacts), 1)
	contactMenu.Mark(" * ")

	title := "Contacts"
	contactsWin.MovePrint(1, (contactsWinSizeX/2)-(len(title)/2), title)
	contactsWin.HLine(2, 1, '-', contactsWinSizeX-2)
	contactsMenuWin.Keypad(true)
	contactsMenuWin.ScrollOk(true)
	return menu_items, contactMenu, contactsMenuWin
}