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>
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>
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>
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>
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>
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>
Finding the maximum or adding Values are particularly for adjusting
margins for the safe area insets returned in app.UpdateEvent.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Invalidate is intended to be called as a result of external events,
which might very well be from a different goroutine than the one
driving the window.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Before this change MacroOp.Record simply reserved enough space for Stop to fill
out. If a user Record but never Stop'ed a MacroOp, the resulting Ops buffer
would end up with a zero, invalid opcode and panic at decode.
Fill out an empty MacroOp at Record, ensuring the Ops remains valid.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Since the main README recommends Go 1.13 or later, let's make the go.mod
files reflect that. This will enable starting to use new language
features.
Modules that still build on 1.12 will continue to work on that version
just fine; this line is just a hint to enable new language features for
versions of Go new enough.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Distance was meant to be used for implementing nested scrollers, but
I don't think the API is right. For example, Distance doesn't report
residual fling scrolling.
Delete the field while we wait for a better approach.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Inverted lists used to behave as if its top and bottom edges were
flipped. That was easy but also wrong: when the underlying children
changed size, they would move relative to the top edge of the list.
As illustrated by issue gio#34, Invert should only do two things:
- End lign lists smaller than the containing area.
- Scroll to end, but only as long as the user hasn't scrolled away.
List also had a bug where it didn't handle shrinking lists, so
this change rewrites List to fix that bug, fix Invert behaviour and
hopefully be a little simpler.
Fixes gio#34
Including wayland-egl.h will also set WL_EGL_PLATFORM, but generic
egl code in egl_linux.go cannot do that.
For gio#35
Signed-off-by: Elias Naur <mail@eliasnaur.com>
A ToplevelClose event could end in the same batch of events as
another event, which will result in the other event being sent
after a DestroyEvent. Window assumes no event will arrive after
DestroyEvent, so ensure that property for the Wayland backend.
Signed-off-by: Elias Naur <mail@eliasnaur.com>