func CreateTree() gtk3.WidgetLike { model := gtk3.NewTreeStore([]gobject.GType{gobject.G_TYPE_STRING, gobject.G_TYPE_INT}) treeView := gtk3.NewTreeViewWithModel(model) selection := treeView.GetSelection() if selection == nil { panic("Selection object nil") } selection.SetMode(gtk3.GtkSelectionMode.BROWSE) var iter gtk3.TreeIter for _, demo := range Demos { model.Append(&iter, nil) model.SetValues(&iter, gtk3.V{TitleColumn: demo.Title, StyleColumn: pango.PangoStyle.NORMAL}) if len(demo.Children) > 0 { var childIter gtk3.TreeIter for _, childDemo := range demo.Children { model.Append(&childIter, &iter) model.SetValues(&childIter, gtk3.V{TitleColumn: childDemo.Title, StyleColumn: pango.PangoStyle.NORMAL}) } } } cell := gtk3.NewCellRendererText() column := gtk3.NewTreeViewColumnWithAttributes("Widget (double click for demo)", cell, gtk3.A{{"text", TitleColumn}, {"style", StyleColumn}}) treeView.AppendColumn(column) model.GetIterFirst(&iter) selection.SelectIter(&iter) treeView.Connect("row_activated", rowActivated, model) treeView.CollapseAll() treeView.SetHeadersVisible(false) sw := gtk3.NewScrolledWindow(nil, nil) sw.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC) sw.Add(treeView) label := gtk3.NewLabel("Widget (double click for demo)") box := gtk3.NewNotebook() box.AppendPage(sw, label) treeView.GrabFocus() return box }
func createModel() gtk3.TreeModelLike { model := gtk3.NewTreeStore([]gobject.GType{gobject.G_TYPE_STRING, gobject.G_TYPE_BOOLEAN, gobject.G_TYPE_BOOLEAN, gobject.G_TYPE_BOOLEAN, gobject.G_TYPE_BOOLEAN, gobject.G_TYPE_BOOLEAN, gobject.G_TYPE_BOOLEAN, gobject.G_TYPE_BOOLEAN}) // Add data to store var iter gtk3.TreeIter for _, month := range months { model.Append(&iter, nil) model.SetValues(&iter, gtk3.V{HolidayNameCol: month, AlexCol: false, HavocCol: false, TimCol: false, OwenCol: false, DaveCol: false, VisibleCol: false, WorldCol: false}) items := toplevel[month] // Add children for _, it := range items { var childIter gtk3.TreeIter model.Append(&childIter, &iter) model.SetValues(&childIter, gtk3.V{HolidayNameCol: it.Label, AlexCol: it.Alex, HavocCol: it.Havoc, TimCol: it.Tim, OwenCol: it.Owen, DaveCol: it.Dave, VisibleCol: true, WorldCol: it.WorldHoliday}) } } return model }
func createCapitalStore() gtk3.TreeModelLike { type Capital struct { Group string Capital string } capitals := []Capital{ {"A - B", ""}, {"", "Albany"}, {"", "Annapolis"}, {"", "Atlanta"}, {"", "Augusta"}, {"", "Austin"}, {"", "Baton Rouge"}, {"", "Bismarck"}, {"", "Boise"}, {"", "Boston"}, {"C - D", ""}, {"", "Carson City"}, {"", "Charleston"}, {"", "Cheyenne"}, {"", "Columbia"}, {"", "Columbus"}, {"", "Concord"}, {"", "Denver"}, {"", "Des Moines"}, {"", "Dover"}, {"E - J", ""}, {"", "Frankfort"}, {"", "Harrisburg"}, {"", "Hartford"}, {"", "Helena"}, {"", "Honolulu"}, {"", "Indianapolis"}, {"", "Jackson"}, {"", "Jefferson City"}, {"", "Juneau"}, {"K - O", ""}, {"", "Lansing"}, {"", "Lincoln"}, {"", "Little Rock"}, {"", "Ljubljana"}, {"", "Madison"}, {"", "Montgomery"}, {"", "Montpelier"}, {"", "Nashville"}, {"", "Oklahoma City"}, {"", "Olympia"}, {"P - S", ""}, {"", "Phoenix"}, {"", "Pierre"}, {"", "Providence"}, {"", "Raleigh"}, {"", "Richmond"}, {"", "Sacramento"}, {"", "Salem"}, {"", "Salt Lake City"}, {"", "Santa Fe"}, {"", "Springfield"}, {"", "St. Paul"}, {"T - Z", ""}, {"", "Tallahassee"}, {"", "Topeka"}, {"", "Trenton"}, {"", ""}} var iter, iter2 gtk3.TreeIter store := gtk3.NewTreeStore([]gobject.GType{gobject.G_TYPE_STRING}) for _, c := range capitals { switch { case c.Group != "": store.Append(&iter, nil) store.SetValues(&iter, gtk3.V{0: c.Group}) case c.Capital != "": store.Append(&iter2, &iter) store.SetValues(&iter2, gtk3.V{0: c.Capital}) } } return store }