Commit Graph

613 Commits

Author SHA1 Message Date
Elias Naur beaec661d2 op/paint: move paint package below the op package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 16:55:47 +02:00
Elias Naur 8cf35a1f97 op: add package op for operations
Extract operation types from package ui into package op.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 16:55:47 +02:00
Elias Naur eba1b3a95f app,ui: move instructions link to package app documentation
We're about the split up and finally delete package ui. Move the
instructions link to the second most "top-level" package in Gio,
package app.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 15:25:22 +02:00
Elias Naur e7a97bf176 io/event: move event types from package ui to its own package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 15:18:08 +02:00
Elias Naur 7a259e68f7 io: give event packages a common prefix
Packages that provide support for external events such as pointer, key and
system are only the beginning. Future packages are expected for clipboard
access, drag and drop, gps positions and so on.

To keep the number of top-level packages under control, move such I/O packages
to the new `io` directory.

The `system` package name was the previous solution to keeping the number of
top-level packages under control: I named it `system` instead of the narrower
`profile` because I expected to put all the less common events into it, turning
`system` into a "package util" smell.

With `io`, package system can be renamed to `profile`.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 14:50:55 +02:00
Elias Naur a175f38d19 COPYING: delete
It is redundant with the existence of LICENSE. I don't remember why I added
COPYING in the first place.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 13:38:33 +02:00
Elias Naur 3c65aa61f6 cmd/gogio,ui: fixups after gioui.org module rename
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 13:04:10 +02:00
Elias Naur 049c0b4dcd website: redirect unknown patsh to godoc
With the renamed gioui.org module, any path could be a Gio package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 12:49:19 +02:00
Elias Naur 962bc36dac apps,cmd: update to renamed gioui.org module
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 12:41:29 +02:00
Elias Naur 22cd88df9f all: rename the gioui.org/ui module to gioui.org
The "ui" is redundant and stutters.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 12:37:06 +02:00
Elias Naur ce74bc0cba ui/layout,ui/app: fix tests, go fmt, update comments
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-26 19:15:58 +02:00
Elias Naur bdd6b32711 ui/app/internal/input: schedule an extra frame after event delivery
A program might choose to process events that affect UI state already laid out.
For example, a button click might switch to a completely different UI page, but
the click might be processed during the drawing of the current page.

Avoiding that require either processing events very early during layout or
adding InvalidateOps whenever events are handled late.

Early event processing is awkward and InvalidateOps are easy to forget and
their absence masked by any other cause of redraw.

This change adds an implicit InvalidateOp for each frame where events have been
delivered to the program, allowing late event handling without use of
InvalidateOps.

In the worst case we waste a frame, increasing power use. I hope that future
optimizations will detect and discard the duplicate frame before it reaches
the GPU.

A similar situation applies to the delayed delivery of Editor events, but
since Editor.Layout flushes remaining events, extra InvalidateOps are not
required. Add a comment.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-26 18:58:25 +02:00
Elias Naur 90e2a119c0 apps/gophers: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-26 18:43:21 +02:00
Elias Naur dc6fedc163 ui: change Queue to return all events at once
The Queue interface was changed from

	type Queue interface {
		Events(k Key) []Event
	}

to the more complex single-step protocol

	type Queue interface {
		Next(k Key) (Event, bool)
	}

to cater for a particular use case: Editor's SubmitEvent. When a
SubmitEvent is passed to a caller of Editor.Next, the Editor state,
in particular the current text, must not have changed by edits
later in the command stream. For example, pressing the keys <E>,
<Enter>, <E> should result in a SubmitEvent where the Editor has
a single 'e' in Text(), not two.

However, there is no reason to push the more complex Queue to every user.
Rather, store remaining input events inside Editor and process them as
Editor.Event (or Layout) is called.

Finally, revert the Queue interface to the simpler Events method.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-26 18:41:03 +02:00
Elias Naur 578b169279 ui/app: (wayland) pack related field in structs
No functional changes.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-26 13:42:09 +02:00
Elias Naur 51cfb4e5c2 ui/app: (linux) separate xkb logic from wayland backend
Makes the Wayland backend more clean, and X11 might be able to reuse
the xkb code.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-26 13:01:51 +02:00
Elias Naur bbc0cebacf ui/layout: reset Dimensions in Context.Reset
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-25 10:38:06 +02:00
Elias Naur 9c33550644 all: rename more *layout.Context names to gtx
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-25 09:43:15 +02:00
Elias Naur a89c6d1c33 all: rename c to gtx for *layout.Context parameters
Short like `ctx` but not as easily confused with context.Context
values.

