giokit

module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: MIT

README

giokit

[!WARNING] Work in progress: giokit is under active development and pre-1.0. There are no tagged releases yet, and APIs may change before a stable release.

giokit is a cross-platform UI toolkit for Go (desktop, mobile, and WebAssembly) built on Gio and modeled after GPUI.

State lives in plain Go structs owned by the UI goroutine. Each frame handles pending input first and then lays out the window from that state. Components are plain structs paired with explicit state values, styled from theme tokens, and tested headlessly.

The giokit gallery

Example

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/hhhapz/giokit/gio/layout"
	"github.com/hhhapz/giokit/gio/widget"
	"github.com/hhhapz/giokit/kit"
	"github.com/hhhapz/giokit/kit/ui"
)

type view struct {
	th         *kit.Theme
	count      int
	inc, greet kit.Clickable
	name       widget.Editor
	toasts     ui.Toasts
}

func (v *view) Frame(gtx layout.Context) {
	// 1. Handle input.
	if v.inc.Clicked(gtx) {
		v.count++
	}
	if v.greet.Clicked(gtx) {
		v.toasts.Push(kit.StatusGood, "Hello, "+v.name.Text(), "")
	}

	// 2. Draw from state.
	th := v.th
	kit.Fill(gtx, th.Bg, func(gtx layout.Context) layout.Dimensions {
		return ui.ToastHost{Page: func(gtx layout.Context) layout.Dimensions {
			return kit.Flex{Axis: layout.Vertical, Gap: kit.Space3, Pad: kit.Space6}.Layout(gtx, th,
				kit.Rigid(func(gtx layout.Context) layout.Dimensions {
					return th.Heading(gtx, fmt.Sprintf("Clicked %d times", v.count))
				}),
				kit.Rigid(func(gtx layout.Context) layout.Dimensions {
					return ui.Button{ID: "inc", Text: "Click me", Style: ui.Solid}.Layout(gtx, th, &v.inc)
				}),
				kit.Rigid(kit.Fixed(240, func(gtx layout.Context) layout.Dimensions {
					return ui.TextField{ID: "name", Placeholder: "Your name"}.Layout(gtx, th, &v.name)
				})),
				kit.Rigid(func(gtx layout.Context) layout.Dimensions {
					return ui.Button{ID: "greet", Text: "Greet"}.Layout(gtx, th, &v.greet)
				}),
			)
		}}.Layout(gtx, th, &v.toasts)
	})
}

func main() {
	v := &view{th: kit.Dark()}
	a := kit.NewApp("hello", "Hello", 480, 320)
	go func() {
		if err := a.Run(v.Frame); err != nil {
			log.Fatal(err)
		}
		os.Exit(0)
	}()
	kit.Main()
}

Testing it headlessly with kittest (examples/hello/main_test.go):

func TestHello(t *testing.T) {
	v := &view{th: kit.Dark()}
	h := kittest.NewT(t, 480, 320, v.Frame)
	h.Theme = v.th

	h.ClickID("inc")
	h.ClickID("inc")
	h.ExpectText("Clicked 2 times")

	h.ClickID("name")
	h.Type("Ada")
	h.ClickID("greet")
	h.ExpectText("Hello, Ada")

	h.ExpectClean()
	h.ExpectTabReachable()
}

Running Examples and Tests

go run ./examples/hello
go run ./examples/gallery
go run ./examples/music
go run ./examples/padtest
go test ./...

Installation

go get github.com/hhhapz/giokit@latest

giokit includes its own fork of Gio in gio/ (github.com/hhhapz/giokit/gio/...). Import Gio packages from github.com/hhhapz/giokit/gio/... rather than gioui.org/... (see docs/gio-patches.md).

Documentation

Guides:

  • Getting Started: Setting up a window, structuring Frame, managing state, and running background tasks.
  • Layout and Theming: Flex layout, responsive screens, scrolling, OKLCH themes, design tokens, and fonts.
  • Components: Using kit/ui and kit/x widgets and writing custom controls.
  • Input, Persistence, and Platforms: Keyboard shortcuts, gamepads, saving data, native dialogs, WebAssembly, and mobile builds.
  • Graphics, Shaders, and Media: DrawCache, fragment shaders, paint layers, video decoding, and audio output.
  • Testing: Headless UI testing with kittest, conformance checks, and frame profiling.

Internals:

  • Architecture: Frame lifecycle, focus and key dispatch, semantic model, and cost model.
  • Pitfalls: Common Gio and immediate-mode bugs and how to avoid them.
  • Gio Fork: Upstream sync workflow and summary of changes in gio/.

Contributing

See CONTRIBUTING.md.

License

MIT, see LICENSE. The Gio fork in gio/ keeps its upstream license (Unlicense OR MIT).

Directories

