From 8be17d7c7dd423664357d2ccdb57fb4175347c75 Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Tue, 23 Apr 2024 13:54:28 +0200 Subject: [PATCH] added a function to create the window for the UI. --- game/window.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/game/window.go b/game/window.go index f876790..c68a8e5 100644 --- a/game/window.go +++ b/game/window.go @@ -1 +1,41 @@ 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 a new button with the text "Restart" and a handler function, if it gets pressed. + restartButton := widget.NewButton("Restart", func() { + // Add logic here to restart the game. + }) + + // 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 as the only child. + content := container.New(layout.NewBorderLayout(topItems, nil, nil, nil), topItems) + + // Set the content and size of the window. + myWindow.SetContent(content) + myWindow.Resize(fyne.NewSize(300, 300)) + + // Return the created window. + return myWindow +}