Commit Graph

2477 Commits

Author SHA1 Message Date
Elias Naur a3f147541f flake.*: add Nix development environment
This change adds a Nix flake capable of setting up an environment
for building Gio programs for Linux and Android, on top of the
platforms that only needs Go (Windows, WASM).

To use the flake, install Nix 2.4 or later and enable experimental
support for flakes. Then, you can launch a development shell with

$ alias nix='nix --extra-experimental-features "nix-command flakes"'
$ nix develop sourcehut:~eliasnaur/gio

The environment can also be applied to the current shell, which is
useful in combination with direnv:

$ . <(nix print-dev-env sourcehut:~eliasnaur/gio)

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-28 17:48:13 +02:00
Elias Naur 4a061a7d40 .builds: use Android SDK for 32-bit build test
With GOARCH=386, we can't readily build packages that use Cgo. However,
we already have the Android SDK available, so use that to test for 32-bit
issues such as #384.

References: https://todo.sr.ht/~eliasnaur/gio/384
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-28 17:47:57 +02:00
Chris Waldon 3406a6da39 deps,font/opentype: update dependencies to fix 32-bit build
This commit updates to a newer version of textlayout
and switches to a fork of the UAX library that builds
properly on 32-bit machines. This should fix 32-bit Gio
compilation for the time being. I hope to switch back
to npillmayer's UAX as soon as he has time to review
the pending pull requests.

Fixes: https://todo.sr.ht/~eliasnaur/gio/384
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-26 08:36:32 +01:00
Chris Waldon 3fb522caff ci: test non-cgo packages in 32-bit mode
This commit runs Gio's test harness in 32-bit mode as well as 64-bit. This helps
catch bugs in Gio and its dependencies where integer overflow causes build or
runtime problems.

The complexities of cross-compiling CGO made it prohibitively difficult to test
all of Gio, so these changes only run tests for packages in pure Go.

References: https://todo.sr.ht/~eliasnaur/gio/384
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-26 08:36:14 +01:00
Chris Waldon 8833a6738a widget: drop debug prints from tests
This commit removes some lingering editor debug prints
from the test code.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 08:05:19 +01:00
Chris Waldon 7daab97fab widget: [API] make text.Alignment direction-sensitive
This commit ensures that text.Alignment is intuitive for
the direction of the text being aligned. RTL text with
Alignment Start will be aligned to the right edge of the area,
whereas LTR text with Alignment Start will continue to be
aligned to the left edge. Vice versa for the End alignment.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 08:05:06 +01:00
Chris Waldon e14bbee252 font/gofont: [API] use new opentype impl for Collection()
This commit switches gofont.Collection from returning
a collection of fonts using the old text shaper to
using the new harfbuzz-based shaper. The underlying type
of gofont.Collection() has changed, which may break users
who dug into the font data.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 08:04:43 +01:00
Chris Waldon 9576b659d7 text: [API] remove Text and Advances from Layout
These fields are no longer needed with the new text shaper.
Advances is redundant to the glyph information, and Text
should never be used during layout, as you should
traverse the cluster list instead. This commit also removed
the now-unused string field from the path LRU cache key.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 08:04:27 +01:00
Chris Waldon 01276238df font/opentype: [API] replace old font type with harfbuzz
This commit replaces the previous opentype.Font with
an implementation that uses the new text shaper. In
order to keep the implementation simple, support for
opentype font collections was dropped. It should be
possible to re-add this support after some changes
to the text shaper's line wrapping algorithm.

To expand on the above, doing proper font fallback with
harfbuzz will require splitting the input text on font
glyph support boundaries, changing the input from a
simple shaping.Input to []shaping.Input with each input
matched against the font that supports its language.
The line wrapping then needs to be able to properly
consume that slice. Since the line wrapping algorithm is
really complex, I'm hoping to defer that modification
until this simple version is accepted.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 08:04:14 +01:00
Chris Waldon 42c99a5cb2 widget{,/material}: [API] update editor to support complex scripts
This commit updates material.Editor and material.Label to support the
new text shaper. This requires breaking their assumption that glyphs
of font data map 1:1 to runes of text data.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 08:03:46 +01:00
Chris Waldon 938179d293 font/gofont: add font collection using the new shaper
This commit adds a font collection that uses the new
text shaper so that constructing material.Themes atop
it is equally simple to using the old shaper.

You can use material.NewTheme(gofont.CollectionHB()) with
this commit applied.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 08:01:59 +01:00
Chris Waldon 1e5a3696f5 deps,text,widget,font/opentype: [API] add harfbuzz-powered text shaper
This commit introduces a new text shaping infrastructure
powered by Benoit Kugler's Go source-port of harfbuzz.
This shaper can properly display complex scripts and RTL
text. This commit changes the signature of the text.Shaper
function, which is a breaking API change.