Path Synopsis
Package desktop is giokit's bridge to the operating system: native file choosers and opening links.
Package desktop is giokit's bridge to the operating system: native file choosers and opening links.
examples
gallery command
Command gallery shows every giokit component: the kitchen sink and the reference for how an app is structured (handle → layout, ids on everything, keymap for navigation, theme as a value you can swap at runtime).
Command gallery shows every giokit component: the kitchen sink and the reference for how an app is structured (handle → layout, ids on everything, keymap for navigation, theme as a value you can swap at runtime).
hello command
Command hello is the smallest useful giokit app: a counter, a text field and a toast.
Command hello is the smallest useful giokit app: a counter, a text field and a toast.
music command
Music is a no-audio app sketch for exercising media-oriented giokit APIs.
Music is a no-audio app sketch for exercising media-oriented giokit APIs.
padtest command
Command padtest prints what kit/pad sees, for checking a controller without an app: pads connecting, button presses and releases (by the standard layout and as the pad labels them), and stick and trigger movement.
Command padtest prints what kit/pad sees, for checking a controller without an app: pads connecting, button presses and releases (by the standard layout and as the pad labels them), and stick and trigger movement.
scrolltest command
Command scrolltest is a bench for wheel/touchpad scroll smoothness.
Command scrolltest is a bench for wheel/touchpad scroll smoothness.
gio
app
Package app provides a platform-independent interface to operating system functionality for running graphical user interfaces.
Package app provides a platform-independent interface to operating system functionality for running graphical user interfaces.
app/internal/xkb
Package xkb implements a Go interface for the X Keyboard Extension library.
Package xkb implements a Go interface for the X Keyboard Extension library.
app/permission
Package permission includes sub-packages that should be imported by a Gio program or by one of its dependencies to indicate that specific operating-system permissions are required.
Package permission includes sub-packages that should be imported by a Gio program or by one of its dependencies to indicate that specific operating-system permissions are required.
app/permission/bluetooth
Package bluetooth implements permissions to access Bluetooth and Bluetooth Low Energy hardware, including the ability to discover and pair devices.
Package bluetooth implements permissions to access Bluetooth and Bluetooth Low Energy hardware, including the ability to discover and pair devices.
app/permission/camera
Package camera implements permissions to access camera hardware.
Package camera implements permissions to access camera hardware.
app/permission/foreground
Package foreground implements permission to keep running while not in front, as app.StartForeground does.
Package foreground implements permission to keep running while not in front, as app.StartForeground does.
app/permission/microphone
Package microphone implements permissions to access microphone hardware.
Package microphone implements permissions to access microphone hardware.
app/permission/networkstate
Package networkstate implements permissions to access network connectivity information.
Package networkstate implements permissions to access network connectivity information.
app/permission/storage
Package storage implements read and write storage permissions on mobile devices.
Package storage implements read and write storage permissions on mobile devices.
app/permission/wakelock
Package wakelock implements permission to acquire locks that keep the system from suspending.
Package wakelock implements permission to acquire locks that keep the system from suspending.
cmd/gogio command
The gogio tool builds and packages Gio programs for Android, iOS/tvOS and WebAssembly.
The gogio tool builds and packages Gio programs for Android, iOS/tvOS and WebAssembly.
f32
Package f32 is a float32 implementation of package image's Point and affine transformations.
Package f32 is a float32 implementation of package image's Point and affine transformations.
font
Package font provides type describing font faces attributes.
Package font provides type describing font faces attributes.
font/gofont
Package gofont exports the Go fonts as a text.Collection.
Package gofont exports the Go fonts as a text.Collection.
font/opentype
Package opentype implements text layout and shaping for OpenType files.
Package opentype implements text layout and shaping for OpenType files.
gesture
Package gesture implements common pointer gestures.
Package gesture implements common pointer gestures.
gpu
Package gpu implements the rendering of Gio drawing operations.
Package gpu implements the rendering of Gio drawing operations.
gpu/headless
Package headless implements headless windows for rendering an operation list to an image.
Package headless implements headless windows for rendering an operation list to an image.
gpu/internal/rendertest
Package rendertest is intended for testing of drawing ops only.
Package rendertest is intended for testing of drawing ops only.
gpu/internal/rendertest/testshaders
Package testshaders holds the paint shaders of rendertest's paint.ShaderOp tests (giokit patch).
Package testshaders holds the paint shaders of rendertest's paint.ShaderOp tests (giokit patch).
internal/byteslice
Package byteslice provides byte slice views of other Go values such as slices and structs.
Package byteslice provides byte slice views of other Go values such as slices and structs.
internal/cocoainit
Package cocoainit initializes support for multithreaded programs in Cocoa.
Package cocoainit initializes support for multithreaded programs in Cocoa.
internal/debug
Package debug provides general debug feature management for Gio, including the ability to toggle debug features using the GIODEBUG environment variable.
Package debug provides general debug feature management for Gio, including the ability to toggle debug features using the GIODEBUG environment variable.
internal/f32
Package f32 is an internal version of the public package f32 with extra types for internal use.
Package f32 is an internal version of the public package f32 with extra types for internal use.
internal/keylayout
Package keylayout tracks which key name the current keyboard layout gives each physical key.
Package keylayout tracks which key name the current keyboard layout gives each physical key.
internal/scene
Package scene encodes and decodes graphics commands in the format used by the compute renderer.
Package scene encodes and decodes graphics commands in the format used by the compute renderer.
internal/stream
Package stream is the state shared by paint.Stream (producer and layout) and the GPU renderer (consumer).
Package stream is the state shared by paint.Stream (producer and layout) and the GPU renderer (consumer).
internal/stroke
Package stroke implements conversion of strokes to filled outlines.
Package stroke implements conversion of strokes to filled outlines.
io/event
Package event contains types for event handling.
Package event contains types for event handling.
io/input
Package input implements input routing and tracking of interface state for a window.
Package input implements input routing and tracking of interface state for a window.
io/key
Package key implements key and text events and operations.
Package key implements key and text events and operations.
io/pointer
Package pointer implements pointer events and operations.
Package pointer implements pointer events and operations.
io/semantic
Package semantic provides operations for semantic descriptions of a user interface, to facilitate presentation and interaction in external software such as screen readers.
Package semantic provides operations for semantic descriptions of a user interface, to facilitate presentation and interaction in external software such as screen readers.
io/transfer
Package transfer contains operations and events for brokering data transfers.
Package transfer contains operations and events for brokering data transfers.
layout
Package layout implements layouts common to GUI programs.
Package layout implements layouts common to GUI programs.
op
Package op implements operations for updating a user interface.
Package op implements operations for updating a user interface.
op/clip
Package clip provides operations for defining areas that applies to operations such as paints and pointer handlers.
Package clip provides operations for defining areas that applies to operations such as paints and pointer handlers.
op/paint
Package paint provides drawing operations for 2D graphics.
Package paint provides drawing operations for 2D graphics.
shader/giokit
Package giokit holds the shaders giokit adds to Gio's renderer for paint.ShaderOp and transformed paint layers.
Package giokit holds the shaders giokit adds to Gio's renderer for paint.ShaderOp and transformed paint layers.
unit
Package unit implements device independent units.
Package unit implements device independent units.
widget
Package widget implements state tracking and event handling of common user interface controls.
Package widget implements state tracking and event handling of common user interface controls.
widget/material
Package material implements the Material design.
Package material implements the Material design.
x/styledtext
Package styledtext provides rendering of text containing multiple fonts and styles.
Package styledtext provides rendering of text containing multiple fonts and styles.
kit
Package kit is a toolkit layer over Gio for dense, keyboard-first desktop tools.
Package kit is a toolkit layer over Gio for dense, keyboard-first desktop tools.
fonts
Package fonts holds giokit's curated font sets, bundled so text renders the same on every machine.
Package fonts holds giokit's curated font sets, bundled so text renders the same on every machine.
forktrace
Package forktrace adds Gio's low-level window events (wl_*, scroll_flush, gpu_frame, present) to GIOKIT_TRACE output, in order with kit's own lines, through the fork's app.GiokitTrace hook.
Package forktrace adds Gio's low-level window events (wl_*, scroll_flush, gpu_frame, present) to GIOKIT_TRACE output, in order with kit's own lines, through the fork's app.GiokitTrace hook.
pad
Package pad reads game controllers on every platform giokit runs on and turns them into per-frame button events.
Package pad reads game controllers on every platform giokit runs on and turns them into per-frame button events.
store
Package store keeps an app's persistent data: small named entries, such as settings, a saved game or a sync token, each read and replaced whole.
Package store keeps an app's persistent data: small named entries, such as settings, a saved game or a sync token, each read and replaced whole.
ui
Package ui holds giokit's components, built only from package kit's exported API: anything here could be written outside giokit.
Package ui holds giokit's components, built only from package kit's exported API: anything here could be written outside giokit.
x
Package x holds specialised widgets built on kit and kit/ui: a log view and a lyrics view.
Package x holds specialised widgets built on kit and kit/ui: a log view and a lyrics view.
x/video
Package video draws streaming images (video, camera, remote screens) with Video, from a paint.Stream (in giokit's Gio fork).
Package video draws streaming images (video, camera, remote screens) with Video, from a paint.Stream (in giokit's Gio fork).
Package kittest drives a giokit UI headlessly: real layout, real input routing, real GPU rendering (EGL surfaceless), no window or display.
Package kittest drives a giokit UI headlessly: real layout, real input routing, real GPU rendering (EGL surfaceless), no window or display.
conform
Package conform is the conformance suite every interactive giokit control must pass.
Package conform is the conformance suite every interactive giokit control must pass.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL