Commit Graph

34 Commits

Author SHA1 Message Date
Tobias Klauser ca3c58166e all: use "reports whether" in godoc comments
Go documentation style for boolean funcs is to say:

    // Foo reports whether ...
    func Foo() bool

rather than "returns true if" or "returns whether".

Change-Id: I5d01c45a8867b47462ed142a49ad51bf0a319ce1
Reviewed-on: https://go-review.googlesource.com/c/151957
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2018-11-30 13:31:20 +00:00
Daniel Skinner 8ab5dbbea1 event/size: document size pt approximation
Fixes golang/go#13366

Change-Id: I2af5e2492450ab5b5996fa5926460b62ce9d9bf5
Reviewed-on: https://go-review.googlesource.com/24865
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2016-08-04 01:15:58 +00:00
Alessandro Arzilli cf96d36e8f event/key: add Compose key
Fixes #16332

Change-Id: I4fcd9c4c60fb5c32abaab5b68d3036d536ab2b69
Reviewed-on: https://go-review.googlesource.com/24880
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2016-07-21 02:17:49 +00:00
Nigel Tao 204c03cc80 event/mouse: add Button.IsWheel, ButtonWheelLeft and ButtonWheelRight.
Horizontal wheel events can come from some tilting scroll wheels, as
well as trackpoints (pointing sticks).

Change-Id: I02be43d44a65123e2d58539e291e9e6ac7e6bff4
Reviewed-on: https://go-review.googlesource.com/24633
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-07-02 00:00:04 +00:00
Nigel Tao 2d0a4d3322 event/mouse: add DirStep.
Change-Id: I4f9295ac2855928ecd43a5888ed776195c3129a5
Reviewed-on: https://go-review.googlesource.com/24639
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-07-01 22:50:24 +00:00
Nigel Tao 2e06e2c92c event/lifecycle: add an Event.String method.
Change-Id: I5d648327cf39cd3b2cf97fa08a094744528221fe
Reviewed-on: https://go-review.googlesource.com/18400
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-01-08 07:36:36 +00:00
Nigel Tao a103499a63 event/size: make methods take values, not pointers.
This makes the following program valid:

----
package main

import (
    "fmt"

    "golang.org/x/mobile/event/size"
)

func foo() size.Event { return size.Event{} }

func main() {
    fmt.Println(foo().Bounds())
}
----

Previously, you would get:
./main.go:12: cannot call pointer method on foo()
./main.go:12: cannot take the address of foo()

Change-Id: I2801d18a04d56d1c7496cb008531d078490ccf86
Reviewed-on: https://go-review.googlesource.com/18356
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-01-07 22:44:33 +00:00
David Crawshaw 7fe809f8e0 event/paint: mark paint events sent by the system
A paint.Event now has an External field. Whenever a paint event is
sent by the x/mobile/app package, it is marked as external so users
with an active paint loop can ignore them.

Implemented on OS X and Android, with examples updated.

Change-Id: Ibee8d65625c8818ff954936be48257ad30daa147
Reviewed-on: https://go-review.googlesource.com/15480
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-07 19:41:52 +00:00
David Crawshaw 59ab51f73f gl: move to context methods
All OpenGL functions are now methods on a Context interface. The
gl.Context matches the one loaded into thread-local storage in C.

For mobile apps, the context is owned by an app.App. For now, it is
provided through the events channel on a lifecycle event. Long-term,
it should probably be available by a method on app.App, but this is
inherently racey with our current use of a channel to deliver events.

Shiny-based programs will have a gl.Context associated with a each
shiny.Window. The expectation is each Window will have different
contexts, allowing them to draw separately.

Change-Id: Ie09986fb74e493129f2ea542a151c95c6fa29812
Reviewed-on: https://go-review.googlesource.com/13431
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-23 23:46:16 +00:00
Nigel Tao 4c15c79e19 app: change EndPaint to Publish.
More than a name change, the painting model changes so that the app, not
the library, is responsible for driving painting. If the app is
animating and wants paint events at 60 Hz, it has to ask for that. If
the app is not animating and doesn't need to update its screen, it
shouldn't get any paint events.

Plenty of TODOs, and this CL doesn't get us to a perfect place, but it
is a checkpoint along the way.

The darwin_*.go code changes were minimal. I don't even have a Mac or
iOS device to test that this even builds. Even so, the TODOs about not
sending paint.Events unconditionally are important TODOs. That's the
whole point of switching to this model. I'll leave the actual
implementation to you (crawshaw).

Out of all the example apps, the change to example/network/main.go is
probably the most interesting.

It seems like there ought to be some way to reduce the copy/paste
between all of the example app code, but I'll leave that for future CLs.

