Commit Graph

62 Commits

Author SHA1 Message Date
Elias Naur 013ea395b4 all: use new rectangle and point convenience functions
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 11:03:30 +02:00
Elias Naur d82eb8fc66 layout,f32: add convenience functions for rectangles and points
layout.FRect, layout.FPt for converting from integer to floating point,
useful for drawing operations.

f32.Pt is a shorthand that mirrors image.Pt.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 10:59:32 +02:00
Elias Naur dac8ffc002 layout: add Exact for constructing rigid Constraints matching a size
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 10:12:11 +02:00
Elias Naur 8a6d4f699c layout: expand Stack documentation
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 10:05:27 +02:00
Elias Naur 7bf3265ccd 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>
2020-05-19 09:58:07 +02:00
Elias Naur 03db2817ac all: rename io/event.Key to Tag
Key had an unfortunate association with keyboard input.

This is an API change. The following rewrites were run to fixup
Gio code:

        $ gofmt -r 'pointer.InputOp{Key:a} -> pointer.InputOp{Tag:a}' -w .
        $ gofmt -r 'pointer.InputOp{Key:a, Grab:b} -> pointer.InputOp{Tag:a, Grab:b}' -w .
        $ gofmt -r 'key.InputOp{Key:a} -> key.InputOp{Tag:a}' -w .
        $ gofmt -r 'key.InputOp{Key:a, Focus:b} -> key.InputOp{Tag:a, Focus:b}' -w .
        $ gofmt -r 'event.Key -> event.Tag' -w .

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 19:48:12 +02:00
Wagner Riffel 4bbc6379ed doc: rewrite references to preivous api to current
Signed-off-by: Wagner Riffel <wgrriffel@gmail.com>
2020-05-13 12:59:33 +02:00
Elias Naur 4e20ea83a1 widget/material: use cosntraints for setting pointer hit areas
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 12:23:18 +02:00
Elias Naur 289fe02b90 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>
2020-05-03 21:03:40 +02:00
Elias Naur d350f82011 layout: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 17:13:08 +02:00
Elias Naur 148a2828e7 layout: don't force Expanded Stack children larger than their minimum
Instead, honor the constraints after laying out both Stacked and
Expanded children.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-29 14:06:25 +01:00
Elias Naur bfb50cef5d all: remove unused fields, functions and add missing error handling
Credit to staticcheck.io.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 22:26:54 +01:00
Elias Naur 60904dd9a6 layout: fix typos
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-14 21:17:44 +01:00
Elias Naur fb7337f794 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>
2020-02-02 17:13:02 +01:00
Elias Naur 18cddc0300 layout: include Expanded sizes in Stack size calculation
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-01-16 13:20:50 +01:00
Elias Naur 7814da47a0 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>
2019-12-12 00:45:36 +01:00
Elias Naur f60a5c7ac3 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>
2019-12-12 00:45:36 +01:00
Elias Naur edc81ea0bb op: remove operation list argument from MacroOp.Add
The ability to invoke other operation lists belongs in the new CallOp.

While we're here, make MacroOp.Add use a pointer receiver to match the
other methods.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-12 00:45:36 +01:00
Elias Naur 65dc6797eb layout: don't allow overlapping Flex and Stack layouts
Overlapping layouts such as

	outer := layout.Flex{}
	inner := layout.Stack{}
	child := inner.Rigid(gtx, ...)
	outerChild := outer.Rigid(gtx, func() {
		inner.Layout(gtx, child)
	})
	outer.Layout(gtx, outerChild)

runs but result in a wrong layout.

This change use empty StackOps to ensure that the Stack and Flex
child layout methods are called in the same scope as their Layout
methods:

	outer := layout.Flex{}
	inner := layout.Stack{}
	outerChild := outer.Rigid(gtx, func() {
		child := inner.Rigid(gtx, ...)
		inner.Layout(gtx, child)
	})
	outer.Layout(gtx, outerChild)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-02 18:54:35 +01:00
