Commit Graph

1348 Commits

Author SHA1 Message Date
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
Pierre.Curto bade277876 widget: Clickable: added support for NumClicks
Clickable.Clicks() now returns the number of clicks.

Signed-off-by: Pierre.Curto <pierre.curto@gmail.com>
2020-06-02 10:26:14 +02:00
Elias Naur 3ef841bd07 widget: make Clickable.Clicked use a pointer receiver
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-02 10:19:50 +02:00
Elias Naur f86e1a6421 app/internal/window: [wayland] move listener registration to Go
In turns out that only the listener declarations need to be in C, not
the listener registration calls.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-01 21:56:06 +02:00
Elias Naur eafe09967f cmd,example: bump gio
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-01 00:05:45 +02:00
Elias Naur 28bf9e2001 layout: create input group for List
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-01 00:04:44 +02:00
Elias Naur 6fbcae07cb app/internal/window: fix multitouch action on Android
Fixes #122

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-01 00:04:44 +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 2487842aae cmd,example: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-31 12:00:10 +02:00
Elias Naur 4bf043eb5b app/internal/window,app/internal/xkb: silence string(int) conversion warnings
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-31 11:57:45 +02:00
Elias Naur d2c67cdf80 app/internal/egl: use nilEGLConfig to guard against int vs pointer-typed EGLConfig
Updates #121

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-30 16:18:30 +02:00
Elias Naur e9500f5f4c cmd,example: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-30 14:44:02 +02:00
Elias Naur 1377bea3cd app/internal/window: [macOS,iOS] reduce display link starting and stopping
Recent changes to the macOS threading exposed a problem where a
window's display link may fail to start after being started and stopped
in rapid succession.

Introduce a displayLink type that waits a while after the last stop
request before stopping its display link. That seems to be the way
other projects are using display links.

As a bonus, the new implementation avoids the potentially expensive
overhead of frequent starting and stopping the underlying OS thread.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-30 14:42:00 +02:00
Elias Naur 3817941175 app/internal/window: [iOS] move redraw logic to Go
We're about to move the display link to common Go code. To do that,
we need the redraw logic in Go as well.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-30 14:16:54 +02:00
Elias Naur 266b01bb5d app/internal/window: [wasm] report key modifiers for pointer events
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-27 17:12:11 +02:00
Elias Naur 6a0da04598 cmd,example: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-27 16:41:26 +02:00
Elias Naur 9da54eac61 app/internal/window: [X11] report key modifiers for pointer events
Fixes #120

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-27 16:39:24 +02:00
Elias Naur f6dff2fd1c app/internal/window,app/internal/xkb: [Wayland] report modifiers for pointer events
Updates #120

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-27 16:39:07 +02:00
Elias Naur 7b6eafcb59 cmd,example: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-27 16:17:22 +02:00
Elias Naur 33146961f4 app/internal/window: [macOS] avoid racy access to window width, height, scale
The macOS redraw callback is not invoked on the main thread, so its
access to window fields must be synchronized.

An alternative would be to schedule the asynchronous redraws on the main
thread, but I believe frame callbacks are performance-sensitive enough
to warrant the extra locking complexity.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-27 16:12:57 +02:00
Elias Naur 5c6ff659bf app/internal/window: [macOS] don't call Cococa from non-main thread
Only the synchronous draws from the main thread may involve changing
width, height and scale. Introduce cached window.width and window.height
fields and limits updates to main-thread draws.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-27 16:07:40 +02:00
Elias Naur ad93e32128 widget: redefine Enum.Changed and Bool.Changed to consider only user interaction
Ignore programmatic value changes to avoid feedback loops.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 19:48:33 +02:00
Elias Naur f2df7c1458 widget: change Enum.Layout to follow layout protocol
Respect constraints and return dimensions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 13:52:48 +02:00
Elias Naur 31d722d9eb widget: change Bool.Layout to follow layout protocol
Just like Clickable, Bool.Layout should respect constraints and
return its dimensions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 13:50:03 +02:00
Elias Naur 3164a3fee7 example,cmd: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 13:24:13 +02:00
Elias Naur 4898e1a691 widget: add Button.Clicks for retrieving clicks
An earlier change unexported the Button.Update method that exposed raw pointer
input not available from the boolean Button.Clicked method. Introduce Click
and Button.Clicks to replace it, and implement Clicked in terms of it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 13:20:00 +02:00
Elias Naur 8d838e89f5 widget,widget/material: rename widget.Click to widget.Press
Press tracks pointer presses, not clicks, and we're about to add a Click
type that does.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 13:19:34 +02:00
Elias Naur d017c722f5 widget,widget/material: only process events in Layout methods
Before this change, events were typically processed twice or more per
widget: once in the Layout method for refreshing the visual state, and
once per method that queries for state changes.

One example is widget.Clickable that processed events in both its Layout
and Clicked method.

This change establishes the convention that events are processed once, in
the Layout method. There are several advantages to that approach:

- Query methods such as Clickable.Clicked no longer need a layout.Context.
- State updates from events only occur in Layout.
- Widgets are simplified because they won't need a separate processEvents
(or similar) method and won't forget to call it from methods other than Layout.
- Useless calls to gtx.Events are avoided (gtx.Events only returns events
for the first call each frame for a given event.Tag).

The disadvantage is that state updates from input events will not appear
before Layout. For example, in the call sequence

	var btn *widget.Clickable

	if btn.Clicked() {...}
	btn.Layout(...)

