Commit Graph

1239 Commits

Author SHA1 Message Date
Egon Elbre f29964fee1 example/tabs: animated switching
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2020-05-13 12:59:29 +02:00
Elias Naur d682e92606 example/tabs: use material.Clickable
Replace the hacked material.Buttons with Clickables for the tab areas.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-13 10:31:40 +02:00
Elias Naur 062e2bc54b gesture: only report TypePress for Click gestures if pointer is grabbed
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 16:50:07 +02:00
Elias Naur ca0af08ff2 gesture: use Enter/Leave events instead of Moves
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 16:32:37 +02:00
Elias Naur a0df8ba59b example: bump gio version and add flat button example to kitchen
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 13:20:17 +02:00
Elias Naur 23baeff18d widget/button,widget/material: introduce Clickable for generic click areas
material.Clickable is useful for adding a click response to any widget
or area.

Rename widget.Button to widget.Clickable to reflect the wider use
spectrum.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 13:17:14 +02:00
Elias Naur 47ce4b8cb8 widget: export Button.Update method for accessing raw gesture events
Document Button while we're here.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 12:56:56 +02:00
Elias Naur 43c2b90716 widget: simplify popping an element from a slice
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 12:47:27 +02:00
Elias Naur fd2cb4a7a1 widget,widget/material: use constraints for setting up hit area
Before this change, the widget.Button.Layout method assumed the caller had set
up the pointer hit area before. Further, the very common rectangular hit
areas needed both an AreaOp and a widget.Button.Layout call.

Make widget.Button less subtle and more useful by setting up a
pointer hit area given by the incoming minimum constraints.

Drop a pointer.AreaOp made redundant by the change.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 12:37:08 +02:00
Elias Naur 4e20ea83a1 widget/material: use cosntraints for setting pointer hit areas
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 12:23:18 +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
Elias Naur 73475270fe example: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 11:32:45 +02:00
Elias Naur c32b3fe43a widget/material: drop Color from ButtonLayoutStyle
Setting a ColorOp before calling a widget function is too subtle.
Let the widget manage its color instead.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-11 11:31:48 +02:00
Daniel Martí 669e4cc96a cmd/gogio: speed up the wine e2e test
First, use wineboot instead of winecfg to set up the WINEPREFIX. It's
the right tool for it.

Second, when initialising WINEPREFIX, use output pipes instead of
CombinedOutput. The latter will wait for *all* output to be copied to a
buffer, including the output from grandchildren processes. Since wine
starts wineserver automatically, and wineserver lingers for three
seconds by default, this is bad. We would waste three seconds waiting
for wineserver doing nothing, and then the next wine call (to start the
app) would need to start wineserver all over.

Instead, with pipes we can get cmd.Run to only wait for the parent
process to finish. wineserver stays running but we don't care. And, when
we start the gio app, we very likely reuse the same wineserver process.

Third, disable wine-gecko and wine-mono. This ensures we don't get stuck
if they're not installed, and speeds up wineboot by avoiding work we
don't need.

The time to set up WINEPREFIX goes down form ~6s to ~1s, and the overall
subtest run-time goes down from ~10s to ~3s.

Finally, copiously document all of the precious data I've gathered above
after hours of debugging.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2020-05-10 21:51:30 +02:00
Daniel Martí 023e022255 cmd/gogio: make e2e test output consistent
Fix a long-standing TODO: instead of each sub-test handling its own
output separately, just make each expose its output via an io.Reader.
Then, the shared driverBase code can tell if any of the lines contain
the magic "gio frame ready" string.

Reduces the amount of code a bit, but most importantly, it keeps the "is
a frame ready?" logic in a single place.

In the future, this also enables us to do more with all the e2e test app
output consistently. For example, we might want to add a -debug flag to
always log output lines as they happen.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2020-05-10 20:32:57 +02:00
Daniel Martí 9ad412ea0b cmd: bump gioui.org dependency, use -modfile properly on CI
A simple 'go test -modfile=<path>' won't work properly for the
end-to-end tests, since they run 'go build' under the hood as well.

To properly propagate the flag, we need to use GOFLAGS. Since -modfile
is always relative to the current directory, we can't use it to test
many packages at once, nor can we use it via 'go test ./gogio'.

