43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package game
|
|
|
|
import (
|
|
"tictactoe/theme"
|
|
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/app"
|
|
"fyne.io/fyne/v2/container"
|
|
"fyne.io/fyne/v2/layout"
|
|
"fyne.io/fyne/v2/widget"
|
|
)
|
|
|
|
// creates a window for the TicTacToe game application.
|
|
func CreateWindow() fyne.Window {
|
|
// Create the app.
|
|
App := app.New()
|
|
|
|
// Adding a theme to my Window
|
|
App.Settings().SetTheme(theme.TicTacToeTheme{})
|
|
// Create a new window for the game application.
|
|
Window := App.NewWindow("TicTacToe")
|
|
|
|
// create the 3x3 Button grid
|
|
matchField := MakeButtonGrid(3, 3, Window)
|
|
// 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(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.
|
|
Window.SetContent(content)
|
|
Window.Resize(fyne.NewSize(300, 300))
|
|
|
|
// Return the created window.
|
|
return Window
|
|
}
|