Commit Graph

76 Commits

Author SHA1 Message Date
Elias Naur 2d8072fbbb ui/layout: replace "interface element" with "widget" in documentation
Now that we have a Widget type, use it in the documentation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-22 16:19:07 +02:00
Elias Naur 4a1e0a30cb ui/layout: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-19 18:53:45 +02:00
Elias Naur 3817b19bbe ui/layout: update documentation to reflect the function scope changes
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-18 22:57:14 +02:00
Elias Naur 31f7f04181 ui/layout: clean up after function scope change
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-18 22:03:08 +02:00
Elias Naur 29639565cd ui/layout: replace implicit begin/end scopes with explicit function scopes
Before this change, layout objects followed a pattern where a
begin method would set up the layout and return a tweaked set
of constraints, and a end method would take the widget dimensions
and return the tweaked dimensions.

As has been pointed out, this process is error prone, because the
scope of the layout objects are not clear and because it is easy
to swap two begins or two ends.

It turns out that it is possible to implement layout with function
scopes in garbage free way. A typical layout changes from

        al := layout.Align{Alignment: layout.NE}
	cs = al.Begin(ops, cs)
	in := layout.Inset{Top: ui.Dp(16)}
	cs = in.Begin(c, ops, cs)
	txt := fmt.Sprintf("m: %d %s", mallocs, u.profile.Timings)
	dims := text.Label{Material: theme.text, Face: u.face(fonts.mono, 10), Text: txt}.Layout(ops, cs)
	dims = in.End(dims)
	return al.End(dims)

to

        al := layout.Align{Alignment: layout.NE}
	return al.Layout(ops, cs, func(cs layout.Constraints) layout.Dimensions {
	       in := layout.Inset{Top: ui.Dp(16)}
	       return in.Layout(c, ops, cs, func(cs layout.Constraints) layout.Dimensions {
		       txt := fmt.Sprintf("m: %d %s", mallocs, u.profile.Timings)
		       return text.Label{Material: theme.text, Face: u.face(fonts.mono, 10), Text: txt}.Layout(ops, cs)
	       })
	})

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-18 19:31:36 +02:00
Elias Naur 6ad154419b ui/layout: rename List.Invert to ScrollToEnd
Much clearer.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-05 21:15:37 +02:00
Elias Naur 7d93a2790c ui/layout: delete List.Distance field
Distance was meant to be used for implementing nested scrollers, but
I don't think the API is right. For example, Distance doesn't report
residual fling scrolling.

Delete the field while we wait for a better approach.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-05 20:41:09 +02:00
Elias Naur 1529f20eb7 ui/layout: rewrite List
Inverted lists used to behave as if its top and bottom edges were
flipped. That was easy but also wrong: when the underlying children
changed size, they would move relative to the top edge of the list.

As illustrated by issue gio#34, Invert should only do two things:

- End lign lists smaller than the containing area.
- Scroll to end, but only as long as the user hasn't scrolled away.

List also had a bug where it didn't handle shrinking lists, so
this change rewrites List to fix that bug, fix Invert behaviour and
hopefully be a little simpler.

Fixes gio#34
2019-09-05 20:27:08 +02:00
Kenshi Kamata 82b0563c8b README, ui/layout: fix typos
Signed-off-by: Kenshi Kamata <kenshi.kamata@gmail.com>
2019-09-03 19:26:00 +02:00
Elias Naur 5766a8d226 ui/layout: avoid accumulating rounding errors from Flexible
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-30 21:15:18 +02:00
Elias Naur 12089ea62a 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>
2019-08-30 15:00:17 +02:00
Elias Naur a296903c76 ui: documentation fixes
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-11 19:50:03 +02:00
Elias Naur 40091c5918 ui/gesture: add Scroll.State method
And move Click.State to a method.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-11 18:18:27 +02:00
Elias Naur e3ae277841 ui/layout: add List example
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 18:54:18 +02:00
Elias Naur b3e8f5953e ui/layout: add Stack example
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 18:46:18 +02:00
Elias Naur 44d16d04e9 ui/layout: add Flex example
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 18:41:01 +02:00
Elias Naur 94f2752885 ui/layout: add Align example
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 18:28:19 +02:00
Elias Naur 4ce8f4ea51 ui/layout: add Inset example
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 18:18:18 +02:00
Elias Naur 3c941e938f ui/layout: expand package documentation
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 17:56:16 +02:00
Elias Naur 8f37a565b9 ui/layout: document layout types and helpers
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 17:09:35 +02:00
Elias Naur ba3a952af2 ui/layout: document List, Stack
Tweak Flex documentation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 16:49:02 +02:00
Elias Naur 8f17163a13 ui/layout: rename List.Elem to End to match Stack and Flex
Add more documentation while we're here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 16:26:39 +02:00
Elias Naur 6d1339733a apps: update gioui.org/ui
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 12:34:58 +02:00
Elias Naur 1a15d7241a ui/layout: rename and sanitize enums
Rename MainAxisAlignment to Spacing and CrossAxisAlignment to just
Alignment.

Drop the untyped Start, End, Center values and add them as Spacing
and Direction values. Center is both a Direction and Alignment, so
use the synonym "Middle" for the alignment.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-10 12:29:17 +02:00
Elias Naur dd35a48a61 ui/paint: rename the draw package
The draw package name clashes with the standard library draw package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-07 20:11:53 +02:00
Elias Naur bfece0beba ui: change area ops to use rectangles, not sizes
And then use the more general rectangles to add a buffer around
text.Editor click and scroll area.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-01 10:06:19 +02:00
Elias Naur 3d9861011e ui/layout: restore Flex.Rigid behaviour
Broken by 5f2adf9b2f.

