Commit Graph

42 Commits

Author SHA1 Message Date
Pierre Curto 3db11cbaad io/router: make transfer targets hovering easier to detect
In commit 929e4dc12, the rules to send pointer.{Enter,Leave}
events were relaxed. Unfortunately, to be able to make use
of them was not straight forward as it required the transfer
target op to use the same handle as the hover one.
This patch eases this by allowing any handle for the target
as well as not requiring the hover op to be defined on the same
clip op as the target (then requiring a PassOp though), making
it much easier to use.

Also added a test for pointer.Enter events not being generated
if the target type does not match the source one.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-12-19 13:22:11 +01:00
Pierre Curto 929e4dc120 io/router: deliver enter/leave events to transfer participants
When a drag and drop gesture is ongoing, let the potential target
handlers receive enter/leave events so that they can react to them (e.g.
highlight themselves when the dragged item is over them).

Fixes #321.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-12-14 11:43:23 +01:00
Pierre Curto 03016f0c69 widget: add drag and drop support
This patch adds internal Drag and Drop support to app.Windows.

The new package io/transfer adds the ability to
define draggable and droppable targets, which
are leveraged by the new widget.Draggable type.

The API is generic and could handle future use
cases, such as external Drag and Drop.

Updates gio#153

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-12-07 12:45:53 +01:00
Pierre Curto 218a9588d6 io/router, internal/ops: minor refactoring
Rename the assertEventSequence helper to assertEventPointerTypeSequence.
Fix typos.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-11-26 22:26:38 +01:00
Jon Egil Strand e82438e53d io/router: fix spelling
Signed-off-by: Jon Egil Strand <jon.egil.strand@gmail.com>
2021-11-26 21:56:02 +01:00
Elias Naur 3e0b72304a all: replace deprecated pointer.Rect with clip.Rect
Converted with

gofmt -w -r 'pointer.Rect(r) -> clip.Rect(r)' .
gofmt -w -r 'pointer.Ellipse(r) -> clip.Ellipse(layout.FRect(r))' .

combined with 'goimports -w .' to clean up imports.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-11-03 14:12:31 +01:00
Elias Naur 29cea1db49 io/pointer,io/router: replace AreaOp with clip.Op
Pointer hit areas and paint clip areas are separate concepts, but
similar enough to warrant merging. This change replaces pointer hit
areas with clip areas, so Gio is left with just one area concept (in
package op/clip).

The reason for separating the concepts in the original Gio release was
because of my being unsure general path/stroke hit areas would ever be
implemented, let alone efficient.

This change represents a change of mind, in the sense that it's better
to have an incomplete API than two separate area concepts.

Leave the deprecated pointer.Rect, pointer.Ellipse for temporary
backwards compatibility.

This is an API change. Most existing programs should continue to build
with this change, but may have to adjust to having all clip.Ops participate
in InputOp hit areas.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-11-03 14:12:31 +01:00
Elias Naur 8cafbd309f io/pointer,io/router: make PassOp apply to InputOps, not areas
We're about to make clip.Ops act as pointer areas, in which case we'd
like to contain the effect of PassOp to just pointer InputOps.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-26 12:13:11 +02:00
Pierre Curto e6ed25bb1f io/router: deduplicate pointer handlers
When the same handler is added several times
and that handler sets pointer.Grabbed, it gets lost.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
2021-10-19 15:00:29 +02:00
Elias Naur 87d050bcc7 internal/ops: remove Data, Version, Refs methods from Ops
They're only used internally.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-12 14:28:05 +02:00
Elias Naur 391725b9d0 op: move Ops internal methods and state to internal package ops
Merge package opconsts into ops as well; it only existed to break
import cycles.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-08 17:21:56 +02:00
Elias Naur 936c266b03 all: [API] split operation stack into per-state stacks
The op.Save and Load methods exist to support the need for
transformation, clip, pointer area state to behave as stacks. For
example, layout needs to apply an offset to its children but not
subsequent operations.

Before this change, op.Save and Load were used to save and restore the
state:

    ops := new(op.Ops)
    // Save state.
    state := op.Save(ops)
    // Apply offset.
    op.Offset(...).Add(ops)
    // Draw with offset applied.
    draw(ops)
    // Restore state.
    state.Load()

A drawback with the op.Save mechanism is that there is no direct
connection between the state change and the saving and loading of state.
This causes confusion as to when a Save/Load is needed and who is
responsible for performing them, which leads to subtle bugs and over-use
of Save/Loads.

