Skip to content

Instantly share code, notes, and snippets.

@cryptix
Created January 8, 2015 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cryptix/a37dd97c21087d7b990a to your computer and use it in GitHub Desktop.
Save cryptix/a37dd97c21087d7b990a to your computer and use it in GitHub Desktop.
example usage of msgbox
package main
import (
"flag"
"github.com/andlabs/ui"
"github.com/cryptix/go/msgbox"
)
var (
mainW ui.Window
started chan struct{}
newText chan string
)
func initGui() {
read := ui.NewButton("Read")
tf := ui.NewTextField()
read.OnClicked(func() {
newText <- tf.Text()
})
stack := ui.NewVerticalStack(
read,
tf,
)
stack.SetStretchy(1)
mainW = ui.NewWindow("TestGui", 200, 300, stack)
mainW.OnClosing(func() bool {
ui.Stop()
return true
})
mainW.Show()
close(started)
}
func doStuff() {
<-started
for t := range newText {
if len(t) > 0 && t != "nice" {
msgbox.New(mainW, "Wrong input", "please enter nice")
}
}
}
func main() {
flag.Parse()
started = make(chan struct{})
newText = make(chan string)
go ui.Do(initGui)
go doStuff()
if err := ui.Go(); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment