Commit Graph

52 Commits

Author SHA1 Message Date
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
Elias Naur 4ec352727e ui/layout: remove unused isInf
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-09 17:05:38 +02:00
Elias Naur 99be31bc26 ui/layout: convert Sized and Insets to use ui.Value
Layout objects are usually ephemereal, but when saved and re-used
between frames their measurements are not updated with varying pixel
density and font scaling.

Go back to storing unconverted ui.Values instead of raw pixels,
and convert them at each use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-09 11:28:41 +02:00
Elias Naur 683df6345b ui/layout: fix Flex spacing
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-01 19:22:06 +02:00
Elias Naur ef9384ceee ui/layout: allow one-line initialization of Flex and Stack
Returning itself from the Init methods allows the client to
initialize the layout instance on one line.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-27 12:44:15 +02:00
Elias Naur 4f94f1078a ui/gesture: rename Scroller.Update to Scroller.Scroll
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-22 17:36:57 +02:00
Elias Naur 7aa7bb3be4 ui: rename ops to have Op suffixed, not prefixed
Match Go's FooError name pattern.

While we're here, rename RedrawOp to InvalidateOp.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-21 17:01:45 +02:00
Elias Naur 898c3c5d7d ui/layout: unexport List.Update and move its parameters to state
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-21 16:17:29 +02:00
Elias Naur c1e129a87d ui/layout: implement List.Invert for end aligned lists
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-19 19:46:11 +02:00
Elias Naur c511858d30 ui/layout: add sanity checks to Insets/Align Begin/End
Would have caught the invalid layout re-use fixed by a recent commit.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-17 17:36:47 +02:00
Elias Naur d67b7eca6c ui/draw,ui/layout: export OpClip
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-17 16:45:49 +02:00
Elias Naur a35118d522 ui: add package input for merged input
To avoid passing a queue type for each kind of input (pointer, key),
introduce package input for mapping a handler key to all input events.

Future input sources can be added without changes to programs, and
as an added bonus, event ordering is preserved across input sources.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-08 10:58:57 +02:00
Elias Naur df791f2e9b ui: remove ui.Ops parameters from layouts and path builder structs
Layouts and path builders are transient and need an ops list for
operation. However, instead of passing the ops list to every method,
pass the list in an init method and store it for subsequent methods.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-03 16:08:38 +02:00
Elias Naur 40856a244e ui/pointer: introduce OpArea for pointer hit testing
Split out OpArea from OpHandler to allow stacked areas in a followup.

Replace hit closures with static shapes (rectangles and ellipses) to
avoid allocations. If needed, generic hit functions can be introduced
again later.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-03 14:54:26 +02:00
Elias Naur 1e38eec0ab ui: build paths as ops
Instead of allocating and constructing a clip path, store path data
directly in op lists. Use separate op lists for cached text layout
paths.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-02 22:18:04 +02:00
Elias Naur 9142345fd4 ui: make OpPush and OpPop explicit
We're about to allow OpBlock for invoking ops from multiple (cached)
Ops containers. To allow for drawing state changes to stick after
invoking such a cached block, we can't let OpBlock perform an implicit
save and restore of drawing state.

Instead, introduce OpPush and OpPop for explicit drawing state stack
management.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-02 19:37:34 +02:00
Elias Naur 1c880f2b9d ui/layout: activate sanity checks for Stack
Added by an earlier change, but not activated.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-02 15:14:46 +02:00
Elias Naur a7874d70ef ui: rename event methods to Update
For uniformity.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-30 21:55:52 +02:00
Elias Naur 9b3429d6da ui: switch to (more) explicit layout
The layout package switched from interfaces to functions for
composing layouts. The switch made sure that no garbage is
generated for transient layouts such as Align, Inset, Stack, Flex.

Unfortunately, that left the stateful widgets and layouts: as soon
as their layout methods are embedded in a transient layout, a
closure is generated that escapes to the heap.

To avoid garbage for both transient as well as stateful widgets,
replace the functional approach with explicit begin/end methods.

A begin method generally starts an op block and returns the adjusted
constraints. An end method takes computed dimensions, ends its op
block and returns adjusted dimensions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-30 21:39:00 +02:00
Elias Naur 2d96e760d3 ui/layout,ui/text,ui/widget: shorten Widget function names to W
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-16 15:41:43 +02:00
Elias Naur e436dce0e7 ui/layout: make layout API explicit
With layout.Widget a function instead of an interface, the amount
of per-frame garbage can be drastically reduced.

The layout code ends up slightly more explicit.

As a side benefit, the awkward ordering indexing for Flex and Stack
fit nicely into their new explicit Layout methods.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-16 11:44:17 +02:00
Elias Naur d98f579048 ui/layout: remove unused layout.Interface
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-14 16:02:24 +02:00
Elias Naur 56133632c6 ui/layout: rename simple.go to layout.go
A more appropriate name.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-04-27 22:24:20 +02:00
Elias Naur 252e058766 all: serialize ops
Pros:
- Much less per-frame garbage
- Allow future preprocessing of ops while building it
- Much fewer interface calls and pointer chasing
- Allow future serialization of ops for remote rendering

Cons:
- Slightly clumsier API

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-04-27 22:19:34 +02:00
Elias Naur a8bb3c2f14 all: make pointer.Area an interface
With an interface instead of anonymous functions, amending an
area's parameters can be done even after adding it to an OpHandler.

This will be useful when we switch to serialized op lists.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-04-25 10:02:14 +02:00