Suggested by Larry Clapp.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-25 09:34:12 +02:00
Elias Naur 4d84f46edb apps: replace separate layout state with layout.Context fields
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-24 22:29:12 +02:00
Elias Naur 3944ef4b2e ui: merge package input
Event handling is as fundamental as operations, so move the input
package declarations to package ui.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-24 22:24:10 +02:00
Elias Naur 2782436ffc ui/layout: add common state to Context
Almost every layout and widget need the ui.Config for its environment,
an ui.Ops to store operations. Stateful widgets need an input.Queue
for events.

Add all these common objects to Context, greatly simplifying the
function signatures for Gio programs.

Fixes gio#33

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-24 21:44:33 +02:00
Elias Naur b928ee65f7 apps/gophers: update to new layout.Align
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-24 20:35:32 +02:00
Elias Naur 2f878fe154 ui/layout: make Align a Direction
Removes the stutter by simplifying

	layout.Align{Alignment: layout.NE}

to

	layout.Align(layout.NE)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-24 20:32:14 +02:00
Elias Naur ec307008db all: update layouts to use layout.Context
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-24 19:14:58 +02:00
Elias Naur ce9bcee62b ui/layout: introduce Context
Context keeps the current Constraints and Dimensions so the layout
function scopes don't have to.

With

	ctx := new(layout.Context)

a label with margins and alignment goes from

	return al.Layout(ops, cs, func(cs layout.Constraints) layout.Dimensions {
		in := layout.Inset{...}
		return in.Layout(c, ops, cs, func(cs layout.Constraints) layout.Dimensions {
			return text.Label{...}.Layout(ops, cs)
		})
	})

to

	al.Layout(ops, ctx, func() {
		in := layout.Inset{...}
		in.Layout(c, ops, ctx, func() {
		       text.Label{...}.Layout(ops, ctx)
		})
	})

It was a difficult trade-off between the verbose functional approach
and the shorter but more complex Context.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-24 19:06:07 +02:00
Elias Naur 64add13d28 ui/app: (wayland) wait for xdg_shell configure event before drawing
According to the xdg_shell documentation, the xdg_surface must be
configured before use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-24 17:28:04 +02:00
Daniel Martí 687ea833a3 cmd/gogio: add the first end-to-end test for js via chrome
This commit adds the first fully end-to-end test. It builds a very
simple Gio app, loads it on Chrome, and checks that it works.

To control Chrome, we use chromedp, a library in pure Go that takes care
of starting the browser and talking to it via the devtools protocol.

We add the test directly in the cmd module, since it mainly interacts
with the gogio tool, and also because the code might turn into some sort
of 'gogio test' command in the future. This does add chromedp and ui as
test dependencies to go.mod, but GOPROXY should allow a 'go get' of
gogio to not download their entire source code archives.

We don't replace ui with ../../ui in the go.mod, to ensure that testing
the cmd module works from anywhere without unintended differences.

The test app being used is inside a testdata directory, to ensure it's
not go-gettable, and that it doesn't otherwise affect the cmd module.

Finally, the test itself is pretty simple. The app just paints a red
background, and the test verifies that, once loaded, the background of
the browser viewport is indeed red.

The test does currently require Chrome or Chromium to be installed,
which is fine for now. It may also require a GPU, though I don't have a
headless machine to check for sure. The test uses Chrome in headless
mode though, so it doesn't open up any visible browser window.

All in all, the test succeeds in just over a second on my laptop with
Chromium 77.0.3865.75.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-09-23 21:23:31 +02:00
Elias Naur 736692a725 ui/app: (windows) process all events before redrawing
While here, make sure the DestroyEvent is sent after exiting the
event loop.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-23 20:49:51 +01:00
Elias Naur 5c9d35c186 ui/app,ui/app/internal/gl: work around golang.org/issue/34474
Apparently, the (*syscall.LazyProc).Call does not keep its arguments
alive across calls.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-23 20:26:52 +01:00
Elias Naur 5c87437542 ui/app: (windows) don't unregister window class
It silently fails because the Gio window is using it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-23 19:17:14 +01:00
Elias Naur 8e41c8a0be ui/app: (windows) don't cast syscall.Handle to unsafe.Pointer
The cast is not necessary and a syscall.Handle is not a pointer.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-23 10:25:11 +02:00
Elias Naur 2d8072fbbb ui/layout: replace "interface element" with "widget" in documentation
Now that we have a Widget type, use it in the documentation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-22 16:19:07 +02:00
Elias Naur 4a1e0a30cb ui/layout: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-19 18:53:45 +02:00
Elias Naur 3817b19bbe ui/layout: update documentation to reflect the function scope changes
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-18 22:57:14 +02:00
Elias Naur a12912c944 cmd/gogio: rename the gio too to gogio
The `gio` name clashes with a widely deployed GNOME tool.
Rename our tool to `gogio`, "the go tool for gio programs".

