func CreateMainMenu(p *Pidrive, i chan Intent, names []string, tasks []Task) *mainMenu { this := new(mainMenu) this.i = i font := p.Fonts["Tiny Font"] if font == nil { log.Fatalln("Couldn't get Tiny Font") } iconFont := p.Fonts["Icon Font"] if font == nil { log.Fatalln("Couldn't get Icon Font") } if len(names) != len(tasks) { log.Fatalln("names and tasks must be same length") } this.view = ui.NewView(nil, "Main Menu") this.view.SetWidth(WIDTH) this.view.SetHeight(HEIGHT) this.view.Visible = true this.list = ui.NewList(this.view.Widget, font, iconFont) this.list.Title = "Main Menu" this.list.SetWidth(WIDTH) this.list.SetHeight(HEIGHT) this.list.AutoHeight = false //this.list.selected = 0 this.tasks = make([]Task, 0, len(tasks)) for i, n := range names { this.list.AddItem(n, 0, mainMenuAction, tasks[i].Name()) this.tasks = append(this.tasks, tasks[i]) } this.view.AddChild(this.list) return this }
func CreateLedMenu(p *Pidrive, basename string, values [4]int) *ledMenu { this := new(ledMenu) paths := [4]string{strings.Join([]string{basename, "red"}, "/"), strings.Join([]string{basename, "green"}, "/"), strings.Join([]string{basename, "blue"}, "/"), strings.Join([]string{basename, "speed"}, "/")} this.Leds = leds.NewLeds(paths, values) font := p.Fonts["Tiny Font"] if font == nil { log.Fatalln("Couldn't get Tiny Font") } iconFont := p.Fonts["Icon Font"] if font == nil { log.Fatalln("Couldn't get Icon Font") } this.view = ui.NewView(nil, "LED Menu") this.view.SetWidth(WIDTH) this.view.SetHeight(HEIGHT) this.view.Visible = false this.list = ui.NewList(this.view.Widget, font, iconFont) this.list.SetWidth(25) this.list.SetHeight(HEIGHT - 8) this.list.AutoHeight = false this.list.SetPos(image.Point{0, 8}) //this.list.selected = 0 this.list.AddItem("R:", 0, ledListAction, this) this.list.AddItem("G:", 0, ledListAction, this) this.list.AddItem("B:", 0, ledListAction, this) this.list.AddItem("S:", 0, ledListAction, this) this.view.AddChild(this.list) this.redBar = ui.NewProgressBar(this.view.Widget) this.redBar.SetWidth(WIDTH - 25) this.redBar.SetHeight(8) this.redBar.SetPos(image.Point{26, 8}) this.redBar.Max = 255 this.redBar.Progress = values[leds.RED] this.view.AddChild(this.redBar) this.greenBar = ui.NewProgressBar(this.view.Widget) this.greenBar.SetWidth(WIDTH - 25) this.greenBar.SetHeight(8) this.greenBar.SetPos(image.Point{26, 16}) this.greenBar.Max = 255 this.greenBar.Progress = values[leds.GREEN] this.view.AddChild(this.greenBar) this.blueBar = ui.NewProgressBar(this.view.Widget) this.blueBar.SetWidth(WIDTH - 25) this.blueBar.SetHeight(8) this.blueBar.SetPos(image.Point{26, 24}) this.blueBar.Max = 255 this.blueBar.Progress = values[leds.BLUE] this.view.AddChild(this.blueBar) this.speedBar = ui.NewProgressBar(this.view.Widget) this.speedBar.SetWidth(WIDTH - 25) this.speedBar.SetHeight(8) this.speedBar.SetPos(image.Point{26, 32}) this.speedBar.Max = 255 this.speedBar.Progress = values[leds.SPEED] this.view.AddChild(this.speedBar) this.focus = this.list return this }