コード例 #1
0
ファイル: main.go プロジェクト: jmptrader/goui-example
func main() {
	//	Tell goui where to find HTML/CSS/JavaScript content.
	goui.SetAssetPath("assets/") //	Use a real path during debugging...
	goui.SetBindataSource(Asset) //	But wrap it all up in a bindata blob for deployment.

	//	Assign handlers for incoming goui messages (sent via goui.SendMessage on the JavaScript side)
	goui.SetMessageHandler("examples.showPopup", showExamplePopup)
	goui.SetMessageHandler("examples.spawnThread", spawnThread)

	//	Start running goui. This method does not return until the user exits the program.
	goui.Run(func() {
		//	Create a new main window.
		mainWindow := goui.OpenWindow(goui.WindowOptions{
			Template:    "templates/main.html",
			StyleFlags:  goui.WindowResizable | goui.WindowClosable | goui.WindowMinimizable,
			PercentLeft: 10, PercentTop: 10,
			PercentWidth: 75, PercentHeight: 75,
			RememberGeometry: true,
		})

		//	Set a callback to exit the application when the main window is closed.
		mainWindow.SetCloseHandler(func(window *goui.Window) {
			fmt.Println("Main window closed. Exiting.")
			goui.Stop()
		})

		//	Push a message to the main window; just throw some general data at it to show this works.
		u, _ := user.Current()
		mainWindow.Send(goui.Message{"showName", goui.Data{"name": u.Name}})
	})

	fmt.Println("Exited gracefully.")
}
コード例 #2
0
ファイル: main.go プロジェクト: jmptrader/goui-example
func showExamplePopup(window *goui.Window, request *goui.Message) (response goui.Data) {
	inputText, ok := request.Params["data"].(string)
	if !ok || len(inputText) == 0 {
		inputText = "Nothing!"
	}

	popupWindow := goui.OpenWindow(goui.WindowOptions{
		Template: "templates/popup.html",
		//		StyleFlags: goui.WindowModal,
		Centered:   true,
		PixelWidth: 500, PixelHeight: 250,
	})

	popupWindow.SetCloseHandler(func(window *goui.Window) {
		//	Code to run when the popup closes (if any) goes here.
		fmt.Println("Looks like you closed a popup.")
	})

	popupWindow.Send(goui.Message{"showMessage", goui.Data{"inputText": inputText}})

	return
}