Elias Naur 3701e2eb1d layout: move examples to example_test.go
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-02 17:46:40 +01:00
Elias Naur c0beeb5e77 layout: update documentation for NewContext
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-02 13:21:35 +01:00
Elias Naur 11506a974e 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>
2019-12-02 13:13:15 +01:00
Elias Naur bbdedfa4a7 layout: move Context to its own file
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-02 12:43:42 +01:00
Elias Naur 75d4eaff0e layout: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-02 12:41:52 +01:00
Larry Clapp ce76c2e996 layout: make list scroll position settable
Put List.{first|offset|beforeEnd} into a new exported Position slot, and
also export each individually.

Have to put BeforeEnd into the Position slot to support ScrollToEnd
lists.

Signed-off-by: Larry Clapp <larry@theclapp.org>
2019-11-26 17:53:29 +01:00
Elias Naur 16cc51ee8a io/pointer: unify area ops into a single AreaOp
Make Rect and Ellipse constructors of AreaOp.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-18 15:03:11 +01:00
Elias Naur 7299d1c875 op/clip: replace Rect and RoundRect with Rect type
Remembering the order of the corners in the RoundRect is difficult,
which suggest that RoundRect should be a struct with named fields.

Do that, and make Rect the special case where corner radii are all
zero.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-18 14:33:28 +01:00
Elias Naur 65c783179d clip: change Rect argument to f32.Rectangle
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 19:42:19 +01:00
Elias Naur e864ac3fc3 op/clip: split clip operations into its own package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 19:07:00 +01:00
Elias Naur c4ac40e609 layout: remove Format
Move Format to eliasnaur.com/giox/layout because it's not clear it
belongs in the Gio standard library.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-23 10:53:59 +02:00
Elias Naur afcff9c8b5 layout: fix comment
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-21 10:38:58 +02:00
Elias Naur dafb180176 layout: fix ambiguous parsing of stack and flex arguments
Fixed gio#44

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-21 01:04:31 +02:00
Elias Naur 79d505623a layout: parse empty names and let higher levels generate errors
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-21 01:04:31 +02:00
Elias Naur c07b520157 layout: rename formatState to formatter
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-21 01:04:31 +02:00
Elias Naur 32d51dd9e6 layout: fix spelling of "northeast"
Fixes gio#45

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-21 01:04:19 +02:00
Elias Naur 5c0f1ed954 layout: update tests
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-17 14:22:24 +02:00
Elias Naur 862061b363 layout: rename "exp" layout variants to "max"; add "min" variants
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-17 13:55:30 +02:00
Elias Naur d7694ae95f layout: add "exp" format layout for expanding both constraints
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 20:51:20 +02:00
Elias Naur 759900902a layout: fix Flex baseline
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 20:35:24 +02:00
Elias Naur b1643e5e2a layout: skip Flex and Stack Layout when scanning format string
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 20:29:17 +02:00
Elias Naur f442512888 layout: more doc fixes for layout.Format
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 18:00:57 +02:00
Elias Naur 80b1af3024 layout: fix godoc.org rendering of layout.Format docs
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 17:59:04 +02:00
Elias Naur c76490956d layout: add support for layout format strings
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 17:44:13 +02:00
Elias Naur 7f07933eb3 layout: unexport Context.Layout and make it a function
Layout wasn't used outside package layout, so let's not export it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 11:08:52 +02:00
Elias Naur e2d0b3cfca layout: invert baseline to measure positive distance from bottom
With an inverted baseline, the zero value results in the widget
baseline aligned to its bottom.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 00:49:52 +02:00
Elias Naur 8e3d03f2c4 layout: correct Align baseline
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 00:49:52 +02:00
Elias Naur 4bbad66947 layout: adjust only max constraints on Inset
Only adjust minimums, and insets, if necessary.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-16 00:49:52 +02:00
Elias Naur 45ccbbe571 layout: expand Flex children
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-15 23:33:31 +02:00
Elias Naur fd1fa85998 layout: allow Expand children to fill the available area
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-15 23:33:31 +02:00
Elias Naur 2990ceda69 layout: relax constraints in Stack.Rigid
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-15 17:59:23 +02:00