We're about to remove all references to window from runOnMain callbacks.
The JNI methods are constant and can be moved out of window.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Using Window.Invalidate for animation with, say
var w Window
var e FrameEvent
w.Invalidate()
e.Frame(...)
stops and immediately starts animation mode which is inefficient
and may cause jitter in the redraw timing.
InvalidateOp is the efficient and sure way to achieve smooth animation,
and Invalidate only exists for external events where there is nowhere to
add an InvalidateOp.
We can do better, so this change makes Invalidate almost as efficient as
InvalidateOp by checking for Invalidates at the same time we check for
InvalidateOps.
Note that we can't avoid the inefficiency in all cases, for example
when the calls above are swapped,
e.Frame(...)
w.Invalidate()
the Invalidate may not be registered before the check during Frame.
While here, add a note to Invalidate that it's meant for externally
triggered redraws.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Track whether requestAnimationCallback has been called when SetAnimating
changes the animated state of the window. Multiple callbacks result in wasteful
redraws.
Without this change, my browser becomes unresponsive when Window.Invalidate
is called every frame. Calling Invalidate every frame is a misuse (InvalidateOp
should be used for animation), but it's nice to have reasonable behaviour.
This change might also fix the issues described in
https://github.com/gioui/gio/pull/7.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
While here, merge BeginFrame and EndFrame; the split was done for
performance reasons, yet never measured.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Modern graphics APIs have immutable objects, with mutable data. For example,
a texture's dimensions are immutable, while the texture contents is not.
Change the GPU API abstraction to match.
Clearing a Texture is convenient to do with a plain []byte. Generalize
Texture.Upload to take a plain byte slice and introduce a helper function for
uploading *image.RGBA data.
Add TextureFormatRGBA8 a format for the linear RGB colorspace.
Add OpenGL ES 3.1 functions for compute programs.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
NewBackend was recently changed to take a context, which must only
be specified on GOOS=js.
Fixes gio#189
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Currently, on iOS, the keyboard can block the content since it doesn't
trigger the "resize". Now, the `insets` will provide the size of the
keyboard (on iOS) and scrollbars. It's compatible with the Android (and
desktop), but Chrome automatic resizes the windows, so the `Inset` will
be 0.
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
The Mesa software OpenGL implementation strays enough from the
reference values that tests fail. Relax the tests to make them
pass again.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The mesa surfaceless renderer doesn't support configs, but does
support EGL_KHR_no_config_context so no config is required. Don't
fail context creation in this setup.
With this change, the headless tests work on a headless linux with the
EGL_PLATFORM environment variable set to "surfaceless".
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Apparently, darwin/arm64 cgo doesn't match the types of YES and BOOL:
os_macos.go:235:40: cannot use _Ciconst_YES (type untyped int) as type _Ctype__Bool
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Previously, the keyboard is open by default, even without any focus.
Now, the keyboard will remain closed, until `.focus()` is called. That
change also prevents the keyboard from reopening immediately after blur.
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
Previously, the only way to manipulate the clipboard (read or write) is
using the `app.Window`.
The new `clipboard.ReadOp` and `clipboard.WriteOp`makes possible to
read/write from the widget.
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
API change. Update your code with gofmt rule and goimports:
gofmt -r "system.ClipboardEvent -> clipboard.Event"
goimports
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
Signed-off-by: Elias Naur <mail@eliasnaur.com>
As a consequence, most API is gone from gpu/gl, and embedding Gio in
foreign frameworks don't need to provide an OpenGL implementation.
The next change simplifies the GLFW embedding example accordingly.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Building an iOS results in errors about missing NSCursor:
$ gogio -target ios -o app.app ./kitchen
gogio: go build -ldflags=-s -w -X gioui.org/app/internal/log.appID=org.gioui.kitchen -buildmode=c-archive -o /var/folders/_7/lnt35k555hl2bs7fjygkhgx00000gp/T/gogio-770783182/gio-amd64 -tags ./kitchen failed: # gioui.org/app/internal/window
os_darwin.m:26:10: error: use of undeclared identifier 'NSCursor'
os_darwin.m:32:10: error: use of undeclared identifier 'NSCursor'
os_darwin.m:40:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:43:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:46:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:49:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:52:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:55:14: error: use of undeclared identifier 'NSCursor'
os_darwin.m:58:14: error: use of undeclared identifier 'NSCursor'
NSCursor is supported under mac catalyst; disable NSCursor support while
figuring out how.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The removal of getError significantly improves performance on js/wasm:
Opera 72 (w/ AMD Ryzen 3900X): ~12.29ms per frame to ~8.09ms;
Chrome 87 (w/ Snapdragon 435): ~156.34ms per frame to ~94.31ms;
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
To get the `popstate` we need to create a new entry into
the browser history. Then, Gio will handle the "back" and
"forward" of the page.
In some browsers (Chrome 87/Edge 87): The user must
click inside the window/page at least one time. It will not
work if the user leaves the page (clicking back button)
without interaction with Gio.
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
Update key.State documentation and add State.String while here. Also
update Event.String to include State.
Signed-off-by: Raffaele Sena <raff367@gmail.com>
That change mitigates the issue gio#150 and gio#166. The
iOS can only `focus()` as a response to touchstart/click
events. We can't `focus()` at random, without user interaction.
The `w.requestFocus` will try to focus on the next `touchstart`,
which may need some "double click" in some cases. That mitigates
the issue, but doesn't fixes completely, but open the keyboard. (:
I didn't notice any side-effect of that change on Android and on
Windows.
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
The context-menu seems useless. The only action available, on the
context-menu is to "Save image": which gives a black image.
I think it's better to remove it. The right-click still work and still
provide `pointer.Event`.
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
color.RGBA has two problems with regards to using it.
First the color values need to be premultiplied, whereas most APIs
have non-premultiplied values. This is mainly to preserve color components
with low alpha values.
Second there are two ways to premultiply with sRGB. One is to premultiply
after sRGB conversion, the other is before. This makes using the API more
confusing.
Using color.NRGBA in sRGB makes it align with CSS.e
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This reverts commit e84a2344cf.
The fix is wrong: it's supressing the release key.Event, not key.EditEvents.
The culprit is that Editor fails to ignore release events.
Updates gio#171
Edit events were being sent twice, once upon key press and again on key release for special keys such as Enter, Arrow keys etc, which resulted in duplicate inputs while pressing these keys. key.EditEvents for special keys now fire once on key press only.
Signed-off-by: Rajiv Kanchan <rajiivkanchan@gmail.com>
PaintOp.Rect is the wrong abstraction; it implies a clip operation
better handled by package clip, and not all paints need it (colors).
Furthermore, it's awkward to specify a PaintOp that fills up the
current clip area, regardless of its size.
Redefine PathOp to mean "fill current clip area".
API change. Replace uses of PaintOp.Rect with a TransformOp applied
before the PaintOp.
Leave a TODO for the PathOp infinity area.
Fixes gio#167
Signed-off-by: Elias Naur <mail@eliasnaur.com>
We're about to remove PaintOp.Rect. Replacing PaintOps with Fill or
FillShape where possible will ease the transition.
Using Fill in tests exposed a problem with the infinity in paint.Fill.
Adjust it for now; it will be removed later.
Updates gio#167
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Implement key state for the following platforms:
js, wayland, windows, x11.
Unsupported platforms will continue to function as before, sending
key.Press for all key events.
Signed-off-by: Josiah Niedrauer <josiah@niedrauer.com>
The Window creates the context, and should also be responsible for
destroying it.
As a bonus, the wrong release ordering of loop.renderLoop is fixed.
Before this change, the context would be destroyed before the renderer
got a chance to destroy its resources.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
First, don't filter on HWND in GetMessage and PeekMessage, lest
thread-specific messages may get lost. See
https://devblogs.microsoft.com/oldnewthing/20050209-00/?p=36493
Second, replace the dead status with the detection of WM_QUIT; it's
what it's there for.
May update gio#168
Signed-off-by: Elias Naur <mail@eliasnaur.com>