// ShowWindow shows the UI after invocation func (this *GUI) ShowWindow(errorsToDisplay, warningsToDisplay []error) { guiError := ui.Main(func() { log.Info("Showing GUI") contentBox := ui.NewVerticalBox() contentBox.SetPadded(true) this.Window = ui.NewWindow("QL", 800, 600, false) this.Window.OnClosing(func(w *ui.Window) bool { log.Info("Destroy of window initiated") this.Symbols.SaveToDisk() ui.Quit() return true }) this.Window.SetChild(contentBox) this.Window.SetMargined(true) this.Window.Show() // if there are any errors/warnings, show a dialog if errorsPresent := this.showErrorDialogIfNecessary(errorsToDisplay); !errorsPresent { this.showWarningDialogIfNecessary(warningsToDisplay) this.ShowForm() } }) if guiError != nil { log.WithFields(log.Fields{"guiError": guiError}).Panic("Encountered GUI error") } }
func main() { err := ui.Main(func() { name := ui.NewEntry() button := ui.NewButton("Greet") greeting := ui.NewLabel("") box := ui.NewVerticalBox() box.Append(ui.NewLabel("Enter your name:"), false) box.Append(name, false) box.Append(button, false) box.Append(greeting, false) window := ui.NewWindow("Hello", 200, 100, false) window.SetChild(box) button.OnClicked(func(*ui.Button) { greeting.SetText("Hello, " + name.Text() + "!") }) window.OnClosing(func(*ui.Window) bool { ui.Quit() return true }) window.Show() }) if err != nil { panic(err) } }
func main() { err := ui.Main(initGUI) if err != nil { panic(err) } log.Println("The end") }
func main() { file, err := os.Open("document.json") if err != nil { panic(err) } defer file.Close() buffer := new(bytes.Buffer) _, err = buffer.ReadFrom(file) if err != nil { panic(err) } var document uidoc.Element err = ui.Main(func() { document, err = uidoc.Parse(buffer.Bytes()) if err != nil { panic(err) } font := ui.LoadClosestFont(&ui.FontDescriptor{ Family: "Deja Vu", Size: 12, }) name := ui.NewEntry() button := ui.NewButton("Greet") doc := uidoc.New() doc.SetDocument(document) box := ui.NewVerticalBox() box.Append(ui.NewLabel("Enter your name:"), false) box.Append(name, false) box.Append(button, false) box.Append(doc, true) window := ui.NewWindow("Hello", 400, 700, false) window.SetChild(box) button.OnClicked(func(*ui.Button) { element := uidoc.NewText("Hello, "+name.Text()+"!", font) document.(*uidoc.Group).Append(element) doc.Layout() }) window.OnClosing(func(*ui.Window) bool { ui.Quit() return true }) window.Show() }) if err != nil { panic(err) } }