the Clicked call will not detect an incoming click until the frame after it
happened.

This is ok because

- The Gio event router automatically dispatches an extra frame after events
arrive, bounding the latency from events to queries such as Clicked to
at most one frame (~17 ms).
- The potential extra frame of latency does not apply to Layout methods as long
as they process events before drawing. In other words, the visual feedback
from input events are not delayed because of this change.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 13:03:23 +02:00
Elias Naur c791f59351 widget: simplify Editor event flushing
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-24 12:53:09 +02:00
Elias Naur d8000880c3 example,cmd: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-23 23:14:46 +02:00
Elias Naur 2451750782 widget/material: move widget state object from Layout methods to constructors
Instead of, say,

	var th *material.Theme
	var btn *widget.Clickable

	material.Button(th, "Click me").Layout(gtx, btn)

move the widget state objects to the constructor:

	material.Button(th, btn, "Click me").Layout(gtx)

The advatage is that several widgets can now be used without
wrapping them in function literals. For example,

	layout.Inset{}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
		material.Button(th, "Click me").Layout(gtx, btn)
	})

collapses to just

	layout.Inset{}.Layout(gtx, material.Button(th, btn, "Click me").Layout)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-23 22:28:49 +02:00
Elias Naur 3af01a3f43 layout: change Widget to take explicit Context and return explicit Dimensions
Change the definition of Widget from the implicit

        type Widget func()

to the explicit functional

        type Widget func(gtx layout.Context) layout.Dimensions

The advantages are numerous:

- Clearer connection between the incoming context and the output dimensions.
- Returning the Dimensions are impossible to omit.
- Contexts passed by value, so its fields can be exported
and freely mutated by the program.

The only disadvantage is the longer function literals and the many "returns".
What tipped the scales in favour of the explicit Widget variant is that type
aliases can dramatically shorten the literals:

	type (
		C = layout.Context
		D = layout.Dimensions
	)

	widget := func(gtx C) D {
		...
	}

Note that the aliases are not part of the Gio API and it is up to each user
whether they want to use them.

Finally the Go proposal for lightweight function literals,
https://github.com/golang/go/issues/21498, may remove the disadvantage
completely in future.

Context becomes a plain struct with only public fields, and its Reset is
replaced by a NewContext convenience constructor.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-23 22:28:49 +02:00
Elias Naur af10307f4a widget/material: drop Padding from IconButtonStyle
Use Inset instead, matching the other buttons.

Redefine Size to apply to the icon size, without padding.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-23 10:44:10 +02:00
Elias Naur 60bed57cd7 cmd/gogio: use URL query for passing arguments to wasm programs
The location.hash method doesn't work correctly with multiple
iframes and Safari.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-22 16:22:08 +02:00
Elias Naur fc2a2ae615 cmd,example: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-22 11:35:50 +02:00
Elias Naur 67382bec39 cmd/gogio: [wasm] pass location.hash (if set) to os.Args
Allow for specifying command line arguments to webassembly programs
through the URI hash (https://example.com/wasm/index.html#args)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-21 20:34:11 +02:00
Elias Naur a96b208582 example,cmd: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-21 10:56:44 +02:00
Elias Naur 0614bd29d7 app/internal/window: [X11] handle zero-length clipboard writes correctly
Fixes gio#118

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-21 10:56:36 +02:00
Elias Naur 22b367cb33 app/internal/window: [Android] don't block in runOnMain
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-20 20:22:45 +02:00
Elias Naur ac62e3a7ab op/clip: add Rect.Add shorthand
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-20 10:21:11 +02:00
Elias Naur 7a13c2c905 widget/material: correctly apply alpha to ProgressBar color
color.RGBA values are pre-multiplied, so transparency must be applied
to all components.

Fixes gio#117

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 15:39:43 +02:00
Elias Naur 5a8e1c5acf layout: expand Constraints documentation
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 15:21:27 +02:00
Elias Naur 013ea395b4 all: use new rectangle and point convenience functions
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 11:03:30 +02:00
Elias Naur d82eb8fc66 layout,f32: add convenience functions for rectangles and points
layout.FRect, layout.FPt for converting from integer to floating point,
useful for drawing operations.

f32.Pt is a shorthand that mirrors image.Pt.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 10:59:32 +02:00
Elias Naur 99080023e4 example,cmd: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 10:16:25 +02:00
Elias Naur dac8ffc002 layout: add Exact for constructing rigid Constraints matching a size
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 10:12:11 +02:00
Elias Naur 8a6d4f699c layout: expand Stack documentation
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 10:05:27 +02:00
Elias Naur 7bf3265ccd layout,widget: transpose Constraints to use image.Points for limits
Instead of

    type Contraints struct {
	    Width, Height Constraint
    }

use

    type Constraints struct {
	    Min, Max image.Point
    }

which leads to simpler use. For example, the Min method is trivally replaced by
the field, and the RigidConstraints constructor is no longer a net win.

API Change. Rewrites:

    gofmt -r 'gtx.Constraints.Min() -> gtx.Constraints.Min'
    gofmt -r 'gtx.Constraints.Width.Min -> gtx.Constraints.Min.X'
    gofmt -r 'gtx.Constraints.Height.Min -> gtx.Constraints.Min.Y'
    gofmt -r 'gtx.Constraints.Height.Max -> gtx.Constraints.Max.Y'
    gofmt -r 'gtx.Constraints.Width.Max -> gtx.Constraints.Max.X'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-19 09:58:07 +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