2014-11-25 17:35:17 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/andlabs/ui"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-11-26 21:09:56 -06:00
|
|
|
// This runs the code that displays our GUI.
|
|
|
|
// All code that interfaces with package ui (except event handlers) must be run from within a ui.Do() call.
|
2014-11-25 17:35:17 -06:00
|
|
|
go ui.Do(gui)
|
|
|
|
|
|
|
|
err := ui.Go()
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func gui() {
|
2014-11-26 21:09:56 -06:00
|
|
|
// All windows must have a control inside.
|
|
|
|
// ui.Space() creates a control that is just a blank space for us to use.
|
2014-11-25 17:35:17 -06:00
|
|
|
newControl := ui.Space()
|
|
|
|
|
2014-11-26 21:09:56 -06:00
|
|
|
// Then we create a window.
|
2014-11-25 17:35:17 -06:00
|
|
|
w := ui.NewWindow("Window", 280, 350, newControl)
|
2014-11-26 21:09:56 -06:00
|
|
|
|
|
|
|
// We tell package ui to destroy our window and shut down cleanly when the user closes the window by clicking the X button in the titlebar.
|
2014-11-25 17:35:17 -06:00
|
|
|
w.OnClosing(func() bool {
|
2014-11-26 21:09:56 -06:00
|
|
|
// This informs package ui to shut down cleanly when it can.
|
2014-11-25 17:35:17 -06:00
|
|
|
ui.Stop()
|
2014-11-26 21:09:56 -06:00
|
|
|
// And this informs package ui that we want to hide AND destroy the window.
|
2014-11-25 17:35:17 -06:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2014-11-26 21:09:56 -06:00
|
|
|
// And finally, we need to show the window.
|
2014-11-25 17:35:17 -06:00
|
|
|
w.Show()
|
|
|
|
}
|