experimental package to reduce boilerplate when working with the Gio immediate mode GUI.

Greg 11e2dbad38 Update Gio version. 7 months ago
cmd 11e2dbad38 Update Gio version. 7 months ago
examples f134a1f21e Add form example, add /examples directory. 7 months ago
.gitignore f134a1f21e Add form example, add /examples directory. 7 months ago
README.md a463c073ed Documentation fix. 7 months ago
grid.go 11e2dbad38 Update Gio version. 7 months ago
main.go 11e2dbad38 Update Gio version. 7 months ago
prof.go 83c9d40500 Memory profiling code. Updates to reduce memory footprint. 7 months ago

README.md

GIOWrap

An experimental wrapper package for the Gio immediate mode GUI, designed to reduce boilerplate.

go run ~/go/src/git.wow.st/gmp/giowrap/cmd/hello/main.go

The basic concept is to define a Context type that contains the Gio variables required for layout and drawing. Context contains a pointer to app.Window and ui.Ops so that, once layout is complete, you can call Context.Draw() to draw your objects in your window.

The following types and functions are defined in order to transform a Context variable during layout:

type Layout func(Context) Context

type Widget interface {
	Layout(Context) Context
}

type WidgetCombinator func(...Widget) Widget

type Enclosure interface {
	Begin(Context) Context
	End(Context) Context
}

func Enclose(e Enclosure, w ...Widget) Widget { ... }

The giowrap package also includes a private package-global variable called extra that is a []interface{}, allowing arbitrary data to be maintained by UI elements. Elements can request access to the structure when they are allocated and they are returned a unique integer index into the slice. This can be used, for example, to define themes, and control the operation of a WidgetCombinator during operation. For example:

type fWidget struct { l Layout }
func NewfWidget(l layout) fWidget { return fWidget{ l: l } }

func Flexible(v float32) Widget {
	return NewfWidget(func(ctx Context) Context {
		extra.data[extra.cur].(*FlexOpts).flexible = v
		return ctx
	})
}

...
	ctx = myFlex(
			w1,
			giowrap.Flexible(0.5),
			w2,
			giowrap.Flexible(1),
			w3,
		).Layout(ctx)
	ctx.Draw()
...