A first application
From the template
go-widgets/app-template is a
template repository: a small but real browser application with a search
field, a category filter, a list of the rows that match and a status line.
Everything a larger application needs is already wired: a view-model with no
widget in it, a view bound to it, a wasm host, a 100% coverage gate, and the
MVVM gate.
git clone https://github.com/go-widgets/app-template my-app
cd my-app
go mod edit -module github.com/you/my-app
./build.sh # dist/app.wasm, dist/wasm_exec.js, dist/index.htmlServe dist/ over HTTP: a page opened from file:// cannot instantiate wasm.
| File | What it holds |
|---|---|
viewmodel.go | every piece of state, as mvvm observables and commands. No widget. Testable with no canvas. |
scene.go | the widgets, each bound to the view-model through mvvmtk. It never assigns a widget’s state field itself. |
main.go | the only file with a build tag (js && wasm): forwards input to the toolkit and blits the frame into a <canvas>. |
Edit the first two and keep state flowing through the binders: the
mvvm job in CI fails a pull request that assigns a widget’s field directly.
From a bare window
package main
import (
"github.com/go-widgets/toolkit"
"github.com/go-widgets/window"
)
func main() {
w, err := window.Open(window.Config{Title: "Demo"})
if err == window.ErrUnsupported {
return // no native back-end on this platform
}
if err != nil {
panic(err)
}
defer w.Close()
box := toolkit.NewVBox()
box.Append(toolkit.NewLabel("Hello"))
box.Append(toolkit.NewButton("Click me", func() {}))
w.Run(box) // layout, draw, present, dispatch input, until closed
}Width and height left at zero ask the back-end for a readable default; on
macOS that is a fraction of the main screen. CGO_ENABLED=0 go build produces
the binary for each platform, from any machine.
Which module for what
| You want | Start with |
|---|---|
| a desktop window | window |
| a desktop application with a tray icon and the system appearance | application |
| a page in a browser | webcanvas, or the template above |
| a terminal program | tui |
| an Android app | android |
| a picture of a widget for a README | svg |
To see the widget set before writing anything, open the gallery: every widget family, live, in a browser canvas.
Created on by tannevaled
Modified on by tannevaled