Use Fyneform to stop wasting time developing Fyne GUI Forms based on Go types.
Fyneform is a code generator which generates Fyne GUI form code based on Go types without adding a dependency to your project.
| Topic | Category |
|---|---|
| Using Fyneform | 1. Define Go types 2. Configure Copygen 3. Generate Fyne Forms |
| View Output |
This demonstration (at example) generates a Fyneform for an Account Go type.
Go types are defined in a file.
./domain/domain.go
// Account represents a user's account.
type Account struct {
ID int
Username string
Password string
Name string
}Copygen is used to generate code based on Go types.
1) example/setup/copygen/setup.yml
Configure the setup.yml file.
# Define where the code is generated.
generated:
setup: ./setup.go
output: ../../app/fyneform/fyneform.go
template: ../fyneform/generate.go
matcher:
skip: true2) example/setup/copygen/setup.go
Configure the setup.go file.
package fyneform
import (
"github.com/fyneform/example/app/domain"
)
// Copygen defines the functions that are generated.
type Copygen interface {
// AccountForm represents the generated functions name which returns a &widget.Form.
//
// You can include multiple Go types (e.g., `domain.Account`) in a single form.
//
// WARNING: Do not define Go types with a pointer.
AccountForm(domain.Account)
}3) example/setup/fyneform/generate.go
Configure the generator template (e.g., copy the file).
You can modify this file to customize how a form is generated.
Install Copygen.
go install github.com/switchupcb/copygen@latest
Run the executable in a command line.
cd example/app
copygen -yml ../setup/copygen/setup.yml
You must execute this demonstration from the example/app directory so the Go types defined in the example's Go module (i.e., github.com/fyneform/example/app) are resolved correctly by the Go module system.
