Clipping all children once to the entire List area is enough. The
change was motivated by #389 where individual child clips would
make it harder for focus scroll heuristics to work.
References: https://todo.sr.ht/~eliasnaur/gio/389
Signed-off-by: Elias Naur <mail@eliasnaur.com>
List was recently changed to include an extra child at each end, to
automatically scroll when reaching the end of a focus direction. However,
if List includes unfocusable children that strategy may fail. This change
adds another fallback where app.Window will scroll a constant amount in
the focus direction, to reveal more children.
For https://github.com/tailscale/tailscale/issues/4278.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Enter/Leave events make sense for mouse pointers, to track hover
status. It doesn't make sense to track hover for touch input, so
this change stops pointer.Enter and pointer.Leave from being
emitted for pointer.Touch sources.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
A recent change added automatic scrolling to move focused widgets
into view. This change modifies List to layout an extra child at
each of its ends, to enable focus to move to them and trigger
automatic scrolling of the list.
For https://github.com/tailscale/tailscale/issues/4278.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Before, List would only report the remaining scrollable area of the visible
children when positioned close to either end. Now, List always report infinite
scroll bounds *unless* it is positioned at an extremum.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Before this change, semantic clicks would be delivered according to
the center of the targeted widget, which could result in a different
widget receiving the click. Or in worst case, no widget in case the
center is not visible because of clipping.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
A focused widget may be partially or completely off-screen in which case
the user will have difficulty interacting with it. This change attempts to
scroll the focused widget into view by issuing synthetic scroll events.
For https://github.com/tailscale/tailscale/issues/4278, but doesn't completely
solve it because layout.Lists won't layout focusable widgets outside its visible
bounds. A follow-up change deals with that.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
We're about to not emit Enter and Leave events for touch input, and
this change changes the Click gesture to no longer rely on those
events to determine whether a Release is inside its bounds.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
A meaningful clip area for a key handler will matter when we start
auto-scrolling to move focused handlers into view.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Creating an image.Rectangle from a f32.Rectangle is used by two packages in Gio
and about to be used for a third. Add a Round method to f32.Rectangle to avoid
duplicating the implementation.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This is a refactor to make it easier to add higher level logic to
focus moves. A follow-up will add automatic scrolling to bring
focused widgets into view.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The emulator needs android system images to run, each of which takes
up a lot of space. Remove emulator from the Nix flake environment and
let something else provide emulator support, maybe even a custom
Nix devShell.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>