This commit adds the first fully end-to-end test. It builds a very simple Gio app, loads it on Chrome, and checks that it works. To control Chrome, we use chromedp, a library in pure Go that takes care of starting the browser and talking to it via the devtools protocol. We add the test directly in the cmd module, since it mainly interacts with the gogio tool, and also because the code might turn into some sort of 'gogio test' command in the future. This does add chromedp and ui as test dependencies to go.mod, but GOPROXY should allow a 'go get' of gogio to not download their entire source code archives. We don't replace ui with ../../ui in the go.mod, to ensure that testing the cmd module works from anywhere without unintended differences. The test app being used is inside a testdata directory, to ensure it's not go-gettable, and that it doesn't otherwise affect the cmd module. Finally, the test itself is pretty simple. The app just paints a red background, and the test verifies that, once loaded, the background of the browser viewport is indeed red. The test does currently require Chrome or Chromium to be installed, which is fine for now. It may also require a GPU, though I don't have a headless machine to check for sure. The test uses Chrome in headless mode though, so it doesn't open up any visible browser window. All in all, the test succeeds in just over a second on my laptop with Chromium 77.0.3865.75. Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Gio
Gio implements portable immediate mode GUI programs in Go. Gio programs run on all the major platforms: iOS/tvOS, Android, Linux (Wayland), macOS, Windows and browsers (Webassembly/WebGL).
Gio includes an efficient vector renderer based on the Pathfinder project (https://github.com/pcwalton/pathfinder). Text and other shapes are rendered using only their outlines without baking them into texture images, to support efficient animations, transformed drawing and pixel resolution independence.
Installation
Gio is designed to work with very few dependencies. It depends only on the platform libraries for window management, input and GPU drawing.
Running Gio programs
With Go 1.13 or newer,
$ export GO111MODULE=on
$ go run gioui.org/apps/hello
should display a simple message in a window.
The command
$ go run gioui.org/apps/gophers
runs a simple (nonsense) demo that displays Go contributors fetched from GitHub.
If you run into quota issues, supply a
Github token
with the -token flag:
$ go run gioui.org/apps/gophers -token <github token>
Running on mobiles
For Android, iOS, tvOS the gogio tool can build and package a Gio program for you.
To build an Android .apk file from the gophers example:
$ go run gioui.org/cmd/gogio -target android gioui.org/apps/gophers
The apk can be installed to a running emulator or attached device with adb:
$ adb install gophers.apk
The gogio tool passes command line arguments to os.Args at runtime:
$ go run gioui.org/cmd/gogio -target android gioui.org/apps/gophers -token <github token>
The -appid flag specifies the iOS bundle id or Android package id. The flag is required
for creating signed .ipa files for iOS and tvOS devices, because the bundle id must match an id
previously provisioned in Xcode. For example,
$ go run gioui.org/cmd/gogio -target ios -appid <bundle-id> gioui.org/apps/gophers
Use the Window->Devices and Simulators option in Xcode to install the ipa file to the device.
If you have ideviceinstaller installed,
you can install the app from the command line:
$ ideviceinstaller -i gophers.ipa
If you just want to run a program on the iOS simulator, use the -o flag to specify a .app
directory:
$ go run gioui.org/cmd/gogio -o gophers.app -target ios gioui.org/apps/gophers
Install the app to a running simulator with simctl:
$ xcrun simctl install booted gophers.app
Webassembly/WebGL
To run a Gio program in a compatible browser, the gogio tool can output a directory ready to
serve. With the goxec tool you don't even need a web server:
$ go run gioui.org/cmd/gogio -target js gioui.org/apps/gophers
$ go get github.com/shurcooL/goexec
$ goexec 'http.ListenAndServe(":8080", http.FileServer(http.Dir("gophers")))'
Open http://localhost:8080 in a browser to run the program.
Integration with existing projects
See the integration guide for details on using Gio with existing projects.
Programs using Gio
- Scatter, an implementation of the Signal protocol over email.
Resources
- FAQ.
- Gophercon 2019 talk about Gio and Scatter. Slides, Demos.
- Gophercon UK 2019 talk. Demos.
Issues
File bugs and TODOs through the issue tracker or send an email to ~eliasnaur/gio@todo.sr.ht. For general discussion, use the mailing list: ~eliasnaur/gio@lists.sr.ht.
Contributing
Post discussion and patches to the mailing list. No Sourcehut account is required and you can post without being subscribed.
See the contribution guide for more details.
License
Dual-licensed under UNLICENSE or the MIT.
Donations
Bitcoin donations are gladly accepted to bc1q8xw95urett00f4xs3v66p2l6xp2mfk5erpe5ug. Donations will go toward hosting expenses and for supporting the author's full time work on Gio.