tictactoe-in-go/game/window.go

47 lines
1.3 KiB
Go
Raw Normal View History

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"
)
var TextLabel *widget.Label
// 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")
// 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.
Window.SetContent(content)
Window.Resize(fyne.NewSize(300, 300))
// Return the created window.
return Window
}