The new functionality is available via opentype.ParseHarfbuzz,
which configures a text.Shaper leveraging the new backend.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 08:01:44 +01:00
Chris Waldon db82d12372 layout: add Locale to Context
This commit adds a system.Locale to the layout.Context,
providing an easy means to plumb language information
throughout an application.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 07:58:12 +01:00
Chris Waldon 512900c9b1 system: define new Locale type
This commit adds a Locale struct that captures language and layout
flow direction for the system. This information can be leveraged
by text shaping and layout code to make better choices.

References: https://todo.sr.ht/~eliasnaur/gio/146
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-18 07:58:00 +01:00
Chris Waldon b0ab5ae06e widget: remove unneeded editor flicker logic
We cannot find a way to trigger this flickering
condition anymore, and so we're removing the logic
guarding against it.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-17 09:05:35 +01:00
Chris Waldon 1ad785658e widget: optimize painting editor selection
This commit introduces logic to skip painting the
selection rectangle on lines prior to the line
containing the beginning of the selection.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-17 08:15:31 +01:00
Inkeliz eec78223d1 gpu: prevent texture to be larger than MaxTextureSize
Change eeb2febfea added extra space to FBO
sizes to avoid re-creating them often. However, the size could end up higher
than the GPU supports. This change caps the size.

Fixes: https://todo.sr.ht/~eliasnaur/gio/380
Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2022-03-16 15:52:35 +01:00
Egon Elbre 3fd231367f internal/stroke: optimize arc drawing
Arc with a small angle doesn't need many segments.

Updates: https://todo.sr.ht/~eliasnaur/gio/313
Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2022-03-14 11:42:59 +01:00
Elias Naur 99f6224eb7 cmd/gogio: [Android] export GioActivity to please Android 32 and later
Fixes: https://todo.sr.ht/~eliasnaur/gio/378
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-14 09:27:04 +01:00
Elias Naur eeb2febfea gpu: minimize FBO resizes in current renderer
References: https://todo.sr.ht/~eliasnaur/gio/375
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-11 20:34:49 +01:00
Elias Naur 7785310e9d gpu/internal/vulkan,internal/vk: allocate descriptor sets in batches
We know exactly the configuration and number of sets in each pool, so
we may as well allocate them al up front.

References: https://todo.sr.ht/~eliasnaur/gio/375
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-11 20:34:49 +01:00
Elias Naur e8aa881d40 gpu/internal/vulkan: [Vulkan] replace Device/QueueWaitIdle with fences
vkDeviceWaitIdle and vkQueueWaitIdle are expensive; a vkFence is cheaper
and the usual way to ensure a previous frame has completed before starting
another.

References: https://todo.sr.ht/~eliasnaur/gio/375
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-11 20:34:49 +01:00
Elias Naur c244b7c349 gpu/internal/vulkan: resize descriptor set pool correctly
Before this change, the resized descriptor set pool would never
increase, defeating the purpose of re-using pools.

References: https://todo.sr.ht/~eliasnaur/gio/375
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-11 20:34:49 +01:00
Elias Naur b48b1270a3 app: [Android] re-introduce Choreographer for frame pacing
According to #375, change b86928ceec
increased frame pacing jitter. This change effectively reverts it
by re-introducing Choreographer for pacing.

References: https://todo.sr.ht/~eliasnaur/gio/375
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-11 20:34:49 +01:00
Elias Naur f19b16fecc gpu,app: don't call time.Now when not profiling
runtime.nanotime1 shows up in profiles on Android, so avoid calling
time.Now when we can.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-11 20:34:49 +01:00
Elias Naur 317635b176 .builds: disable Vulkan on FreeBSD
Running GPU tests on freeBSD currently fails with

vulkan: vkCreateGraphicsPipelines: error -8

Disable Vulkan by removing the vulkan-loader package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-11 20:34:49 +01:00
Elias Naur 083d407b47 app: [macOS] ensure only one redraw request is in flight at any time
After 34f10d9cbb, the display link callback
will never block. However, if the main thread is blocked for another reason,
say a bug in the user program, callback requests will pile up as blocked
goroutines.

This change ensures that a redraw request is queued only if no other request
is pending.

