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 73b1e64209 ui/input: change Queue to return Events one at a time
By returning all events, widgets that might return early from its
event loop might throw away subsequent events. Instead of requiring
those widgets to store the event list, convert input.Queue to step
through the available events one at a time.

Functional revert of 1735d5ced8.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-08-01 18:56:49 +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 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 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 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 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 6a4ba30c96 ui/text: shorten event loop in Editor.Layout
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-12 00:05:56 +02:00
Elias Naur 37ac75f3bb ui/gesture: switch Click to return all events
Simpler and more ergonomic for clients.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-12 00:05:56 +02:00
Elias Naur 1735d5ced8 ui/input: change Events to return all events at once
Single stepping events only makes sense for widgets with complex
state, e.g. the text.Editor. For the input.Events source, returning
all events in a single Events call is sufficient and more natural
for clients.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-12 00:05:46 +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 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 ad4215a7eb ui: use ints for unit conversions to pixels
The dp and sp units are approximate and mostly used for layout
dimensions that operate in whole pixels. This change alters the
Config methods to return pixels in ints instead of floats, which
results in smoother use for layout and emphasize the inexactness of
the device independent units.

Clients can still access to raw PxPrDp and PxPrSp factors from
Config.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-10 13:31:06 +02:00
Elias Naur 51905c0aad ui/text: ignore all newlines in single line editors
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-08 14:59:32 +02:00
Elias Naur 84cd3fcdca ui/text: handle stop and scroll immediately
In case an event is returned, don't aggregate state changes in Next.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-08 00:07:51 +02:00
Elias Naur ab13a2ee73 ui/text: add Editor.Focus method
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 18:23:50 +02:00
Elias Naur 2c5b7496d2 ui/text: apply correct material for cursor
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-07 00:48:00 +02:00
Elias Naur 38ec6a8831 ui/draw: rename ColorOp.Col to Color 2019-07-05 17:14:57 +02:00
Elias Naur 0f576cf625 ui/text: use default colors to guard against empty materials
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-05 17:11:17 +02:00
Elias Naur 86bc3e612d ui/text: use BlockOp as materials
Before this change, clients were expected to set up the current
material (color or image) before laying out Labels and Editors.
This was done to avoid garbage from a hypothetical material
interface covering both colors and images.

However, some widgets need more than one material: the Editor had
HintImage for the hint text material.

This change implements generalized materials through blocks:
anywhere a material is expected, a ui.BlockOp is is assumed to
contain the operation(s) needed for setting the desired material.

This way we avoid allocations (interfaces) and keep the
abstraction over material types.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-05 16:52:13 +02:00
Elias Naur f1dffa155c ui/text: add ChangeEvent and rename Submit to SubmitEvent
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-04 15:06:50 +02:00
Elias Naur d720fa6233 ui/text: add Hint and HintImage to Editor
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-07-01 13:36:54 +02:00
Elias Naur 0546683720 ui/text: add LayoutOptions
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-30 23:58:05 +02:00
Elias Naur 28f53d8708 ui/text: add Label.MaxLines
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-30 23:51:11 +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 bebfd822d8 ui/gesture: convert Click to single step events for symmetry
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-22 17:33:29 +02:00
Elias Naur 0b6dd4efd9 ui: change events to have "Event" suffixed, not prefixed
Match the Go error naming convention (FooError).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-21 17:14:16 +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 b981ccf9ed ui/input: support single stepping through events
Change input.Events interface to return one event at a time until
the queue is empty.

Change text.Editor and gestures to match.

Re-add Editor.Submit while we're here; we don't want to enable
submit mode always.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-21 16:30:20 +02:00
Elias Naur d4eb86a9b5 ui/text: replace Editor.Update with Next for stepping through events
Before this change, the Editor cleared its content after each
Submission event. If it didn't multiple submits for a frame would
not result in the cleared text for clients that wants to clear the
Editor between submits.

However, for clients that do not want to clear the content or that
wants to validate the text before accepting it were not supported.

Instead, switch to a event stepping model, where the client can
call Next to receive each EditorEvent (that is, Submit event) in
turn.

We can then delete the Submit flag on Editor and always report Submit
events.

We can also make Layout flush the pending events now that Editor
always has access to its Config and input queue.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-21 16:17:29 +02:00
Elias Naur 98d4d926f6 ui/text: move input.Events parameter from Update to Editor state
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-21 15:35:45 +02:00
Elias Naur dda9e3486d ui/text: move Config parameter from Editor.Update to Editor state
Assume the user will set a Config pointer once at init.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-21 15:27:57 +02:00
Elias Naur 7354874bb5 ui/text: add submit events to Editor
Add Editor.Text() and fix a reset while here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-18 21:30:19 +02:00
Elias Naur 3d1e16c4d2 ui/text: unexport Editor.Command
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-18 20:26:52 +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 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 0061c73a89 ui: split OpImage into OpImage and OpDraw
In preparation for an OpColor (and future OpGradient and similar).

Label and Editor no longer take an explicit source image. They
draw with the current image.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-01 12:44:49 +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 00cb158247 ui: add Config.Sp and Config.Dp convenience methods
And rename Pixels to Val.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-16 19:32:47 +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 701ceda4d0 ui/gesture,ui/editor: don't focus and show keyboard on touch press
Wait until click for touches.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-12 18:06:18 +02:00
Elias Naur 2d7fb556a4 ui/test: invalidate Editor layout on scale changes
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-08 17:57:09 +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