What is Fyne.io
Fyne is a free and open-source cross-platform widget toolkit for creating graphical user interfaces (GUIs) across desktop and mobile platforms.
Site: https://fyne.io
GitHub: https://github.com/fyne-io/fyne
Setup Go environment on Mac M1
Mac version: 12.4 (ARM_64)
Version management: asdf vm
Shell: zsh + ohmyzsh
Go version: 1.18.3
Setup go with asdf
asdf plugin-add golang https://github.com/kennyp/asdf-golang
asdf install golang 1.18.3
asdf global golang 1.18.3
asdf reshim golang
Setup GOPATH
GOROOT
GOBIN
most annoying thing
Edit .zshrc
## Paste it after . $HOME/.asdf/asdf.sh
export GO111MODULE=on
export GOROOT=$(go env GOROOT)
export GOPATH=$(go env GOPATH)
export GOBIN=$GOPATH/bin
PATH="$GOROOT:$PATH"
PATH="$GOPATH:$PATH"
PATH="$GOBIN:$PATH"
Install Fyne cmd globally
# Install
go install fyne.io/fyne/v2/cmd/fyne@latest
# Test
❯ fyne -v
fyne version v2.2.0
Install Fyne sample demo
# Install
go install fyne.io/fyne/v2/cmd/fyne_demo@latest
# Run
> fyne_demo
2022/06/12 04:51:22 Lifecycle: Started
2022/06/12 04:51:23 Lifecycle: Entered Foreground
2022/06/12 04:51:25 Lifecycle: Exited Foreground
Setup a Fyne project with Visual Studio Code
Make a directory for your project
mkdir fyne-example && cd fyne-example
Init with go mod
go mod init FyneExample
Get the dependencies
go get fyne.io/fyne/v2
go mod tidy
Paste code below into main.
go
package main
import (
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func main() {
a := app.New()
w := a.NewWindow("Hi Mom!")
hello := widget.NewLabel("Ya Mom :D ")
w.SetContent(container.NewVBox(
hello,
widget.NewButton("Say Hi!", func() {
hello.SetText("Welcome :)")
}),
))
w.ShowAndRun()
}
Save and build binary, and run
# Build and manually execute binary file
go build
./FyneExample
# Run directly
go run main.go
Hope you enjoy it.
I plan release some tutorial by learning Fyne soon.
Something like a personal app for saving WIFI password for Coffee shop nearby my place.
References
- https://eddwardo.github.io/posts/gopath-and-goroot/
- https://gist.github.com/rubencaro/5ce32fb30bbfa70e7db6be14cf42a35c/2d804bb26e82cdcf9a43d7527e0cd74ae5ffd3c6Fyne is a free and open-source cross-platform widget toolkit for creating graphical user interfaces (GUIs) across desktop and mobile platforms.