Change-Id: I17e11c06174110c68e17f7183b2d8af19b6a170e
Reviewed-on: https://go-review.googlesource.com/14300
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-17 03:17:09 +00:00
Nigel Tao b5b6051b23 event/size: add an Event.Size method.
This is similar to the Event.Bounds method. Some functions in other
packages take an image.Rectangle (i.e. bounds), others take an
image.Point (i.e size).

Change-Id: Ie892a8902992d4e6b9edfbf6d12342297fae4068
Reviewed-on: https://go-review.googlesource.com/14003
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-01 00:58:08 +00:00
Nigel Tao 3a0fcd575e event/key: make Event implement fmt.Stringer.
Change-Id: I453bed283767e0adf5efd271b329a469c0073d69
Reviewed-on: https://go-review.googlesource.com/13733
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-21 01:21:32 +00:00
Nigel Tao e959dea03d event/key: implement Code.String, via stringer.
Change-Id: I4acf4f351a30ee64192ed9f896ca31d29fe0397f
Reviewed-on: https://go-review.googlesource.com/13712
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-19 23:59:47 +00:00
Nigel Tao f632204bcc event/config: rename to event/size.
Change-Id: I908b5f0818da32b2b040f430ebcc3762eb6f7570
Reviewed-on: https://go-review.googlesource.com/13601
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-13 13:31:00 +00:00
David Crawshaw 51384a9898 event/config: add Orientation
There are several variations on orientation. iOS expposes a little
more orientation information through its basic enum than Android
does, but the more powerful Android API gives you degrees around a
circle, which while strictly more powerful, doesn't tell you easily
where the status bar is.

What I'm thinking with this is the primary use of an orientation
concept is to decide whether or not to lay out a UI for a wide screen.
This gives you that.

Later I hope the sensor API will give far more information about the
physical orientation of the device.

Change-Id: I00ff598853c7ed618cde266729d8d05e1a02a601
Reviewed-on: https://go-review.googlesource.com/13361
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-08-10 12:46:05 +00:00
Nigel Tao fa181effb8 event/config: add a Bounds method.
This is analogous to the image.Image's Bounds method.

Change-Id: I2be927f21008107b535cb79e231149cb8d4e8e36
Reviewed-on: https://go-review.googlesource.com/13152
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-07 00:14:21 +00:00
Nigel Tao 8fffdfa9fd event/{mouse,touch}: work in float32 pixels, not geom.Pt.
Higher-level widget or animation libraries should probably work in
geom.Pt, but pixels instead of (1/72s of) inches seems a better fit for
lower-level event libraries. Needlessly converting from (float32) pixels
to (float32) points and back can be lossy and lead to off-by-one errors.

Change-Id: I68102e36f2574b07b44c6a1b7281f4f27f9174cf
Reviewed-on: https://go-review.googlesource.com/13002
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-04 07:35:09 +00:00
David Crawshaw 0c8ff9f648 app, event/paint: plumb through paint Generation
Change-Id: I82bac0dc24943c64560a0bac4687cbbbb8b5c328
Reviewed-on: https://go-review.googlesource.com/12841
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-30 16:09:38 +00:00
Nigel Tao cdc5281044 event/config: specify width and height in both pixels and points.
Change-Id: I494c17b2bad6c920ea20b22046d1d3fbc7b6b1d4
Reviewed-on: https://go-review.googlesource.com/12700
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-28 01:48:05 +00:00
Nigel Tao f2f4efe74b event/mouse: new package.
Change-Id: Idd30a70bf62971ecea8ee9db905d4a0a8baf6525
Reviewed-on: https://go-review.googlesource.com/12667
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-28 01:28:46 +00:00
David Crawshaw bd8a095b54 event/key: add Code type
Also add a few missing codes.

Change-Id: I26b6db31067c67107fe4db142ec9f48ff13cc53e
Reviewed-on: https://go-review.googlesource.com/12536
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-24 12:23:42 +00:00
David Crawshaw de4ba64cf5 app, event/key: keyboard events
First cut of events from physical keyboards.
Simple darwin/amd64 implementation.

Change-Id: I6e9d0a253387c841864ca9845ee729ea4f7573c7
Reviewed-on: https://go-review.googlesource.com/11815
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-22 20:09:27 +00:00
Nigel Tao c4654583ad event/touch: rename TypeStart to TypeBegin.
Change-Id: Ie8392cd6167fca1c0a7f10192824300d7885151d
Reviewed-on: https://go-review.googlesource.com/12342
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-18 04:39:45 +00:00
Nigel Tao 84f8e5edcc event: move event.Filter to app.Filter.
Change-Id: I11044a6e01b53e441c05fc1baec36718e783622f
Reviewed-on: https://go-review.googlesource.com/12288
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-17 01:18:36 +00:00
Nigel Tao b43065626f app: rename EndDraw to EndPaint.
Change-Id: I3e38df0e21be2246dd16886fa00c9360d42db145
Reviewed-on: https://go-review.googlesource.com/12282
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-16 03:33:11 +00:00
Nigel Tao e4c6af17e3 event: rename event.Foo to foo.Event.
Fixes golang/go#10444