While at it, document this distinction in go.local.mod to prevent others
getting confused like I did.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2020-05-10 20:32:53 +02:00
Daniel Martí c2cbcee78d cmd/gogio: use a standalone WINEPREFIX for the wine e2e test
This way, if the user has a custom winecfg, it can't possibly affect the
tests. I was encountering this as DXVK does not work on virtual Xorg
servers (which we use), and Gio thus failed to render on such a
combination.

>From the numbers below, it can be seen that setting up a new WINEPREFIX
takes roughly five seconds:

	$ rm -rf ~/.cache/gio-e2e-wine
	$ go test -run EndToEnd/Windows
	PASS
	ok  	gioui.org/cmd/gogio	16.369s
	$ go test -run EndToEnd/Windows
	PASS
	ok  	gioui.org/cmd/gogio	11.810s

A repeated run still has a slow "wine winecfg /?", for some reason. Add
a TODO since I can see it taking a third of the time on my terminal. I
haven't been able to properly investigate why, unfortunately. As far as
I can tell, winecfg is just faster when run with a terminal instead of
an output buffer. They might use isatty on stdout/stderr.

The overall time to run the wine sub-test is increased from ~5s to ~11s,
but it's worth it to make it run everywhere. It looks like there is
plenty of room as per the TODO above, as winecfg seems to mostly do
nothing. We're also not too worried, as all e2e subtests run in
parallel.

Fixes #106.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2020-05-10 08:40:36 +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
Elias Naur 0ad8f85c05 cmd/gogio: add -linkmode flags
For experimenting with https://github.com/golang/go/issues/38918.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-08 08:31:26 +02:00
Elias Naur bcbea7e653 cmd/gogio: fix ldflags overwriting
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-08 08:27:42 +02:00
Elias Naur 630e0b494d app/internal/windows: remove extra empty line
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-07 16:03:22 +02:00
Elias Naur 681bafce08 cmd/gogio: use filepath for Windows compatibility
Fixes gio#112

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-07 15:52:13 +02:00
Elias Naur 3957be37c8 app: [Android] tweak environment for os.UserHomeDir and os.UserConfigDir
Set the fallback environment variables XDG_CONFIG_HOME and HOME to
make os.UserConfigDir and os.UserHomeDir report useful paths.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-06 16:54:55 +02:00
Elias Naur 2395659be3 app: [Android] set XDG_CACHE_HOME to make os.UserCacheDir work
os.UserCacheDir can't work on Android because it doesn't have
access to the Java app context. Gio programs do have access, so set
up UserCacheDir's fallback, the XDG_CACHE_HOME environment variable.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-06 16:39:21 +02:00
Daniel Martí e97adeedd9 app/internal/log: use the app ID as the Android log tag
This way, a Gio app's logs can be filtered uniquely, which wasn't
possible before since the tag "gio" would be the same between gio apps.

Since the app ID is supplied at build time, inject it via a variable
with the linker's help. The variable is only used on Android for now,
but that's OK. It might be useful for other platforms or other internal
packages in the future.

Fixes #84.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2020-05-06 08:41:04 +02:00
Daniel Martí ec34eb4919 cmd: add a go.local.mod for development
It's essentially a copy of go.mod, but with the gioui.org module replaed
with the parent directory. Useful when wanting to try a change in the
root module as part of a gogio invocation or end-to-end test, such as
either of the following:

	$ cd cmd; go test -modfile=go.local.mod ./...
	$ cd cmd/gogio; go build -modfile=../go.local.mod

Since go.sum can essentially be shared, and since it seems to work with
the go tool, use a symlink. The way the -modfile flag works, if given
foo.mod, it will use the sum file at foo.sum. The only caveat is that
'go mod tidy -modfile=go.mod.local' will try to remove gioui.org lines,
since that module is replaced. So tidy shouldn't be used with -modfile.

