~eliasnaur/gio

gio/layout/doc.go -rw-r--r-- 1.6 KiB
layout: fix spelling of Alignment

Signed-off-by: Dan Kortschak <dan@kortschak.io>
layout: change Widget to take explicit Context and return explicit Dimensions

Change the definition of Widget from the implicit

        type Widget func()

to the explicit functional

        type Widget func(gtx layout.Context) layout.Dimensions

The advantages are numerous:

- Clearer connection between the incoming context and the output dimensions.
- Returning the Dimensions are impossible to omit.
- Contexts passed by value, so its fields can be exported
and freely mutated by the program.

The only disadvantage is the longer function literals and the many "returns".
What tipped the scales in favour of the explicit Widget variant is that type
aliases can dramatically shorten the literals:

	type (
		C = layout.Context
		D = layout.Dimensions
	)

	widget := func(gtx C) D {
		...
	}

Note that the aliases are not part of the Gio API and it is up to each user
whether they want to use them.

Finally the Go proposal for lightweight function literals,
https://github.com/golang/go/issues/21498, may remove the disadvantage
completely in future.

Context becomes a plain struct with only public fields, and its Reset is
replaced by a NewContext convenience constructor.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
doc: rewrite references to preivous api to current

Signed-off-by: Wagner Riffel <wgrriffel@gmail.com>
layout: update documentation for NewContext

Signed-off-by: Elias Naur <mail@eliasnaur.com>
all: rename package ui to unit

Package ui is now only about units except for the Config.Now method.
Remove Now and rename Config to Converter. Add layout.Config to
replace the old ui.Config.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
all: rename the gioui.org/ui module to gioui.org

The "ui" is redundant and stutters.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
all: rename more *layout.Context names to `gtx`

Signed-off-by: Elias Naur <mail@eliasnaur.com>
ui/layout: add common state to Context

Almost every layout and widget need the ui.Config for its environment,
an ui.Ops to store operations. Stateful widgets need an input.Queue
for events.

Add all these common objects to Context, greatly simplifying the
function signatures for Gio programs.

Fixes gio#33

Signed-off-by: Elias Naur <mail@eliasnaur.com>
ui/layout: make Align a Direction

Removes the stutter by simplifying

	layout.Align{Alignment: layout.NE}

to

	layout.Align(layout.NE)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
ui/layout: introduce Context

Context keeps the current Constraints and Dimensions so the layout
function scopes don't have to.

With

	ctx := new(layout.Context)

a label with margins and alignment goes from

	return al.Layout(ops, cs, func(cs layout.Constraints) layout.Dimensions {
		in := layout.Inset{...}
		return in.Layout(c, ops, cs, func(cs layout.Constraints) layout.Dimensions {
			return text.Label{...}.Layout(ops, cs)
		})
	})

to

	al.Layout(ops, ctx, func() {
		in := layout.Inset{...}
		in.Layout(c, ops, ctx, func() {
		       text.Label{...}.Layout(ops, ctx)
		})
	})

It was a difficult trade-off between the verbose functional approach
and the shorter but more complex Context.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
ui/layout: update documentation to reflect the function scope changes

Signed-off-by: Elias Naur <mail@eliasnaur.com>
README, ui/layout: fix typos

Signed-off-by: Kenshi Kamata <kenshi.kamata@gmail.com>
all: rename layout.Dimens to layout.Dimensions

Dimens is only 4 characters shorter and not worth the abbreviation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
ui: documentation fixes

Signed-off-by: Elias Naur <mail@eliasnaur.com>
ui/layout: expand package documentation

Signed-off-by: Elias Naur <mail@eliasnaur.com>
Next