Change-Id: Ie5a8ab8a09b1b1a4f7037da7cf945d39ab6a98fc
Reviewed-on: https://go-review.googlesource.com/12225
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-16 01:03:51 +00:00
Nigel Tao c0fb3fcc1e event: fix the build from a bad merge.
https://go-review.googlesource.com/#/c/11822/3/event/event.go
removed the fmt package dependency, but concurrently,
https://go-review.googlesource.com/#/c/11813/2/event/event.go
introduced new code that relied on fmt already being imported.

Change-Id: Ib5c66bf59850aa49d251778371c4863bfdf54655
Reviewed-on: https://go-review.googlesource.com/11859
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-03 02:19:54 +00:00
Nigel Tao 15dc27054b event: delete TouchType in favor of Change.
Change-Id: I8772c8d2690fbe6b636f1dcafe1393f6810d6716
Reviewed-on: https://go-review.googlesource.com/11822
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-03 01:56:41 +00:00
David Crawshaw f02d32beeb event: add String method to LifecycleStage enum
Change-Id: Iaa723e8db258540d60170216430295ac9dee1901
Reviewed-on: https://go-review.googlesource.com/11813
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-01 05:20:26 +00:00
Nigel Tao 42f0d17876 app: use one thread for both GL and other UI C code.
This change will break Darwin. I have only built and tested this on
desktop linux and Android linux. A follow-up CL will fix Darwin.

Currently, OpenGL gets its own thread, and UI C code (e.g. the Android
event loop, or the X11 event loop) gets its own thread. This relies on
multiple system-provided UI-related C libraries working nicely together,
even when running on different threads. Keeping all the C code on the
one thread seems more sound.

As side-effects:
  - In package app/debug, DrawFPS now takes an explicit Config.
  - In package app, some callbacks now take an explicit Config.
  - In package exp/sprite, Render now takes an explicit Config.
  - In package event, there are new events (Config, Draw, Lifecycle),
    and an event filter mechanism to replace multiple app Callbacks.
  - In package geom, the deprecated Width, Height and PixelsPerPt global
    variables were removed in favor of an event.Config that is
    explicitly passed around (and does not require mutex-locking).
    Converting a geom.Pt to pixels now requires passing a pixelsPerPt.
  - In package gl, the Do, Start and Stop functions are removed, as well
    as the need to call Start in its own goroutine. There is no longer a
    separate GL thread. Instead, package app explicitly performs any GL
    work (gl.DoWork) when some is available (gl.WorkAvailable).
  - In package gl/glutil, Image.Draw now takes an explicit Config.

Callbacks are no longer executed on 'the UI thread'.

Changing the app programming model from callbacks to events (since a
channel of events works with select) will be a follow-up change.

Change-Id: Id9865cd9ee1c45a98c613e9021a63c17226a64b1
Reviewed-on: https://go-review.googlesource.com/11351
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-26 07:43:17 +00:00
Gordon Klaus 253eb63b86 mobile/app: identify touches by ID to enable multitouch
An example of how to handle multiple concurrent touches using this design:

var touched = map[event.TouchSequenceID]*Widget{}
func touch(t event.Touch) {
    if t.Type == event.TouchStart {
        if w := widgetAt(t.Loc); w != nil {
            touched[t.ID] = w
        }
    }
    if w, ok := touched[t.ID]; ok {
         // move/scroll widget, etc
    }
    if t.Type == event.TouchEnd {
        delete(touched, t.ID)
    }
}

Change-Id: I79910ef30abe9a41bc0720783022b1af081fbd43
Reviewed-on: https://go-review.googlesource.com/1895
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Burcu Dogan <jbd@google.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-29 16:53:16 +00:00
David Symonds 7b659348a5 mobile: add import comments.
Change-Id: I0ff6d42a8e11f49df6fc3066e86be75015b93631
Reviewed-on: https://go-review.googlesource.com/1238
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-10 01:59:04 +00:00
Andrew Gerrand 9470e0ba58 go.mobile: use golang.org/x/... import paths
LGTM=bradfitz, rsc
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/162710043
2014-11-10 08:55:57 +11:00
David Crawshaw 1a7379ccf0 go.mobile/event: types for user input events, starting with touch
LGTM=adg, nigeltao
R=nigeltao, bryanturley, adg, crawshaw
CC=davidday, golang-codereviews
https://golang.org/cl/141060043
2014-09-09 20:54:51 -04:00