In the future, the only upkeep needed for go.local.mod is to update the
external dependencies to mirror changes in go.mod. This is not automated
nor checked by CI, but it could be in the future if it becomes
repetitive or error-prone.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2020-05-06 08:41:00 +02:00
Elias Naur 33493501a6 app/internal/headless: [Android] expose Java initialization method
Android apps may want to run Go code independent of the Gio Android Activity.
Expose a Gio.init Java method public for early loading and initialization of
the Go library.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 19:22:11 +02:00
Elias Naur cde651db60 app/internal/window: [Android] remove JNI_OnLoad JNI callback
There can only be one JNI_OnLoad callback per JNI library, and the
Gio program may need it for its own purposes.

Gio only used JNI_OnLoad for explicitly registering native methods. Switch
to implicit name based registration and get rid of JNI_OnLoad.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 19:01:12 +02:00
Elias Naur 0c0a22bee7 app/internal/window: don't rely on JNI_OnCreate for getting the JavaVM
We're about to remove the global JNI_OnLoad constructor, and the
JavaVM singleton is just as easily fetched from a Java JNI callback.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 18:55:14 +02:00
Elias Naur c7c5b87264 app/internal/window: remove unused #includes
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 18:29:25 +02:00
Elias Naur 7301ebe0ef app/internal/window: removed unused function
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 18:23:31 +02:00
Elias Naur f08568a6df widget: report whether Value changed after Enum.Update and Bool.Update
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 11:33:41 +02:00
Elias Naur 05efb9b5f4 example/kitchen: add Switch widget
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 10:41:10 +02:00
Elias Naur 26da49e145 widget/material: add Switch widget
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 10:38:31 +02:00
Elias Naur 6b4eb710b3 widget: rename CheckBox to Bool
We're about to introduce the Switch widget that re-uses the same
state type as CheckBox. The Bool name covers both uses.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-04 17:13:50 +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 52d8a8867d widget,widget/material: export CheckBox.Checked
Similar to the previous change to Enum, expose the current state of
the CheckBox. Rename the Checked method to just Update and get rid
of the SetChecked method.

Fixes gio#100

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:28:33 +02:00
Elias Naur f1e266a9e7 widget,widget/material: export Enum.Value
The Value method both updated the enum value and returned it.

In order to access the current value withoutm, expose the Value
field of the enum and rename the method to Update. As a bonus we
can get rid of the SetValue method as well.

Updates gio#96

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:28:33 +02:00
Elias Naur a1166e6652 example,cmd: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:07:53 +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 289fe02b90 layout: replace NewContext with a Queue argument to Context.Reset
We're about to reduce the scope of the Window.Queue by moving it
to FrameEvent. As a consequence, Context can no longer rely on a
Queue constant over its lifetime.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:03:40 +02:00
Elias Naur d350f82011 layout: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 17:13:08 +02:00
Elias Naur d474b5b16a example: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 13:06:55 +02:00
Elias Naur 060cff257f material: make theme constructors stand-alone functions
The multitude of widget methods on Theme is unnecessary coupling in that all
possible widgets either have to be included in package material, or be
different than 3rd party widgets:

	var th *Theme

	// Core widget, calling a method on Theme.
	th.Button(...).Layout(...)

	// 3rd party widget, calling a function taking a Theme.
	datepicker.New(th, ...).Layout(...)

Another reason for the Theme methods was to enable a poor man's
theme replacement, so that you could use the same code for
compatible themes. For example,

	mat.Button(...).Layout(...)

would not need to change if the type of mat changed, as long as
the new type had a compatible method Button.

However, that point misses the fact that the mat variable had to
be declared somewhere, naming the theme package:

	var mat *material.Theme (or, say, *cocoa.Theme)

A better and complete way to replace a theme is to use import renaming.
For example, to replace the material theme with a hypothetical Windows
theme, replace

	import theme "gioui.org/widget/material"

with

	import theme "github.com/somebody/windows

This change moves all Theme widget methods to be standalone functions,
and renames the widget style types accordingly.

For example, instead of the method

	func (t *Theme) Button(...) Button

there is now a function

	func Button(t *Theme, ...) ButtonStyle

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 13:03:04 +02:00
Elias Naur e460e4f4bf widget,widget/material: move Image and Icon to widget package
There is nothing theme-specific about displaying images and icons,
so move the types from the material package to the generic widget
package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 12:22:32 +02:00