~eliasnaur/gio

gio/layout/example_test.go -rw-r--r-- 2.8 KiB
layout: make list example use List.Position.Count

Counting the number of displayed elements via the ListElement function is incorrect.

Signed-off-by: pierre <pierre.curto@gmail.com>
layout: add WeightSum to Flex for overriding the Flexed total weight

Updates gio#139

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: make Flexed weight a weight, not a ratio

It's more intuitive to specify the weight as a ratio of the total
weight of all Flexed children than to specify the ratio of the
flexable space.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
layout,widget: transpose Constraints to use image.Points for limits

Instead of

    type Contraints struct {
	    Width, Height Constraint
    }

use

    type Constraints struct {
	    Min, Max image.Point
    }

which leads to simpler use. For example, the Min method is trivally replaced by
the field, and the RigidConstraints constructor is no longer a net win.

API Change. Rewrites:

    gofmt -r 'gtx.Constraints.Min() -> gtx.Constraints.Min'
    gofmt -r 'gtx.Constraints.Width.Min -> gtx.Constraints.Min.X'
    gofmt -r 'gtx.Constraints.Height.Min -> gtx.Constraints.Min.Y'
    gofmt -r 'gtx.Constraints.Height.Max -> gtx.Constraints.Max.Y'
    gofmt -r 'gtx.Constraints.Width.Max -> gtx.Constraints.Max.X'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: replace NewContext with a Queue argument to Context.Reset

We're about to reduce the scope of the Window.Queue by moving it
to FrameEvent. As a consequence, Context can no longer rely on a
Queue constant over its lifetime.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: replace Align with a Layout method on Direction

It's one less type (Align) and shorter:

Before:

	layout.Align(layout.Center).Layout(...)

After

	layout.Center.Layout(...)

It is also safer: since `layout.Align(...)` was a casting operation,
the Go compiler would not complain about an incompatible constant.

For example, the widget/material package contained a wrong cast:

	layout.Align(layout.Start)

which should have been

	layout.Align(layout.W)

After this change, attempting `layout.Start.Layout(...)` result
in a compile error.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: simplify Stack API

Similar to what a previous commit did for Flex, this change simplifies
Stack to just one Layout call:

	layout.Stack{}.Layout(gtx,
		layout.Stacked(func() {...}),
		layout.Expanded(func() {...}),
	)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: simplify Flex API to a single Layout call

With the simplification of MacroOp, it is now possible to simplify
the Flex API to just a single Layout method, similar to List:

	layout.Flex{}.Layout(gtx,
		layout.Rigid(func() { ... }),
		layout.Flexed(0.5, func() { ... }),
	)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: move examples to example_test.go

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: add NewContext, make zero value Contexts useful

While here, unexport the Queue and Config fields. The NewContext
cosntructor is shorter, and there is no reason to expose the fields
to accidental mutation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: update tests

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: rename Flex.Flexible to just Flex

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: delete Init methods from Flex and Stack

With Context containing all the necessary information, separate
Init methods no longer makes much sense. Delete them and thereby
remove a source of runtime panics.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
layout: take a size, not constraints in Context.Reset

Taking a constraint in Reset smells too much of a layout operation,
whereas a size is simpler and only serves to set the context constraints
to something sensible.

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>
io/event: move event types from package ui to its own package

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>
ui/layout,ui/app: fix tests, go fmt, update comments

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: merge package input

Event handling is as fundamental as operations, so move the input
package declarations to package ui.

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