Clamp to 0 while we're here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-30 15:25:23 +02:00
Elias Naur 5f2adf9b2f ui: get rid of Inf
It's not worth the special cases. Use a large value where needed
(layout.List, text.Editor...) instead.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-29 12:12:51 +02:00
Elias Naur 5e1f078b12 ui: merge Transform into TransformOp
The separate Transform type is not worth its weight.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-29 02:50:55 -07:00
Elias Naur b6290990ad ui/text,ui/layout: move ui.Config and input.Queue to parameters
I too often forget to initialize widgets' config and queue. Moving
them from fields to parameters fix that. The change results in a
little more verbosity but cleaner code.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-21 11:44:48 +02:00
Elias Naur fd096e8838 ui/input,ui/layout: update comments
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-16 14:30:59 +02:00
Elias Naur 586d33c26e ui: replace PushOp, PopOp with a StackOp
Before this change, there was no guarantee that a PopOp matched
the intended PushOp. With a single stack operation, the client is
forced to match pop with the right push.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-16 13:49:32 +02:00
Elias Naur 94a913a371 ui: move macro recording from Ops to MacroOp
Move the Record and Stop methods from Ops to MacroOp itself.

Before this change, Ops.Stop stopped the recording of the most
recent macro, which could be a different macro than intended.
After this change, there is no such confusion.

As a bonus, the Ops API becomes less cluttered.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-16 13:21:51 +02:00
Elias Naur eb9c2896cd ui/layout: round, not truncate, flex sizes in Flex.Flexible
Without proper rounding, a pixel could be left uncovered at the end
of the flex layout.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-15 21:43:53 +02:00
Elias Naur 00b9ff603f ui/layout: rename Insets to Inset and EqualInsets to UniformInset
Rename Insets to the verb Inset for consistency with Align.

Uniform is a better description than Equal for the result of
UniformInset.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-15 21:10:43 +02:00
Elias Naur 3b5fcfe2bb ui: rename block to macro
It is a more precise name.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-15 20:36:17 +02:00
Elias Naur f36070f716 ui/layout: delete Constraints.Expand and Constraints.Loose
They're not (yet) shown their use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-15 19:29:42 +02:00
Elias Naur 667670f9c6 ui/layout: delete Constraints.Exact and rename ExactConstraints
Exact was too special and can be expressed with RigidConstraints.

RigidConstraints is a better name ("rigid" was in the comment!)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-15 19:16:11 +02:00
Elias Naur a22bcfc88c ui/input: rename Queue to Router and Events to Queue
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-12 00:05:56 +02:00
Elias Naur 0d49eb3f4b ui/layout: drop CrossAxisAlignment value Stretch
It doesn't carry its own weight; client can just as easily adjust
the Constraints themselves.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 20:13:10 +02:00
Elias Naur 10ef4576e7 ui/layout: drop Flex.MainAxisSize setting and MainAxisSize type
The setting doesn't bear its own weight; it's simpler for the client
to adjust the constraints itself.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 19:15:17 +02:00
Elias Naur c7e85efc27 ui/layout: ensure that flex weights add to 1
Before this change, the weight applied to the space left, not the
total space available after rigid children.

While here, ensure that weight sums > 1 are capped to the available
space.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 19:06:27 +02:00
Elias Naur 449c2b844a ui/layout: drop FlexMode
The type and argument to Flex.Flexible does not carry its weight;
It is just as easy to expand the constraint directly.

While we're here, rename the flex argument to weight which is clearer.
2019-07-11 18:44:44 +02:00
Elias Naur fe4a61ec89 ui/layout: make List more friendly to for loops
With this change, a List l can be iterated with

    for l.Init(...); l.More(); l.Next() {
        l.Elem(..., l.Constraints(), l.Index())
    }

instead of

   l.Init(...)
   for {
       i, cs, ok := l.Next()
       if !ok {
               break
       }
       l.End(..., cs, i))
    }

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 18:07:16 +02:00
Elias Naur 896f5a77dd ui/layout: don't stretch Align child
Let the caller decide whether the constraints should be stretched.

Also unexport Constraint (not Constraints) methods, they weren't
pulling their weight.

Finally, don't force cross axis constraint minimum to 0 in List.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-11 09:18:56 +02:00
Elias Naur 4fadf71992 ui/pointer: split AreaOp into RectAreaOp and EllipseAreaOp
Now that the pass through mode is moved into its own PassOp op,
it doesn't make sense to collect all area types into one exported
type.

Add RectAreaOp and EllipseAreaOp for clients; the internal
representation is still a single op. It can be changed later without
breaking clients.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-10 22:55:16 +02:00
Elias Naur f44ccec043 ui/pointer: simplify pointer pass through
Get rid of the confused LayerOp and the transparent property from
AreaOp. Add an explicit PassOp to specify whether pointer events
pass-through the current area.

Let AreaOp swallow events even when no handlers are active for the
area. That behaviour is less surprising and allow clients to disable
a widget by keeping its areas but leave out its handlers.

Simplify the pointer.HitResult enum to just a bool: hit or no hit.

Finally, simplify the pointer queue by tracking parent areas and
node with indices.
2019-07-10 22:43:03 +02:00
Elias Naur 32aae18293 ui,ui/app: convert Config to an interface
To keep the interface slim, remove the helper methods and shorten
the essential method, Pixels, to Px.

Add and use unexported Config implementation in the app package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-10 17:20:55 +02:00
Elias Naur 320579814f ui: rename Config.Val to Pixels
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-10 14:00:44 +02:00
Elias Naur 25af3e3701 ui/layout: replace Sized struct with simpler Constraint.Exact method
While here, add String methods to ui.Value and ui.Unit.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-10 11:18:45 +02:00