Fixes gio#20

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-18 22:46:47 +02:00
Elias Naur 31f7f04181 ui/layout: clean up after function scope change
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-18 22:03:08 +02:00
Elias Naur 1767588028 apps/gophers: update to function scoped layouts
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-18 21:46:48 +02:00
Elias Naur 29639565cd ui/layout: replace implicit begin/end scopes with explicit function scopes
Before this change, layout objects followed a pattern where a
begin method would set up the layout and return a tweaked set
of constraints, and a end method would take the widget dimensions
and return the tweaked dimensions.

As has been pointed out, this process is error prone, because the
scope of the layout objects are not clear and because it is easy
to swap two begins or two ends.

It turns out that it is possible to implement layout with function
scopes in garbage free way. A typical layout changes from

        al := layout.Align{Alignment: layout.NE}
	cs = al.Begin(ops, cs)
	in := layout.Inset{Top: ui.Dp(16)}
	cs = in.Begin(c, ops, cs)
	txt := fmt.Sprintf("m: %d %s", mallocs, u.profile.Timings)
	dims := text.Label{Material: theme.text, Face: u.face(fonts.mono, 10), Text: txt}.Layout(ops, cs)
	dims = in.End(dims)
	return al.End(dims)

to

        al := layout.Align{Alignment: layout.NE}
	return al.Layout(ops, cs, func(cs layout.Constraints) layout.Dimensions {
	       in := layout.Inset{Top: ui.Dp(16)}
	       return in.Layout(c, ops, cs, func(cs layout.Constraints) layout.Dimensions {
		       txt := fmt.Sprintf("m: %d %s", mallocs, u.profile.Timings)
		       return text.Label{Material: theme.text, Face: u.face(fonts.mono, 10), Text: txt}.Layout(ops, cs)
	       })
	})

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-18 19:31:36 +02:00
Elias Naur 816f0e901f ui/app: scale touch events by surface scale
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-18 19:28:08 +02:00
Drew DeVault dcddd9a84a os_wayland: transform pointer events by scale
Fixes #37
2019-09-18 19:15:17 +02:00
Drew DeVault c5a6ca2aba ui/app/egl.go: on failure, try again without sRGB
Signed-off-by: Drew DeVault <sir@cmpwn.com>
2019-09-18 18:44:35 +02:00
Elias Naur ee89d643cc ui: panic if a StackOp does not Pop in the same macro as Push
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-17 11:56:42 +02:00
Elias Naur bae2e0ecf2 ui/app: (wayland) restore discrete scrolling behaviour
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-16 15:39:31 +02:00
Elias Naur 37d5b947eb ui/app: (wayland) reset fling emulation on key press
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-13 21:13:02 +02:00
Elias Naur 2ea9fd9983 ui/app: (wayland) reset fling emulation of pointer motion
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-13 20:11:14 +02:00
Elias Naur 81f935f69b ui/app: go fmt
Sigh.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-13 19:09:05 +02:00
Daniel Martí a223b36c25 cmd/gio: avoid a trailing newline in -target errors
I was seeing an extra newline when some errors were printed, like:

	$ gio foo
	please specify target

	$

The source of the little bug was a trailing newline in the error
messages. Printing the messages already adds a newline.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-09-13 18:36:19 +02:00
Elias Naur 5bdb1d9e54 ui/app: (wayland) emulate fling behaviour for touchpads
Unlike macOS, Wayland leaves it up to the client to animate the
implied fling gesture when scrolling on a touchpad.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-13 18:35:38 +02:00
Elias Naur e6f0e0582d ui/gesture,ui/internal/fling: extract fling logic into its own package
We're going to re-use fling extrapolation and animation for Wayland touchpads.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-13 18:35:38 +02:00