43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package game
|
|
|
|
import (
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/app"
|
|
"fyne.io/fyne/v2/container"
|
|
"fyne.io/fyne/v2/layout"
|
|
"fyne.io/fyne/v2/widget"
|
|
)
|
|
|
|
var TextLabel *widget.Label
|
|
|
|
// creates a window for the TicTacToe game application.
|
|
func CreateWindow() fyne.Window {
|
|
// Create the app.
|
|
myApp := app.New()
|
|
|
|
// Create a new window for the game application.
|
|
myWindow := myApp.NewWindow("TicTacToe")
|
|
|
|
// Set the text of our TextLabel to TicTacToe
|
|
TextLabel = widget.NewLabel("TicTacToe")
|
|
// create the 3x3 Button grid
|
|
matchField := MakeButtonGrid(3, 3)
|
|
// Create a new button and a handler function, if it gets pressed.
|
|
restartButton := widget.NewButton("Restart", func() {
|
|
ResetButtonTexts(matchField)
|
|
})
|
|
|
|
// vertical box layout containg the top Items, here the textlabel and the button.
|
|
topItems := container.NewVBox(TextLabel, restartButton)
|
|
|
|
// Generate content for the window using a border layout with the topItems and matchField as the children
|
|
content := container.New(layout.NewBorderLayout(topItems, nil, nil, nil), topItems, matchField)
|
|
|
|
// Set the content and size of the window.
|
|
myWindow.SetContent(content)
|
|
myWindow.Resize(fyne.NewSize(300, 300))
|
|
|
|
// Return the created window.
|
|
return myWindow
|
|
}
|