Commit Graph

57 Commits

Author SHA1 Message Date
Viktor b247395c62 gpu, io/router, op: use f32.Affine2D instead of op.TransformOp for transforms
Encode TransformOp as an Affince2D matrix instead and use that in gpu and io transform handling.
There are no changes to user facing API and so far only the offset part of the matrix is used.

This patch is a step towards full affine transformations.

Signed-off-by: Viktor <viktor.ogeman@gmail.com>
2020-06-21 11:17:42 +02:00
Elias Naur 596e321610 all: make unit.Converter concrete and rename to Metric
An interface for scaling dp and sp is overkill, at least for all
current uses. Make it a concrete struct type, and rename it to the
shorter and more precise Metric.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-17 11:47:14 +02:00
Elias Naur 6380baacb6 all: move Now from system.Config to system.FrameEvent
Then, make layout.Context.Now a field, copied from FrameEvent.Now.

API change:

	gofmt -r 'gtx.Now() -> gtx.Now'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-09 23:23:08 +02:00
Elias Naur 1c6809142f io/router: report Enter events for touch press events
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-09 00:10:49 +02:00
Elias Naur 652f1ecd47 io/router: deliver Release before Leave
Fixes a problem where a touch Release would signal gesture.Click
that it had left just before click would complete.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 21:31:23 +02:00
Elias Naur 700d8d8c2c io/router: merge grab and types for multiple InputOps for same handler
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 15:01:14 +02:00
Elias Naur ea85e80dc8 io/router: support multiple pointer areas for same tag
Fixes gio#129

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 14:53:19 +02:00
Elias Naur 1c68b7d585 io/router: shorten tests by using f32.Pt short-hand
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 14:44:41 +02:00
Elias Naur 35e477757b io/router: remove redundant pointerHandler.transform field
The area transform is already stored in areaNode.

Updates gio#129

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-08 13:05:06 +02:00
Elias Naur d280d438c7 io/router: don't clear event queue before cancel events
There may be unrelated events in the queue, so it's not appropriate
to clear the queue just because an input Cancel event occurs.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-07 18:20:18 +02:00
Elias Naur 4f64ac1736 io/pointer: remove special case note
Scroll events are no longer special after gioui.org/commit/65d4707e3.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-05 11:45:55 +02:00
Elias Naur 65d4707e3e io/pointer,io/router,gesture: add pointer.Foremost priority
Replace the pointer.Scroll special case with a new priority that
indicates the foremost handler, checked in gesture.Scroll.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-05 10:46:19 +02:00
Gordon Klaus 1a070a36b6 io/pointer: add Drag event type
This eliminates needless redraws for handlers that care about drag events and not move events, like gesture.Scroll.

Signed-off-by: Gordon Klaus <gordon.klaus@gmail.com>
2020-06-03 20:04:16 +02:00
Gordon Klaus 33a87ac61c io/router: deliver scroll events only to the foremost scroll handler
Signed-off-by: Gordon Klaus <gordon.klaus@gmail.com>
2020-06-03 15:38:56 +02:00
Gordon Klaus 9d2a6c48d8 io/pointer: add InputOp.Types to specify which types of events to receive
Signed-off-by: Gordon Klaus <gordon.klaus@gmail.com>
2020-06-03 15:29:12 +02:00
Gordon Klaus e188d0e6ff io/pointer,gesture,app/internal/window: add pointer.Scroll event type
Signed-off-by: Gordon Klaus <gordon.klaus@gmail.com>
2020-06-03 10:08:22 +02:00
Elias Naur 275a91f26a io/router: remove countPointerEvents
assertEventSequence is shorter and clearer and more precise.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-03 10:03:53 +02:00
Elias Naur d489c20b84 io/pointer: update documentation examples
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-02 16:37:38 +02:00
Elias Naur ff71d0c518 io/router: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-02 14:20:40 +02:00
Thomas Bruyelle ae8a377cda op: add op.Push and op.Record funcs
The funcs replace stack.Push and macro.Record, which become private.
This makes stack and macro faster to write, in particular for stacks
where you can just write the following line to save and restore the
state :

  defer op.Push(ops).Pop()

This usage requires Push to return a pointer (since Pop has a pointer
receiver), or else the code doesn't compile.

For consistancy, I tried to do the same for op.Record, but this implied
to turn all the MacroOp fields into pointers, and this caused some
panics. As a result, op.Record doesn't return a pointer.

An other side effect pointed by Larry Clapp: StackOp and MacroOp are not
re-usable any more, you have to allocate a new one for each usage, using
the described funcs above.

