Saturday, April 19, 2025

Go GUI


there are several Go packages that wrap the Windows GDI functions in a more idiomatic and less verbose interface. Here are some of the better options for creating a chess GUI:

  • Fyne: A cross-platform GUI toolkit that works on Windows and abstracts away the low-level details:
go get fyne.io/fyne/v2
fyne-io/fyne: Cross platform GUI toolkit in Go inspired by Material Design @GitHub

  • Walk: A Windows-specific GUI toolkit for Go that provides native Windows GUI capabilities:
go get github.com/lxn/walk
lxn/walk: A Windows GUI toolkit for the Go Programming Language @GitHub

  • Gio: A cross-platform GUI library with immediate mode rendering:
go get gioui.org
Gio UI

  • Ebiten: More game-focused but excellent for something like chess:
go get github.com/hajimehoshi/ebiten/v2





even without packages, Go can access Windows (and other OS) GUI features
Here is a super-simple but functional Go GUI "Hello World" program.

package main

import (
    "syscall"
    "unsafe"
)

var (
    user32      = syscall.NewLazyDLL("user32.dll") // Loads the user32.dll library dynamically
    messageBoxA = user32.NewProc("MessageBoxA")    // Gets a reference to the MessageBoxA function
)

func main() {
    messageBoxA.Call(
        0, // NULL for the parent window handle
        uintptr(unsafe.Pointer(syscall.StringBytePtr("world!"))), // message text
        uintptr(unsafe.Pointer(syscall.StringBytePtr("Hello"))),  // title
        0, // type of message box, default
    )
}