experimental package to reduce boilerplate when working with the Gio immediate mode GUI.
Go to file
Greg 92cb4d20a4 Cleanups and comments. 2019-08-15 18:32:01 -04:00
cmd/hello Cleanups and comments. 2019-08-15 18:32:01 -04:00
README.md Add README.md 2019-08-15 09:34:47 -04:00
main.go Cleanups and comments. 2019-08-15 18:32:01 -04:00

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
}

func LayoutWithContext(ctx Context, ws ...Widget) Context {
	for _, w := range ws {
		ctx = w.Layout(ctx)
	}
	return ctx
}

type WidgetCombinator func(...Widget) Widget

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

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

The Context struct also contains a map[string]interface{} allowing arbitrary data to be maintained. 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 (f Flex) Flexible(v float32) Widget {
	return NewfWidget(func(ctx Context) Context {
		ctx.extra["Flexible"] = v
		return ctx
	})
}

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