Commit Graph

93 Commits

Author SHA1 Message Date
Elias Naur 1931582683 ui/app: (wasm) switch from <textarea> to <input> to avoid double newline
With a <textarea> DOM element pressing the enter key will result in
a "Enter" key down event and a "\n" input event. We're only
interested in the key event, so switching to a single line <input>
avoids the extra "\n".

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-09 15:11:02 +02:00
Elias Naur bd005a09e3 ui/app/internal/gpu: upload path data to GPU before re-use
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-08 18:30:04 +02:00
Elias Naur 52cea80bd4 ui: update doc comment
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-08 11:00:59 +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 28dd25736f ui/key: make the computed text input state available as a method
When merging the key and pointers input sources, we can't return
the text input state as a side effect of the Frame method.

Expose it as a method in the key event queue instead.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-07 20:59:20 +02:00
Elias Naur bb6ee05d95 ui/key: don't drop handlers that haven't had their events read
Similar to the previous change for pointers, only determine the
activeness of a handler from its presence in the ops list.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-07 20:27:22 +02:00
Elias Naur a78f9c6eaa ui/pointer: don't drop handlers that whose events haven't been read
We're about to merge the pointer and key event streams in a single
input queue. To do that, we need to simplify Queue.For to just returning
events for the given handler.

First step is the handler active flag.

Dropping handlers that haven't had their events read doesn't seem
worth it. Drop that special case and only determine a handler's activeness
from its presence in the ops list.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-07 20:25:32 +02:00
Elias Naur 56bfc6e348 ui/pointer: unexport HitResult enum
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-05 10:53:25 +02:00
Elias Naur f2679b2024 ui/pointer: add Transparent to OpArea to allow events to pass through
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-05 10:51:45 +02:00
Elias Naur b12430bab3 ui/pointer: unexport OpArea.Hit
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-05 10:46:23 +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 955fe1bc77 ui: make the reference list argument to Ops.Write variadic
Makes the code nicer.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-03 15:22:11 +02:00
Elias Naur 402837bbfa ui/pointer/queue: intersect hit areas of stacked OpAreas
Instead of using the most recent area for hit testing a pointer handler,
use the intersection of the areas up until the handler.

Fixes a bug where layout.List children received pointer events in their
clipped areas.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-03 15:21:12 +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 559db02035 ui: simplify op size and reference count code
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-03 13:30:18 +02:00
Elias Naur 86f6765e64 ui/app/internal/gl: avoid allocations when passing handles to C
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-02 22:51:33 +02:00
Elias Naur 659a85aae0 ui/app/internal/gpu: add specialized path cache to avoid key allocations
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-02 22:45:44 +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 9f58ed0fea ui: add version to OpBlock to track invalidated blocks
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-02 19:37:34 +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 bf5d083b8a ui,ui/internal/ops: store owner Ops in OpBlock
Allows users to refer to other (cached) Ops from a main Ops.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-02 19:37:34 +02:00
Elias Naur 9d661277da ui: encapsulate encoded ops in a new type, opsData
Used for making OpBlock refer to other Ops.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-02 19:17:53 +02:00
Elias Naur 0d2cffe196 ui: let OpsReader keep track of references
Instead of exposing the entire reference slice, return the relevant
references from Next.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-02 19:17:53 +02:00
Elias Naur 5966aab77e ui: move ops reader to ui package
To prepare support for cached OpBlock to refer to other Ops lists.

The exposure of OpsReader is alleviated by the removal of the Refs
and Data accessors for Ops.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-02 19:17:53 +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 7ae8fdaae7 ui/app/internal/gpu: track image and color in a state stack
Just like the other drawing state, the current image or color must
be tracked in a stack.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-01 18:43:51 +02:00
Elias Naur d752040f17 ui/draw: typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-01 18:21:58 +02:00
Elias Naur 00a87f542d ui: introduce OpColor, a specialized OpImage for uniform colors
To avoid allocating an image.Image for OpImage.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-06-01 13:01:51 +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 5cc9906eb8 ui/app: (windows) use the new golang.org/x/sys/windows.MessageBox function
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-27 11:37:33 +02:00
Elias Naur e5ddb0b903 ui/app: (macOS) use CFTypeRef for the view factory
The os and gl packages were separate in the past, which required
uintptr for cross-package CFTypeRefs. That's no longer needed.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-24 14:05:30 +02:00
Elias Naur a1c0693eeb ui/app: add Lock/Unlock to Context for macOS
Without locking, asynchronous OpenGL rendering crashes on macOS.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-24 14:01:26 +02:00
Elias Naur c3ea85801c ui/app: (wasm) replace TypedArrayOf with the CopyBytes* API
syscall/js.TypedArrayOf is going away in Go 1.13 and is replaced by
the CopyBytesToGo, CopyBytesToJS.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-24 12:30:34 +02:00
Elias Naur edec032ae6 ui/app: (wasm) re-use javascript buffer
Now that syscall/js.TypedArrayOf is going away in Go 1.13 (sse
https://golang.org/issue/31980), copying byte slices to JS before
use is necessary. To avoid garbage, re-use a single buffer for all
transfers.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-23 10:16:49 +02:00
Elias Naur 7b13da7299 ui/app: (wasm) use JS allocated buffer for invalidateFramebuffer
syscall/js.TypedArrayOf is going away in Go 1.13. Avoid it for
invalidateFramebuffer by using a buffer managed by JS.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-23 10:16:49 +02:00
Elias Naur bc481ea784 ui/app: serialize event handling
The frame callback for macOS comes in from a different thread than
the UI thread. Serialize event handling to maintain the invariant
that only one event is processed at a time.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-21 15:56:56 +02:00
Elias Naur da598663f7 ui/app: add GL buffer caches
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-16 21:47:30 +02:00
Elias Naur 642318842c ui/app/internal/gpu: add pathOp cache
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-16 21:16:36 +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 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 25ba53ea51 ui/app: (macOS) suppress key shortcuts beeps
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-16 09:59:20 +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 a6fc2b6d45 ui/app: round total and cpu times
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-13 21:41:28 +02:00
Elias Naur 3c9c38947d ui/app: (wasm) don't focus input field on mouse down or touch start
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-13 21:30:26 +02:00
Elias Naur 32c525f7fd ui/app/internal/gpu: check for GL_EXT_disjoint_timer_query_webgl2
GL_EXT_disjoint_timer_query_webgl2 is the WebGL 2 counterpart to
the WebGL 1 GL_EXT_disjoint_timer_query extension.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-13 19:50:26 +02:00
Elias Naur 90d2174090 ui/app: take input focus when initializing the HTML canvas element
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-13 12:49:43 +02:00
Elias Naur 18c74f00af ui/app/internal/gpu: check floating point FBO support
Some devices don't support floating point FBOs even though they
support OpenGL ES 3. Check support by creating a FBO and fail early
if no support is found.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-05-13 12:44:47 +02:00