Signed-off-by: Thomas Bruyelle <thomas.bruyelle@gmail.com>
2020-06-02 10:39:56 +02:00
Elias Naur 3b28c5d067 io/router: simplify pointer event routing
- Drop pointer.Event.Hit in favour of Enter/Leave events.
- Track enter/leaves for each pointer.ID (updates #122). Add test.
- Resolve grabs once.
- Get rid of scratch slice.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-01 00:04:34 +02:00
Elias Naur 23c2d44b8c io/router: add addPointerHandler convenience function
Remove a redundant call and shorten image.Rectangle literals while here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-31 13:29:15 +02:00
Elias Naur 67a9d9e9d7 io/system: improve FrameEvent documentation
Phrase stolen from Egon's architecture document.

Replace tabs with spaces in the example while here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-18 17:52:54 +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
Elias Naur 268e9e44b8 io/system: add ClipboardEvent for sending clipboard updates
Not wired up yet; each platform needs implementing low-level access
first.

Updates gio#31

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-17 15:43:12 +02:00
Elias Naur 81f474f5d7 op/paint,io/system: document ImageOp lifetime
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-14 13:15:05 +02:00
Elias Naur 3fd1ccbbed io/router: fix ellipse hit function
The previous formula was simply wrong.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 12:15:54 +02:00
Elias Naur a046f15156 io/router: return boolean expressions directly
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 11:57:37 +02:00
Chris Waldon 29a9e5bc27 io/router: fix Enter/Leave during press events
This commit updates the implementation of the Enter/Leave pointer
events so that it no longer shares any state with the processing
of pointer presses and grabs. This simplifies the implementation,
though it does leave a certain amount of structural redundancy.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-05-09 08:47:01 +02:00
Chris Waldon c1f0f9b5c7 io/router: improve benchmark by trying multiple sizes
This commit improves the usefulness of the benchmark by automatically
measuring event processing times with a range of values for the complexity
of the UI.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-05-09 08:46:56 +02:00
Chris Waldon b2f1776670 io/router: fix enter/leave event tests and add more
This commit fixes a bug which concealed test failures when
the actual event sequence was empty but the expected events
were not.

Additionally, this commit adds the following tests:

- a test for when the active input
area disappears while it is still being "hovered".
- a test for when there are two nested input areas that are
being hovered

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-05-09 08:46:53 +02:00
Chris Waldon 13941c9f1b io/router: add tests for Enter/Leave pointer events
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-05-04 14:41:28 +02:00
Chris Waldon 1c113f19c6 io/router: send pointer Enter/Leave events
This commit introduces a naive system for sending events
when a pointer enters or leaves a pointer hit area.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-05-04 14:41:25 +02:00
Chris Waldon 6501ecf2a0 io/pointer: define new Enter/Leave pointer events
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-05-04 14:41:21 +02:00
Elias Naur 8d9612f9aa layout,app,io/system: move Queue from app.Window to FrameEvent
Change gioui.org/commit/0e70fbc1262920a69c60409285795b6bb8701b09
added a note that app.Window.Queue must only be used during the
processing of a FrameEvent. The change was added because a Gio
user took the existence of app.Window.Queue to mean it was always
available.

This change reduces the scope of window Queues by moving it from Window
to FrameEvent, and minimizes the risk of misuse by not offering
Window.Queue at all.

Note that the gioui.org/commit/a937a7653439333b8c6fc30c7a6039b717339766
change moved Window's Frame method (named Update) to FrameEvent for the
same reason.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:04:52 +02:00
Elias Naur 050f43d60a io/router: add pointer drag-and-move test
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-29 10:11:23 +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 8a2837531e io/router: add pointer routing test
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 09:22:48 +01:00
Elias Naur 5a3ffad00a io/router: expand Router.Add to accept multiple events
Niver API and useful for testing.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 09:08:56 +01:00
steverusso fd5dfacb40 io/pointer: minor documentation update.
The `image.Rectangle` object should be passed to the `pointer.Rect` function.

Signed-off-by: steverusso <steverusso@protonmail.com>
2020-02-12 09:04:47 +01:00
Elias Naur 34c6a2f735 io/router: expose the event router
For integrating with external window implementations (replacing
package app), access to the event router is required. Extract it
and put it into the new package router.

Router may belong in package io/event, but can't without introducing
import cycles.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-07 20:41:04 +01:00
Elias Naur 2aa6071e33 io/system: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-12-02 12:38:48 +01:00
Larry Clapp 65bc7be256 app/internal/window: allow punctuation as keycode events
Allows things like "ctrl-{" and ".".

All punctuation is returned as-is, e.g. "!" is "!", not "shift-1", and
"{" is "{", not "shift-[".

Also add the Enter key as a known key (fn-return on my Mac).

Signed-off-by: Larry Clapp <larry@theclapp.org>
2019-11-24 19:41:11 +01:00
Larry Clapp f8de7545f4 several: add modifiers to mouse events and clicks
macOS only, for the os-specific bits.

Signed-off-by: Larry Clapp <larry@theclapp.org>
2019-11-18 15:38:09 +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 dc7f9bab23 io/pointer,gesture: report right and middle mouse button events
Updates gio#60

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 17:41:39 +01:00
Elias Naur de7d6b28fa io/key: add support for the Tab and Space keys
Fixes gio#62

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-09 11:57:36 +01:00
Elias Naur cc43588aba io/key: switch Event.Name to be a string and add function keys
Function keys don't have a natural rune representation so switch
Event.Name to be a string to fit "F1"-"F12".

Fixes gio#59

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-08 22:20:17 +01:00
Elias Naur c833c98fd7 io/key: add ModAlt, ModSuper
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-08 18:39:21 +01:00
Elias Naur d293dfe604 key: add ModCtrl, ModShortcut
ModCtrl is the physical Ctrl key, ModShortcut is the virtual
"shortcut" modifier, which is Ctrl on most platforms, Command on
Apple platforms.

Updates #59

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-08 18:02:26 +01:00