This change gets rid of the general state stack and replaces it with
per-state stacks. There is now a stack for transformation, clip, pointer
areas, and they can only be restored by the code pushing state to them.
The example above now becomes:

    ops := new(op.Ops)
    // Push offset to the transformation stack.
    stack := op.Offset(...).Push(ops)
    // Draw with offset applied.
    draw(ops)
    // Restore state.
    stack.Pop()

For convenience, transformation also be Add'ed if the stack operation is
not required.

Simple state such as the current material no longer has a way to be
restored; it is assumed the client of a PaintOp adds their desired
material operation before it.

API change: replace op.Save/Load with explicit Push/Pop scopes for
op.TransformOps, pointer.AreaOps, clip.Ops.

To ease porting, this change retains a version of op.Save/Load that
saves and restores the transformation and clip stacks. It also retains
an Add method for clip.Op.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-10-08 17:21:56 +02:00
pierre 5e1a662b94 io/pointer: support nested scrollables
Fixes #185.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-03-31 09:57:13 +02:00
Elias Naur 17ba8e28af io/router: drop the correct handlers when a pointer grab is requested
Fixes gio#208

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-27 13:18:30 +01:00
Elias Naur ffb26b0e17 io/pointer: rename button names to reflect their meaning, not placement
For example, ButtonLeft may be the right-most button for a left-handed user.
Rename the button names to match their intended use.

This is an API change. Use the following commands to update your
projects:

    $ gofmt -r 'pointer.ButtonLeft -> pointer.ButtonPrimary' -w .
    $ gofmt -r 'pointer.ButtonRight -> pointer.ButtonSecondary' -w .
    $ gofmt -r 'pointer.ButtonMiddle -> pointer.ButtonTertiary' -w .

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-03 11:08:41 +01:00
Egon Elbre e66979a8c0 io/router: fix negative areas
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2021-02-24 17:12:36 +01:00
pierre cfb16083a2 io/router: improve areaOp methods performance
name             old time/op  new time/op  delta
AreaOp_Decode-8  10.5ns ± 2%   6.2ns ± 3%  -41.50%  (p=0.000 n=10+10)
AreaOp_Hit-8     4.44ns ± 4%  3.57ns ± 2%  -19.59%  (p=0.000 n=10+10)

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-02-24 12:42:34 +01:00
pierre 1100e03c1e io/router: support cursor changes on Frame events
Add support to Router so that the cursor can be changed with CursorNameOp without any mouse movement.
Enter and Leave events are also delivered as areas change.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-27 22:21:27 +01:00
pierre b11fd6ee8e io/router: fix default cursor in Router
Do not update the cursor was reset upon receiving Cancel events. Added more tests.

Signed-off-by: pierre <pierre.curto@gmail.com>
2021-01-25 17:41:47 +01:00
Elias Naur cc63a3aeb7 io/router: don't send pointer.Cancel events to disappearing handlers
As a follow-up to gioui.org/commit/24f69bf4, this change makes it so
that merely adding a pointer.InputOp doesn't trigger redraws when
the pointer is hovered over its area.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-23 12:00:50 +01:00
Elias Naur 4f45d9a567 io/router: rename Router.Add to the more specific Queue
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-22 16:36:14 +01:00
Elias Naur 24f69bf4bb io/router: don't trigger redraw for handler reset events
key.InputOp and pointer.InputOp handlers are reset on first registration
through a key.FocusEvent{false} or pointer.Cancel, respectively.

However, the mere act of registering a handle shouldn't result in a
redraw. This is particularly true for misconfigured handlers where a new
tag is supplied every frame, resulting in continously redrawing.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-22 16:34:51 +01:00
Elias Naur d331dd2de8 op: rename StackOp/Push/Pop to StateOp/Save/Load
The semantics were relaxed in a previous commit; this change renames
to operations accordingly.

API change. Use gofmt to adjust your code accordingly:

gofmt -r 'op.Push(a).Pop() -> op.Save(a).Load()'
gofmt -r 'op.Push(a) -> op.Save(a)'
gofmt -r 'v.Pop() -> v.Load()'
gofmt -r 'op.StackOp -> op.StateOp'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-01-12 21:28:59 +01:00
pierre 578c226278 io/pointer: CursorNameOp no longer needs an InputOp with Leave and Enter events
Signed-off-by: pierre <pierre.curto@gmail.com>
2020-12-15 18:11:48 +01: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 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
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
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 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
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
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 8a2837531e io/router: add pointer routing test
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-02-27 09:22:48 +01:00