References: https://todo.sr.ht/~eliasnaur/gio/370
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-10 10:25:08 +01:00
Chris Waldon cf787a1a8c widget/material: make clickable respect constraints
This change makes material.Clickable propagate the constraints it is
invoked with to the widget being made clickable. Without this, the
internal use of layout.Stack resets the minimum constraints to zero.
This has the confusing effect of breaking a working layout when you
decide to wrap one element in a Clickable, which I think is sufficiently
surprising that we should eliminate the footgun.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-10 08:42:43 +01:00
Elias Naur 9b2bdf6c0c cmd/gogio: bump Android target SDK to 31
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-08 10:49:32 +01:00
Elias Naur 3e18a310af io/router: replace cursor stack with area field
There's no need to track cursors separately from areas.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-07 13:19:38 +01:00
Elias Naur 99bb542960 io/router: always choose the topmost cursor among candidates
Fixes: https://todo.sr.ht/~eliasnaur/gio/373
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-07 13:05:59 +01:00
Elias Naur 68544111c1 io/router: ensure root pointer area in deferred calls
Fixes: https://todo.sr.ht/~eliasnaur/gio/372
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-07 12:08:08 +01:00
Inkeliz b82427d412 app: [windows] fix maximized window size
Previously, the window size is equal to the screen size. That doesn't
consider the size of the taskbar, causing the height be bigger than the
real height. Now, the maximized have the same behavior of windowed,
since both of them must include decorations and taskbar.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
2022-03-07 11:02:47 +01:00
Elias Naur 2b0898fc67 .builds: upgrade Android builds tools and SDK
Fixes the build.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-07 09:42:53 +01:00
Elias Naur c0c25b777b app: replace C-to-Go handle maps with cgo.Handle
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 18:27:30 +01:00
Elias Naur 95365d5878 app/internal/windows,app: [Windows] generalize windows.GetPointerLong
We're about to use it to store the Go window cgo.Handle.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 18:15:38 +01:00
Elias Naur b9e8a177f0 app: [iOS] disable fallback decorations
Before this change, the iOS backend would not report decoration
support at window creation.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 17:55:40 +01:00
Elias Naur fea2f888bb all: replace unsafe slice operations with unsafe.Slice
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 16:53:02 +01:00
Elias Naur af8ca96414 go.*: upgrade to Go 1.17
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 16:53:02 +01:00
Elias Naur 09309d330d .builds: upgrade to Go 1.17.7
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 16:53:02 +01:00
Elias Naur b0838bf697 app: [Android] avoid a null pointer exception at initialization
GioView.onCreateView may call methods on the imm field of GioView.
Make sure it is initialized before use.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-02 16:42:12 +01:00
Chris Waldon 9b69233924 widget: test caret coordinates
This commit adds a check that caret coordinates never exceed
the max constraints of the editor.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-01 20:51:22 +01:00
Elias Naur 1fa9dd0fd0 app: [macOS] redraw when window moves to a different monitor
The monitor may have a different backing store scale, yet the
system doesn't redraw automatically when that happens

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-01 19:50:12 +01:00
Elias Naur 34f10d9cbb Revert "app: [macOS] pace display link"
This reverts commit 11f39582b8 that
introduced pacing of display link callbacks. Blocking the display link
callback introduced deadlocks with code that updates the display link
display.

Not pacing the display link may introduce extra view invalidations,
but invalidates are consolidated by the system and won't result in
extra redraws.

Fixes: https://todo.sr.ht/~eliasnaur/gio/370
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-03-01 19:33:26 +01:00
Egon Elbre cdb288d1f9 app,io/pointer: [API] remove CursorNameOp and rename CursorName -> Cursor
It's now possible to directly user pointer.Cursor to add to the ops.

   pointer.CursorText.Add(gtx.Ops)

This is an API change. Use pointer.Cursor directly instead of CursorNameOp.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2022-03-01 14:05:46 +01:00
Egon Elbre 4172566aad io/pointer: [API] make cursor name into a byte
Add most of the common cursors defined by different systems.

Normalize cursor names to match CSS.

This is API change: some cursor names have changed, and the
underlying type is no longer a string.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2022-03-01 14:04:21 +01:00
Chris Waldon a401d7aaff widget: fix Editor.CaretCoords when scrolled
This commit fixes the position returned by Editor.CaretCoords
to account for the scroll position of the editor. Without this
change, the returned coordinates can easily overflow the boundaries
of the editor widget when it has been scrolled on either axis.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2022-03-01 10:25:38 +01:00
Elias Naur 79bfd3adbd widget: reset focused states when disabled
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-28 18:17:06 +01:00
Elias Naur 50e35c9c3f widget/material: add focus and hover indicators to Clickable
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-28 17:28:13 +01:00
Elias Naur f711e7eaa8 app: ensure Window.Invalidate redraws after delivering events
Events such as system.CommandEvent may result in Invalidate being
called. Ensure animation state is properly updated.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2022-02-28 17:28:13 +01:00