Skip to content

A first application

Start from app-template, already MVVM-compliant and green, or open a bare window and add widgets.

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.html

Serve dist/ over HTTP: a page opened from file:// cannot instantiate wasm.

FileWhat it holds
viewmodel.goevery piece of state, as mvvm observables and commands. No widget. Testable with no canvas.
scene.gothe widgets, each bound to the view-model through mvvmtk. It never assigns a widget’s state field itself.
main.gothe 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 wantStart with
a desktop windowwindow
a desktop application with a tray icon and the system appearanceapplication
a page in a browserwebcanvas, or the template above
a terminal programtui
an Android appandroid
a picture of a widget for a READMEsvg

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